Re: strdup or str_dup?

From: George Greer (
Date: 03/09/99

On Mon, 8 Mar 1999, Daniel A. Koepke wrote:

>Although why you'd want to isn't clear to me -- crashes aren't always bad
>things.  If str_dup() is being called with a NULL string, which isn't
>supposed to happen in most cases, then a crash with a core dump is useful.
>If you don't want it to crash, then check if the string being passed to
>str_dup() is NULL beforehand.  You can keep the MUD up by reporting an
>error and just returning some standard string in str_dup(), but this
>probably isn't desirable for all the potential uses of str_dup().  So just
>let it crash instead of letting your broken code run and potentially
>corrupt data.

I suppose it could be interesting for those people who must have uptime and
don't want a nasty oversight being player exploitable.

some header:
#define str_dup(x)      my_str_dup(x, __FILE__, __LINE__)

some C file:
#undef str_dup
char my_str_dup(const char *dup, const char *file, int line)
  if (!dup) {
    log("SYSERR: NULL str_dup from %s:%d", file, line);
    return NULL;
  return str_dup(dup);

Or just add it to the real str_dup.

George Greer            | CircleMUD Snippets   |

     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  |

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