From: Ralph Corderoy Date: Sun, 16 Oct 2016 23:08:26 +0000 (+0100) Subject: Rewrite getcpy() using mh_x*() allocation functions. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/bc10b0cee78f7df5b7b2c6958a5a547f56bac4f5?hp=39bfc0b25d39979d1ec47b14e69a4f17ea3493ab Rewrite getcpy() using mh_x*() allocation functions. --- diff --git a/h/prototypes.h b/h/prototypes.h index a6c412e2..f06322b5 100644 --- a/h/prototypes.h +++ b/h/prototypes.h @@ -167,7 +167,9 @@ char **getarguments (char *, int, char **, int); */ char *get_charset(void); -char *getcpy (const char *); +/* Return malloc'd copy of str, or of "" if NULL, exit on failure. */ +char *getcpy(const char *str); + char *get_default_editor(void); char *getfolder(int); diff --git a/sbr/getcpy.c b/sbr/getcpy.c index 4d99a803..32c8db43 100644 --- a/sbr/getcpy.c +++ b/sbr/getcpy.c @@ -14,20 +14,11 @@ #include #include - -char * -getcpy (const char *str) +/* Return malloc'd copy of str, or of "" if NULL, exit on failure. */ +char *getcpy(const char *str) { - char *cp; - size_t len; + if (str) + return mh_xstrdup(str); - if (str) { - len = strlen(str) + 1; - cp = mh_xmalloc (len); - memcpy (cp, str, len); - } else { - cp = mh_xmalloc ((size_t) 1); - *cp = '\0'; - } - return cp; + return mh_xcalloc(1, 1); }