[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: where the hell is itoa()?



On Sat, 14 Jul 2001, Ariel Biener wrote:

> #include <stdio.h>
> #include <stdlib.h>
>
> int main()
> {
>
>     char *mychar;
>     int a=99999;         /* Just some random number */
>
>     mychar=(char *)calloc(1, sizeof(int));

callock (and all other malloc related functions) can fail and return
NULL.

>     sprintf(mychar, "%d%c", a, '\0');

you just overflowed your stack by one byte. snprintf is your friend.

> }
>
>
> This may be broken, but the idea is that standard C doesn't have itoa().
>
> --Ariel

-- 
mulix
http://www.advogato.com/person/mulix

linux/reboot.h: #define LINUX_REBOOT_MAGIC1 0xfee1dead



=================================================================
To unsubscribe, send mail to linux-il-request@linux.org.il with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail linux-il-request@linux.org.il