[PATCH] unify itoa

Denis Vlasenko vda.linux at googlemail.com
Thu Jul 13 10:01:17 PDT 2006


On Thursday 13 July 2006 15:43, Rob Landley wrote:
> On Wednesday 12 July 2006 10:32 am, 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.
> 
> landley at driftwood:~/busybox/busybox$ cat hello.c
> #include <stdio.h>
> 
> int main(int argc, char *argv[])
> {
>   printf("%02d:%02d\n", 123,456);
>   return 0;
> }
> landley at driftwood:~/busybox/busybox$ gcc hello.c
> landley at driftwood:~/busybox/busybox$ ./a.out
> 123:456

Yes, I was stupid and wrong on this one, as well as on Alpha sizeof(int).

:)

--
vda


More information about the busybox mailing list