[comp.mail.mh] Re^2: questions about slocal

carllp@sleipner.diku.dk (Carl-Lykke Pedersen) (12/19/88)

edward@vangogh.sybase.com (Ed Hirgelt) writes:

>I've been using slocal for several months with 6.5. I made one change to
>sbr/getcpy.c to avoid dereferencing the null pointer. The code now looks
>like:
[src deleted]

The code in mh6.6 is better:

/* getcpy.c - copy a string in managed memory */

#include "../h/mh.h"
#include <stdio.h>


char   *getcpy (str)
register char  *str;
{
    register char  *cp;

    if (!str) {
	if ((cp = malloc ((unsigned) (1))) == NULL)
	    adios (NULLCP, "unable to allocate string storage");
	(void) strcpy (cp, "");
    } else {
	if ((cp = malloc ((unsigned) (strlen (str) + 1))) == NULL)
	    adios (NULLCP, "unable to allocate string storage");

	(void) strcpy (cp, str);
    }
    return cp;
}