Re: strdup or str_dup?

From: Daniel Burke (addictmud@home.com)
Date: 03/10/99


nOn Wed, 10 Mar 1999, Acido wrote:

> At 09:43 AM 3/10/99 -0800, you wrote:
>
> Why not throw the same check in str_dup() to avoid the extra function??
>
> char *str_dup(const char *source)
> {
>   char *new;
>
>   if (!*source)
>     return ("undefined"):
>
>   CREATE(new, char, strlen(source) + 1);
>   return (strcpy(new, source));
> }
>
> or would this be a bad thing to do??
>

What you have there is bad bacause, later down the road, what if something
tries to free that "undefined".  That will crash, because you didn't
actually allocate memory for it.

I could probably sound a lot more technical about it, but after spending all
day on the phone with IBM doing software testing, I like doing anything but
being technical :P

Brazil - AddictMUD
game.addictmud.org 4000
http://www.addictmud.org


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |
     +------------------------------------------------------------+



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