Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libutil - not all asprintfs return -1 *and* set buf = NU...



details:   https://anonhg.NetBSD.org/src/rev/a330bcab13df
branches:  trunk
changeset: 805876:a330bcab13df
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Jan 22 16:19:08 2015 +0000

description:
- not all asprintfs return -1 *and* set buf = NULL, check explicitly.
- don't shadow basename(3)

diffstat:

 lib/libutil/pidfile.c |  13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)

diffs (39 lines):

diff -r eccfb9d06119 -r a330bcab13df lib/libutil/pidfile.c
--- a/lib/libutil/pidfile.c     Thu Jan 22 15:29:27 2015 +0000
+++ b/lib/libutil/pidfile.c     Thu Jan 22 16:19:08 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pidfile.c,v 1.9 2011/03/29 13:55:37 jmmv Exp $ */
+/*     $NetBSD: pidfile.c,v 1.10 2015/01/22 16:19:08 christos Exp $    */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: pidfile.c,v 1.9 2011/03/29 13:55:37 jmmv Exp $");
+__RCSID("$NetBSD: pidfile.c,v 1.10 2015/01/22 16:19:08 christos Exp $");
 #endif
 
 #include <sys/param.h>
@@ -105,15 +105,16 @@
  * Returns a pointer to a dynamically-allocatd string containing the absolute
  * path to the pidfile; NULL on failure. */
 static char *
-generate_varrun_path(const char *basename)
+generate_varrun_path(const char *bname)
 {
        char *path;
 
-       if (basename == NULL)
-               basename = getprogname();
+       if (bname == NULL)
+               bname = getprogname();
 
        /* _PATH_VARRUN includes trailing / */
-       (void) asprintf(&path, "%s%s.pid", _PATH_VARRUN, basename);
+       if (asprintf(&path, "%s%s.pid", _PATH_VARRUN, basename) == -1)
+               return NULL;
        return path;
 }
 



Home | Main Index | Thread Index | Old Index