This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] itoa



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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]