Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to next message
hans is currently offline  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 #40989 is a reply to message #40985] Fri, 18 October 2013 07:44 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
You are definitely right. For now adding to RM.

http://www.ultimatepp.org/redmine/issues/541

I am not quite sure how to implement checks for double thought...
Re: CParser: Suggest check for overflow in ReadInt, ReadDouble... [message #41024 is a reply to message #40985] Mon, 21 October 2013 20:36 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Implemented for integer values; have yet to figure out portable way of FP...

Mirek
Re: CParser: Suggest check for overflow in ReadInt, ReadDouble... [message #41026 is a reply to message #41024] Mon, 21 October 2013 22:57 Go to previous messageGo to next message
hans is currently offline  hans
Messages: 44
Registered: March 2006
Location: Germany
Member
Thanks, looks good.

For double no check is needed indeed, it already returns #INF on overflow.

Hans
Re: CParser: Suggest check for overflow in ReadInt, ReadDouble... [message #41027 is a reply to message #41026] Tue, 22 October 2013 07:41 Go to previous messageGo to next message
mirek is currently offline  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....
Re: CParser: Suggest check for overflow in ReadInt, ReadDouble... [message #41036 is a reply to message #41027] Wed, 23 October 2013 07:51 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
FP overflow checks completed both in Win32/POSIX.

Testing code:

http://code.google.com/p/upp-mirror/source/browse/trunk/uppt st/CParser/main.cpp
Previous Topic: append in logging not working
Next Topic: how to just get var from parent Layout class?
Goto Forum:
  


Current Time: Sat Apr 20 04:34:13 CEST 2024

Total time taken to generate the page: 0.02370 seconds