|
Firewalls (April 1994) |
I don't know if I'd trust anything that tromps through what could be a
NULL pointer. In this case, 'dst' could be NULL (if malloc fails), and
the program would print the warning, then dump core (unless run on a
little-endian machine, say, a VAX.)
Jim
/* strndup - make copy of string */
static char *strndup(str, len)
char *str;
int len;
{
char *dst;
if ((dst = malloc(len + 1)) == 0)
fprintf(stderr, "%s: out of memory\n", myname);
dst[len] = 0;
return (strncpy(dst, str, len));
}
|