Re: sprintf and clists



Hi,

> check out if the string is '\0' terminated. best initialize it after the
> declaration with memset(buffer,'\0',1024);

sprintf terminates the string for you (but see below).

> BTW wouldn't it be enough to use a buffer of size "sizeof(int)" ?

no. You need to allocate enough space to print all digits and add a
terminating NULL. This is unrelated to sizeof(int).

However, sprintf() should _never_ be used. You should consider to use
g_strdup_printf() however which will allocate exactly the memory you
need w/o the possibilities of buffer overflows. If you absolutely want
to use static buffer, use snprintf().


Salut, Sven



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