]> diplodocus.org Git - nmh/commitdiff
slocal.c: Alter trim() to return static array, not malloc(3).
authorRalph Corderoy <ralph@inputplus.co.uk>
Sun, 10 Sep 2017 17:12:38 +0000 (18:12 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Mon, 11 Sep 2017 17:12:07 +0000 (18:12 +0100)
The callers are immediately passing the return value to printf(3) for
"%s".  There's only one call per printf().  None of the callers are
bothering to free(3) the existing return value.  Return the address of
trim()'s char array, now static, instead.  Leave trim() returning NULL
when passed NULL, even though that gives NULL to print(3) for "%s".  It,
and slocal's other bugs, remain.

uip/slocal.c

index 723cb27a26114d2f23b96ba4ab62fa77590e6b7a..fe027ee2f8b3f00c3a44e722a154a42222a0d3a0 100644 (file)
@@ -1293,7 +1293,7 @@ fputs_error:
 static char *
 trim (char *cp)
 {
 static char *
 trim (char *cp)
 {
-    char buffer[BUFSIZ*4];
+    static char buffer[BUFSIZ * 4];
     char *bp, *sp;
 
     if (cp == NULL)
     char *bp, *sp;
 
     if (cp == NULL)
@@ -1320,8 +1320,7 @@ trim (char *cp)
        if (isspace((unsigned char) *sp))
            *sp = ' ';
 
        if (isspace((unsigned char) *sp))
            *sp = ' ';
 
-    /* now return a copy */
-    return mh_xstrdup(bp);
+    return bp;
 }
 
 /*
 }
 
 /*