Module Name:    src
Committed By:   kre
Date:           Wed Jan 23 02:32:06 UTC 2019

Modified Files:
        src/lib/libwrap: expandm.c

Log Message:
There's no point setting errno, it is just overwritten by err
in the exit path ... this function never fails, it simply sometimes
doesn't actually expand the %m and just leaves the format string
intact.

And declare variables at the head of their scope, not at some random
place in the middle of the code, whatever C allows, that is just ugly.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/lib/libwrap/expandm.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libwrap/expandm.c
diff -u src/lib/libwrap/expandm.c:1.9 src/lib/libwrap/expandm.c:1.10
--- src/lib/libwrap/expandm.c:1.9	Wed Jan 23 02:00:00 2019
+++ src/lib/libwrap/expandm.c	Wed Jan 23 02:32:06 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: expandm.c,v 1.9 2019/01/23 02:00:00 christos Exp $	*/
+/*	$NetBSD: expandm.c,v 1.10 2019/01/23 02:32:06 kre Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: expandm.c,v 1.9 2019/01/23 02:00:00 christos Exp $");
+__RCSID("$NetBSD: expandm.c,v 1.10 2019/01/23 02:32:06 kre Exp $");
 
 #include <limits.h>
 #include <stdio.h>
@@ -56,11 +56,12 @@ expandm(const char *fmt, const char *sf,
 	buf = NULL;
 	for (ptr = fmt; (m = strstr(ptr, "%m")) != NULL; ptr = m + 2) {
 		size_t cnt = 0;
+		size_t nlen;
 
 		for (char *p = m; p >= ptr && *p == '%'; p--)
 			cnt++;
 
-		size_t nlen = (size_t)(m - ptr);
+		nlen = (size_t)(m - ptr);
 		/*
 		 * we can't exceed INT_MAX because int is used as 
 		 * a format width
@@ -73,10 +74,8 @@ expandm(const char *fmt, const char *sf,
 			 * We can't exceed PTRDIFF_MAX because we would
 			 * not be able to address the pointers
 			 */
-			if (tlen >= PTRDIFF_MAX) {
-				errno = EINVAL;
+			if (tlen >= PTRDIFF_MAX)
 				goto out;
-			}
 
 			nbuf = realloc(buf, tlen + 1);
 			if (nbuf == NULL)

Reply via email to