Home » U++ Library support » U++ Core » CParser: Suggest check for overflow in ReadInt, ReadDouble...
CParser: Suggest check for overflow in ReadInt, ReadDouble... [message #40985] |
Thu, 17 October 2013 21:35 |
hans
Messages: 44 Registered: March 2006 Location: Germany
|
Member |
|
|
Hi,
I would suggest checking the number string for range in the following functions:
int ReadInt() throw(Error);
int ReadInt(int min, int max) throw(Error);
int64 ReadInt64() throw(Error);
int64 ReadInt64(int64 min, int64 max) throw(Error);
uint32 ReadNumber(int base = 10) throw(Error);
uint64 ReadNumber64(int base = 10) throw(Error);
double ReadDouble() throw(Error);
If the number string would overflow the number range silently a garbage number is returned.
Would be nice if range error is thrown instead.
In ReadInt() and ReadInt64() also should be checked if the unsigned number read internal is lower than half of signed before sign can be applied.
Do others agree?
Hans
|
|
|
|
|
|
Re: CParser: Suggest check for overflow in ReadInt, ReadDouble... [message #41027 is a reply to message #41026] |
Tue, 22 October 2013 07:41 |
|
mirek
Messages: 13975 Registered: November 2005
|
Ultimate Member |
|
|
hans wrote on Mon, 21 October 2013 16:57 | Thanks, looks good.
For double no check is needed indeed, it already returns #INF on overflow.
Hans
|
Well, I have not checked in Win32, but in Linux it does not seem to work that way. In any case, to make things consistent, it should throw the error too. After some investigation, I plan to reset FP exceptions state at the start of method and check them at the end. The only problem seems to be that this checking is different for Win32 vs Posix....
|
|
|
|
Goto Forum:
Current Time: Thu Apr 25 08:37:47 CEST 2024
Total time taken to generate the page: 0.02508 seconds
|