Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2001:
[Freeciv-Dev] Re: Fwd: Re: Re: Request (PR#939)
Home

[Freeciv-Dev] Re: Fwd: Re: Re: Request (PR#939)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: rf13@xxxxxxxxxxxxxxxxxxxxxx
Cc: Paul Zastoupil <paulz@xxxxxxxxxxxx>, freeciv-dev@xxxxxxxxxxx, bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: Fwd: Re: Re: Request (PR#939)
From: Jason Dorje Short <jshort@xxxxxxxxxxxxx>
Date: Thu, 06 Sep 2001 03:42:41 -0400
Reply-to: jdorje@xxxxxxxxxxxxxxxxxxxxx

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


[Prev in Thread] Current Thread [Next in Thread]