Re: Curious question for act.comm.c

From: Mike Breuer (mbreuer@new.rr.com)
Date: 09/01/01


----- Original Message -----
From: "Del" <caminturn@EARTHLINK.NET>


> ACMD(do_write)
> {
>   struct obj_data *paper, *pen = NULL;
>   char *papername, *penname;
>
>   papername = buf1;
>   penname = buf2;

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.

Mike

--
   +---------------------------------------------------------------+
   | 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