[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: snprintf: no string is outputed if the input string is longer than t
From: |
Marcus Brinkmann |
Subject: |
Re: snprintf: no string is outputed if the input string is longer than the buffer |
Date: |
Sun, 22 Jul 2001 18:04:07 +0200 |
User-agent: |
Mutt/1.2i |
On Sun, Jul 22, 2001 at 08:28:23AM -0700, James Morrison wrote:
> That subject is way too long, but that is the entire message.
>
> eg.
> char b[5];
> snprintf(b,5,"123456");
> printf("%s\n",b);
>
> output:
>
> end output
In fact, for exmaple
snprintf(b,5,"abc%sdef", "xyz");
leaves b as "def", and similar in other cases. Seems the content of
b is undefined if the string doesn't fit. Programs expect this to be
truncated, though. We now wonder if this is a stdio/libio issue.
Marcus