[Freeciv-Dev] Re: Fwd: Re: Re: Request (PR#939)
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Raimar Falke wrote:
>
> > + char wallbuffer[2048];
> > + wallbuffer[0]=0;
> > + cat_snprintf(wallbuffer, sizeof(wallbuffer),"%s",str);
>
> What about strncpy? printf seems like overkill here.
>
> Otherwise it looks fine.
strncpy doesn't NULL-terminate (unless you do it manually afterwards, of
course). In the hugely bizarre case where str is longer than wallbuffer
a buffer overflow would be Undesirable.
My question is why cat_snprintf was used instead of snprintf
(mysnprintf). What's wrong with
mysnprintf(wallbuffer, sizeof(walluffer), "%s", str);
and why would you ever think to use cat_snprintf with manual termination
first?
And if you do use cat_snprintf, why wouldn't you do
cat_snprintf(wallbuffer,
sizeof(wallbuffer)-strlen(wallbuffer),
"%s", str);
?
jason
|
|