Module Name:    src
Committed By:   joerg
Date:           Wed May 16 20:21:39 UTC 2018

Modified Files:
        src/lib/libc/gen: sysctl.c
        src/sys/sys: sysctl.h

Log Message:
Avoid complicated arithmetic involving NULL.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/lib/libc/gen/sysctl.c
cvs rdiff -u -r1.225 -r1.226 src/sys/sys/sysctl.h

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

Modified files:

Index: src/lib/libc/gen/sysctl.c
diff -u src/lib/libc/gen/sysctl.c:1.36 src/lib/libc/gen/sysctl.c:1.37
--- src/lib/libc/gen/sysctl.c:1.36	Tue Jan 10 17:46:47 2017
+++ src/lib/libc/gen/sysctl.c	Wed May 16 20:21:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysctl.c,v 1.36 2017/01/10 17:46:47 christos Exp $	*/
+/*	$NetBSD: sysctl.c,v 1.37 2018/05/16 20:21:39 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)sysctl.c	8.2 (Berkeley) 1/4/94";
 #else
-__RCSID("$NetBSD: sysctl.c,v 1.36 2017/01/10 17:46:47 christos Exp $");
+__RCSID("$NetBSD: sysctl.c,v 1.37 2018/05/16 20:21:39 joerg Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -309,7 +309,7 @@ user_sysctl(const int *name, unsigned in
 				_DIAGASSERT(__type_fit(uint32_t, dlen));
 				d1->descr_len = (uint32_t)dlen;
 			}
-			d = (size_t)__sysc_desc_adv(NULL, d1->descr_len);
+			d = (size_t)__sysc_desc_len(d1->descr_len);
 			if (d2 != NULL)
 				memcpy(d2, d1, d);
 			sz += d;

Index: src/sys/sys/sysctl.h
diff -u src/sys/sys/sysctl.h:1.225 src/sys/sys/sysctl.h:1.226
--- src/sys/sys/sysctl.h:1.225	Fri Sep  8 10:53:55 2017
+++ src/sys/sys/sysctl.h	Wed May 16 20:21:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysctl.h,v 1.225 2017/09/08 10:53:55 wiz Exp $	*/
+/*	$NetBSD: sysctl.h,v 1.226 2018/05/16 20:21:39 joerg Exp $	*/
 
 /*
  * Copyright (c) 1989, 1993
@@ -1472,10 +1472,11 @@ struct sysctldesc {
 };
 
 #define __sysc_desc_roundup(x) ((((x) - 1) | (sizeof(int32_t) - 1)) + 1)
+#define __sysc_desc_len(l) (offsetof(struct sysctldesc, descr_str) +\
+		__sysc_desc_roundup(l))
 #define __sysc_desc_adv(d, l) \
 	(/*XXXUNCONST ptr cast*/(struct sysctldesc *) \
-	__UNCONST(((const char*)(d)) + offsetof(struct sysctldesc, descr_str) +\
-		__sysc_desc_roundup(l)))
+	__UNCONST(((const char*)(d)) + __sysc_desc_len(l)))
 #define NEXT_DESCR(d) __sysc_desc_adv((d), (d)->descr_len)
 
 static __inline const struct sysctlnode *

Reply via email to