[Freeciv-Dev] Re: Fwd: Re: Re: Request (PR#939)
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
On Thu, Sep 06, 2001 at 03:42:41AM -0400, Jason Dorje Short wrote:
> 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).
I overread the not in "the result wil not be null-terminated". argl
> In the hugely bizarre case where str is longer than wallbuffer a
> buffer overflow would be Undesirable.
Ack.
> 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);
This whole case looks like an ideal application for mystrlcpy.
Raimar
--
email: rf13@xxxxxxxxxxxxxxxxx
"If at first you don't succeed... well so much for skydiving."
|
|