atoi and undefined usage

André Johansen andrejoh at c2i.net
Thu May 27 15:02:58 CDT 2004


The atoi() function has undefined usage when trying to convert numbers
outside the range of int.

When parsing numbers >= 2^31, GNU libc seems to truncate the number to
2^31-1; however, with MSVC, such a number would wrap, and when cast to
an unsigned integer, numbers within an unsigned int are preserved.

Should Wine care about such undefined behaviour?  Currently, it seems
Wine uses the GNU libc implementation, giving a different result than
when running in Windows.

(In my case, an IP address was given as a string, and ended up as
"127.255.255.255" when running in Wine.  I've now fixed that specific
bug in the source code, but with other programs, that might not be an
option...)

-- 
Try   Anarchy  Online   http://www.anarchy-online.com/content/downloads/tryout/
Netiquette guidelines   ftp://ftp.rfc-editor.org/in-notes/rfc1855.txt
How to quote properly   http://www.i-hate-computers.demon.co.uk/
Hvordan sitere riktig   http://home.online.no/~vidaandr/news/OBSquoting.html



More information about the wine-devel mailing list