Re: cppcheck: VDR 1.7.18: [timers.c:53]: (error) snprintf size is out of bounds

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

 



Am 15.06.2011 18:34, schrieb Klaus Schmidinger:
> On 15.06.2011 15:30, Paul Menzel wrote:
>>            if (Instant&&  channel)
>>               snprintf(file, sizeof(file), "%s%s",
>> Setup.MarkInstantRecord ? "@" : "", *Setup.NameInstantRecord ?
>> Setup.NameInstantRecord : channel->Name());
> 
> ...this should be
> 
>   sizeof(file) - 1

Actually, all versions of snprintf documentation I've just checked agree
that snprintf will write at most size-1 chars and a trailing 0 byte, so
it was ok before too. But for safety, on byte less doesn't hurt.

Or is there some broken implementation out there that may write beyond
str[size-1]?

(strncpy is more broken, thats why my typical usage is:
  strncpy(dest, src, sizeof(dest)-1);
  dest[sizeof(dest)-1] = 0;
)

Cheers,

Udo

_______________________________________________
vdr mailing list
vdr@xxxxxxxxxxx
http://www.linuxtv.org/cgi-bin/mailman/listinfo/vdr


[Index of Archives]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Util Linux NG]     [Xfree86]     [Big List of Linux Books]     [Fedora Users]     [Fedora Women]     [ALSA Devel]     [Linux USB]

  Powered by Linux