[PATCH] unify itoa

Rich Felker dalias at aerifal.cx
Wed Jul 12 09:22:33 PDT 2006


On Wed, Jul 12, 2006 at 04:32:12PM +0200, Denis Vlasenko wrote:
> On Tuesday 11 July 2006 21:42, Rob Landley wrote:
> > > The version in current svn produces _most significant_ digits
> > > if buffer is too small. IOW: utoa_to_buf_rob(100223,buf,3)=="10".
> > > The usual practuce is to produce "23".
> > 
> > If the buffer is too small it essentially produces garbage, we just don't want 
> > it to overflow and stomp memory it doesn't own.
> 
> Real-world example why we should do it:
> 
> printf("%02d:%02d\n", seconds/60, seconds);
> 
> Here user of sprintf deliberately uses the fact
> that printf shows least significant digits,
> not most significant ones.

Apparently you don't know C -- field width never causes truncation.
The only format specifier that can cause truncation is precision (not
width) when used with strings.

Rich



More information about the busybox mailing list