Re: [PATCH] Cleanup: snprintf() always NUL-terminates: depend on it

2015-01-12 Thread Aleksandr P
> len = snprintf(fname, 99, "%s", buf); > - fname[len-1] = '\0'; > I just deleted that "really, really" NUL-termination line because > it was based on a misunderstanding of snprintf()'s postcondition. Are you sure this code can be simple deleted? It does not only terminate the string but delete

Re: [PATCH] Cleanup: snprintf() always NUL-terminates: depend on it

2015-01-04 Thread Giel van Schijndel
On Sun, Jan 04, 2015 at 19:05:58 +0100, Giel van Schijndel wrote: > Especially since one very strange piece of code seems to be written in > such a way that a NUL needs to be placed where a NUL is present already. > The author probably meant to fill the last byte of the buffer with a NUL > instead.

Re: [PATCH] Cleanup: snprintf() always NUL-terminates: depend on it

2015-01-04 Thread Giel van Schijndel
On Sun, Jan 04, 2015 at 11:34:43 -0800, Linus Torvalds wrote: > On Sun, Jan 4, 2015 at 10:05 AM, Giel van Schijndel wrote: >> Especially since one very strange piece of code seems to be written in >> such a way that a NUL needs to be placed where a NUL is present already. > > Actually, it's worse

Re: [PATCH] Cleanup: snprintf() always NUL-terminates: depend on it

2015-01-04 Thread Linus Torvalds
On Sun, Jan 4, 2015 at 10:05 AM, Giel van Schijndel wrote: > Especially since one very strange piece of code seems to be written in > such a way that a NUL needs to be placed where a NUL is present already. Actually, it's worse than that. This: > len = snprintf(fname, 99, "%s", buf); > -

[PATCH] Cleanup: snprintf() always NUL-terminates: depend on it

2015-01-04 Thread Giel van Schijndel
Especially since one very strange piece of code seems to be written in such a way that a NUL needs to be placed where a NUL is present already. The author probably meant to fill the last byte of the buffer with a NUL instead. But regardless of that: that isn't necessary since snprintf() already gua