Christoph Egger <[EMAIL PROTECTED]> wrote:

> > Will it write a trailing \0 ? If not, that should be generated, to avoid
> snip from the manual page:
> 
>    Return value
>        These  functions  return  the number of characters printed
>        (not including the trailing `\0' used  to  end  output  to
>        strings).   snprintf  and vsnprintf do not write more than
>        size bytes (including the trailing '\0'), and return -1 if
>        the  output  was truncated due to this limit.  (Thus until
>        glibc 2.0.6. Since glibc 2.1 these  functions  follow  the
>        C99  standard and return the number of characters (exclud
>        ing the trailing '\0') which would have  been  written  to
>        the final string if enough space had been available.)

That's the point. I cannot derive from that, if snprintf will
terminate the string, if an overflow occurs, without leaving a little 
doubt. Does anyone have the C99 standard ready and can confirm, that
snprintf is supposed to terminate the string in _any_ case?

If that is not the case or unsure, I would suggest to explicitly 
terminate the string after every usage of snprintf using something
like

#define TERMINATE_ARRAY(x) x[sizeof(x)-1]='\0'
#define TERMINATE_POINTER(x,len) x[len-1]='\0'


CU, ANdy

-- 
= Andreas Beck                    |  Email :  <[EMAIL PROTECTED]>             =

Reply via email to