[PATCH] itoa

Jon Beniston jon@beniston.com
Mon Dec 8 18:13:00 GMT 2014


Hi Corinna,

> What other platforms?

Various Windows compilers and a variety of embedded targets, but no, not generally unices (although you often see people asking for it in various forums).

> The API is rather unsafe, given that the size of the buffer is not checked (no size parameter).  

The API is that the buffer should be sizeof(int)*8+1 to handle the worst case.  E.g: http://www.cplusplus.com/reference/cstdlib/itoa/ I've added this to the DESCRIPTION.

> But what I'm really missing are checks for the base parameter being valid.  It could be > 36.  Or negative.

According to the docs, base must be between 2 and 36. I didn't add this check initially, as I don't see much parameter range checking in newlib generally, however, I've now added a check and it terminates the string and returns NULL if base is out of range. (It seems MSVC doesn't check the base, as it divides by zero if you use 0).

I've also modified it as per Freddie's suggestion.

Cheers,
Jon

-------------- next part --------------
A non-text attachment was scrubbed...
Name: itoa2.patch
Type: application/octet-stream
Size: 5087 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/newlib/attachments/20141208/785ac93e/attachment.obj>


More information about the Newlib mailing list