[PATCH] unify itoa
Rob Landley
rob at landley.net
Thu Jul 13 13:43:27 UTC 2006
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
Rob
--
Never bet against the cheap plastic solution.
More information about the busybox
mailing list