Re: BUG LIST WITH FIXES

From: Jeremy Elson (jelson@blaze.cs.jhu.edu)
Date: 07/22/95


> This file will generally outline some of the generic circlemud tweks and bugs
> I've found today.  They are by no means all 100% correct, so if someone sees
> room for improvement, please speak up :).

Okay. :)

> Problem: This bug has to do with not initializing the structure "sa" to begin
>          with.
> 
> Fix:
> 
> comm.c:
> 
> #endif
> 
> + bzero((char *) &sa, sizeof(sa));
> 
>   sa.sin_family = AF_INET;
>   sa.sin_port = htons(port);

You've cut off the last line in the portion of the code you've quoted,
but all three of the parts of the address (family, port, and address)
are set to values.  Why would you want to zero them before setting their
values to something else?

The padding at the end of the structure doesn't need to be initialized,
since it's never used (it's just padding ;-)) - maybe that's what you're
zeroing?

> Problem: In utils.c, there are two functions named:
>            - struct time_info_data real_time_passed(time_t t2, time_t t1);
>            - struct time_info_data mud_time_passed(time_t t2, time_t t1);
> 
>          In both cases, they are configured to return a variable named "now",
>          a structure.  This can easily get corrupted and begin to point to
>          garbage the way it is at this point in circlemud beta, so
>          here's what you do to fix it..  (BTW, I know there is a much better
>          way to fix this problem, but I'm too lazy.. there's still too many
>          generic bugs that need fixing).. If someone finds a better way to
>          remedy it, please share it with us.
> 
> Fix:
> 
> utils.c:
> 
> struct time_info_data mud_time_passed(time_t t1, time_t t2)
> {
>   long secs;
> - struct time_info_data now;
> + static struct time_info_data now;

This doesn't need to be static - the code is correct as is.  If I was
returning a *pointer* to the structure, which I'm not, then it would need
to be declared as static.  But I'm just returning a value.  It's like saying
"return 52" or "return x" where x is an integer.  return returns a value,
not a reference so static is not necessary here.  Putting it in won't break
anything but it doesn't have to be there.

Now, if you have something like a local array of chars that you return,
then you *do* need to declare it as static (there are examples of this in
the Circle code), because the value of the return value is, itself, a
pointer into the temporary space used by the function.

--je



This archive was generated by hypermail 2b30 : 12/07/00 PST