Re: strdup or str_dup?

From: Richard Glover (magik@thegrid.net)
Date: 03/08/99


Just curious, but where in this do you see a check for NULL?

/* Create a duplicate of a string */
char *str_dup(const char *source)
{
  char *new_z;

  CREATE(new_z, char, strlen(source) + 1);
  return (strcpy(new_z, source));
}

#define CREATE(result, type, number)  do {\
 if ((number) * sizeof(type) <= 0) \
  log("SYSERR: Zero bytes or less requested at %s:%d.", __FILE__, __LINE__);
\
 if (!((result) = (type *) calloc ((number), sizeof(type)))) \
  { perror("SYSERR: malloc failure"); abort(); } } while(0)

I've sent a NULL here and every time it crashes.

Rick

-----Original Message-----
From: Chris Jacobson <fear@TECHNOLOGIST.COM>
To: CIRCLE@post.queensu.ca <CIRCLE@post.queensu.ca>
Date: Monday, March 08, 1999 3:16 PM
Subject: Re:  strdup or str_dup?


>On 3/8/99 9:57 AM, Nocturnal Occulto (ronnyi@ifi.uio.no) stated:
>
>>strdup or str_dup? Which one should I use and why?
>
>Either, but not all systems have strdup(), hence why an Circle str_dup is
>used.  Plus the Circle version can catch null strings, strdup() would
>crash.
>
>- Chris Jacobson


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