Re: Curious question for act.comm.c

From: Carlos Myers (farix@stargate.net)
Date: 09/01/01


From: "Del" <caminturn@earthlink.net>
> Mike Breuer wrote:
> >
> >
> > This is one of those examples of using global buffers in a potentially
> > dangerous way.  Note, that it IS necessary to assign papername and
penname
> > to something, since they are declared merely as pointers and there is no
> > storage behind them.  Without starting up the whole global vs. local
buffers
> > debate again, let me just comment that this is particularly dangerous
> > because it is not as obvious that the global buffers are being used in
this
> > function.  I would recommend the following change:
> >
> >  ACMD(do_write)
> >  {
> >    struct obj_data *paper, *pen = NULL;
> > -  char *papername, *penname;
> > +  char papername[MAX_STRING_LENGTH], penname[MAX_STRING_LENGTH];
> >
> > -  papername = buf1;
> > -  penname = buf2;
> >
> > A _quick_ glance at the function didn't show any potential problems with
> > this.  It looks like papername and penname point to those buffers
throughout
> > the rest of the function.
>
> Ahhhhhhh I missed that. Would it not be just as wise to
> char *penname = NULL, *papername = NULL;

But two_arguments does not create a new string.  It uses the existing
strings that were passed to it.  So if you pass it a NULL, two_arguments
will reformat your harddrive, corrupt you BIOS and finally blow your house
up.  Well maybe not, but you will get some sort of error.

Carlos

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/06/01 PST