[PATCH] itoa

Craig Howland howland@LGSInnovations.com
Mon Dec 8 17:59:00 GMT 2014

On 12/08/2014 12:17 PM, Corinna Vinschen wrote:
> Hi Jon,
> On Dec  7 13:34, Jon Beniston wrote:
>> Hi,
>> The attached patch adds support for the itoa and utoa functions, for
>> converting integers to strings.
>> This is a function that is supported on other platforms,
> What other platforms?  It appears in K&R, base 10 only, and it appears
> in a Unix manual from 1971(*), but I can't find it in GLibc nor one of
> the BSDs.
> The API is rather unsafe, given that the size of the buffer is not
> checked (no size parameter).  But what I'm really missing are checks for
> the base parameter being valid.  It could be > 36.  Or negative.
Microsoft Visual Studio has a "safe" variant which adds the buffer size:
errno_t _itoa_s(
    int value,
    char *buffer,
    size_t sizeInCharacters,
    int radix
(See http://msdn.microsoft.com/en-us/library/0we9x30h.aspx, where they also have 
some other flavors of it.  They do define an error return for base out of range.)
> I see how this may be useful for embedded targets, but in a standard C
> library, I'm not so sure about.
> Corinna
> (*) http://en.wikibooks.org/wiki/C_Programming/C_Reference/stdlib.h/itoa

More information about the Newlib mailing list