The code was a bit odd.
I'm bundling a trivial style change that makes the "return 0" statement into
"return NULL".


Additionally, there is a very similar function called str_save() which
could be implemented as a call to this str_nsave() function. 
Would OpenBSD mind if I sent a patch to do that?

Index: bin/ksh/misc.c
===================================================================
RCS file: /cvs/src/bin/ksh/misc.c,v
retrieving revision 1.76
diff -u -p -u -r1.76 misc.c
--- bin/ksh/misc.c      26 Oct 2020 18:16:51 -0000      1.76
+++ bin/ksh/misc.c      11 Apr 2021 20:20:58 -0000
@@ -98,10 +98,11 @@ str_nsave(const char *s, int n, Area *ap
        char *ns;
 
        if (n < 0)
-               return 0;
-       ns = alloc(n + 1, ap);
-       ns[0] = '\0';
-       return strncat(ns, s, n);
+               return (NULL);
+       n++;
+       ns = alloc(n, ap);
+       strlcpy(ns, s, n);
+       return (ns);
 }
 
 /* called from expand.h:XcheckN() to grow buffer */

Reply via email to