[MPlayer-dev-eng] [PATCH 6/7] stream ftp: Allocate command buffer on-heap

Sergey sergemp at mail.ru
Thu Nov 15 03:42:19 CET 2012


On Mon, 12 Nov 2012 Reimar Döffinger wrote:

>> +    snprintf(p->cmd_buf,CMD_BUFSIZE - 1,"REST %"PRId64, (int64_t)newpos);
> 
> There should be no -1 for the size argument (same for all other
> snprintfs).

Are you sure?

My man snprintf says:
    The  functions  snprintf() and vsnprintf() write at most size
    bytes (including the trailing null byte (’\0’)) to str.
But it does not say that \0 is always stored there.

Also this page explicitly says that it may not be stored:
  http://msdn.microsoft.com/en-us/library/2ts7cx93.aspx
  If len < count, then len characters are stored in buffer, a null-terminator is appended, and len is returned.
  If len = count, then len characters are stored in buffer, no null-terminator is appended, and len is returned.
  If len > count, then count characters are stored in buffer, no null-terminator is appended, and a negative value is returned.

-- 
  Sergey


More information about the MPlayer-dev-eng mailing list