Source-Changes-HG archive

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

[src/trunk]: src Avoid complicated arithmetic involving NULL.



details:   https://anonhg.NetBSD.org/src/rev/fd86101c4c4b
branches:  trunk
changeset: 322774:fd86101c4c4b
user:      joerg <joerg%NetBSD.org@localhost>
date:      Wed May 16 20:21:39 2018 +0000

description:
Avoid complicated arithmetic involving NULL.

diffstat:

 lib/libc/gen/sysctl.c |  6 +++---
 sys/sys/sysctl.h      |  7 ++++---
 2 files changed, 7 insertions(+), 6 deletions(-)

diffs (50 lines):

diff -r eff231307f74 -r fd86101c4c4b lib/libc/gen/sysctl.c
--- a/lib/libc/gen/sysctl.c     Wed May 16 19:53:54 2018 +0000
+++ b/lib/libc/gen/sysctl.c     Wed May 16 20:21:39 2018 +0000
@@ -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 @@
                                _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;
diff -r eff231307f74 -r fd86101c4c4b sys/sys/sysctl.h
--- a/sys/sys/sysctl.h  Wed May 16 19:53:54 2018 +0000
+++ b/sys/sys/sysctl.h  Wed May 16 20:21:39 2018 +0000
@@ -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 @@
 };
 
 #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 *



Home | Main Index | Thread Index | Old Index