diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2020-10-12 22:08:35 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2020-10-12 22:08:35 +0000 |
commit | a575eb26f0ae95d94ff18ee8b482e93c08feb91b (patch) | |
tree | 12eda421b3d080a63f6605f44cc731ab0fa3d34e | |
parent | ef53b0617ae0009192465f85b3eebc8715d9108d (diff) |
make fixed-sized fixed-value mib[] arrays be const
ok guenther tb millert
-rw-r--r-- | lib/libc/compat-43/gethostid.c | 6 | ||||
-rw-r--r-- | lib/libc/compat-43/sethostid.c | 6 | ||||
-rw-r--r-- | lib/libc/gen/getdomainname.c | 6 | ||||
-rw-r--r-- | lib/libc/gen/gethostname.c | 6 | ||||
-rw-r--r-- | lib/libc/gen/getloadavg.c | 7 | ||||
-rw-r--r-- | lib/libc/gen/getpagesize.c | 6 | ||||
-rw-r--r-- | lib/libc/gen/setdomainname.c | 6 | ||||
-rw-r--r-- | lib/libc/gen/sethostname.c | 6 | ||||
-rw-r--r-- | lib/libc/gen/setproctitle.c | 6 | ||||
-rw-r--r-- | lib/libc/gmon/gmon.c | 6 | ||||
-rw-r--r-- | lib/libc/stdlib/malloc.c | 7 | ||||
-rw-r--r-- | lib/libcrypto/arc4random/getentropy_freebsd.c | 6 | ||||
-rw-r--r-- | lib/libcrypto/arc4random/getentropy_netbsd.c | 6 | ||||
-rw-r--r-- | lib/libkvm/kvm_proc.c | 6 | ||||
-rw-r--r-- | lib/librthread/rthread_np.c | 6 | ||||
-rw-r--r-- | lib/libutil/fmt_scaled.c | 8 | ||||
-rw-r--r-- | lib/libutil/getmaxpartitions.c | 7 | ||||
-rw-r--r-- | lib/libutil/getrawpartition.c | 7 |
18 files changed, 42 insertions, 72 deletions
diff --git a/lib/libc/compat-43/gethostid.c b/lib/libc/compat-43/gethostid.c index 60f0a67dd32..cf902135411 100644 --- a/lib/libc/compat-43/gethostid.c +++ b/lib/libc/compat-43/gethostid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gethostid.c,v 1.8 2015/01/14 23:03:50 deraadt Exp $ */ +/* $OpenBSD: gethostid.c,v 1.9 2020/10/12 22:08:32 deraadt Exp $ */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -35,12 +35,10 @@ long gethostid(void) { - int mib[2]; + const int mib[2] = { CTL_KERN, KERN_HOSTID }; size_t size; long value; - mib[0] = CTL_KERN; - mib[1] = KERN_HOSTID; size = sizeof value; if (sysctl(mib, 2, &value, &size, NULL, 0) == -1) return (-1); diff --git a/lib/libc/compat-43/sethostid.c b/lib/libc/compat-43/sethostid.c index 236f621131e..de80301db5c 100644 --- a/lib/libc/compat-43/sethostid.c +++ b/lib/libc/compat-43/sethostid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sethostid.c,v 1.9 2015/01/14 23:03:50 deraadt Exp $ */ +/* $OpenBSD: sethostid.c,v 1.10 2020/10/12 22:08:32 deraadt Exp $ */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -35,10 +35,8 @@ int sethostid(long hostid) { - int mib[2]; + const int mib[2] = { CTL_KERN, KERN_HOSTID }; - mib[0] = CTL_KERN; - mib[1] = KERN_HOSTID; if (sysctl(mib, 2, NULL, NULL, &hostid, sizeof hostid) == -1) return (-1); return (0); diff --git a/lib/libc/gen/getdomainname.c b/lib/libc/gen/getdomainname.c index b0d8dcf0ed0..2b21a8cd988 100644 --- a/lib/libc/gen/getdomainname.c +++ b/lib/libc/gen/getdomainname.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getdomainname.c,v 1.9 2015/09/12 14:56:50 guenther Exp $ */ +/* $OpenBSD: getdomainname.c,v 1.10 2020/10/12 22:08:33 deraadt Exp $ */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -35,11 +35,9 @@ int getdomainname(char *name, size_t namelen) { - int mib[2]; + const int mib[2] = { CTL_KERN, KERN_DOMAINNAME }; size_t size; - mib[0] = CTL_KERN; - mib[1] = KERN_DOMAINNAME; size = namelen; if (sysctl(mib, 2, name, &size, NULL, 0) == -1) return (-1); diff --git a/lib/libc/gen/gethostname.c b/lib/libc/gen/gethostname.c index aa1e4ce6cf3..aa28e0d1c05 100644 --- a/lib/libc/gen/gethostname.c +++ b/lib/libc/gen/gethostname.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gethostname.c,v 1.9 2015/09/12 14:56:50 guenther Exp $ */ +/* $OpenBSD: gethostname.c,v 1.10 2020/10/12 22:08:33 deraadt Exp $ */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -35,11 +35,9 @@ int gethostname(char *name, size_t namelen) { - int mib[2]; + const int mib[2] = { CTL_KERN, KERN_HOSTNAME }; size_t size; - mib[0] = CTL_KERN; - mib[1] = KERN_HOSTNAME; size = namelen; if (sysctl(mib, 2, name, &size, NULL, 0) == -1) return (-1); diff --git a/lib/libc/gen/getloadavg.c b/lib/libc/gen/getloadavg.c index f6e6b282222..5eb7fa7de75 100644 --- a/lib/libc/gen/getloadavg.c +++ b/lib/libc/gen/getloadavg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getloadavg.c,v 1.8 2019/06/28 13:32:41 deraadt Exp $ */ +/* $OpenBSD: getloadavg.c,v 1.9 2020/10/12 22:08:33 deraadt Exp $ */ /*- * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -46,11 +46,10 @@ int getloadavg(double loadavg[], int nelem) { struct loadavg loadinfo; - int i, mib[2]; + const int mib[2] = { CTL_VM, VM_LOADAVG }; + int i; size_t size; - mib[0] = CTL_VM; - mib[1] = VM_LOADAVG; size = sizeof(loadinfo); if (sysctl(mib, 2, &loadinfo, &size, NULL, 0) == -1) return (-1); diff --git a/lib/libc/gen/getpagesize.c b/lib/libc/gen/getpagesize.c index aa2919032fa..56717acc9bc 100644 --- a/lib/libc/gen/getpagesize.c +++ b/lib/libc/gen/getpagesize.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getpagesize.c,v 1.9 2016/03/20 02:32:40 guenther Exp $ */ +/* $OpenBSD: getpagesize.c,v 1.10 2020/10/12 22:08:33 deraadt Exp $ */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -36,11 +36,9 @@ int getpagesize(void) { if (_pagesize == 0) { - int mib[2]; + const int mib[2] = { CTL_HW, HW_PAGESIZE }; size_t size; - mib[0] = CTL_HW; - mib[1] = HW_PAGESIZE; size = sizeof _pagesize; if (sysctl(mib, 2, &_pagesize, &size, NULL, 0) == -1) return (-1); diff --git a/lib/libc/gen/setdomainname.c b/lib/libc/gen/setdomainname.c index 6e4a1c9ec56..3622dbe1b08 100644 --- a/lib/libc/gen/setdomainname.c +++ b/lib/libc/gen/setdomainname.c @@ -1,4 +1,4 @@ -/* $OpenBSD: setdomainname.c,v 1.9 2015/01/16 16:48:51 deraadt Exp $ */ +/* $OpenBSD: setdomainname.c,v 1.10 2020/10/12 22:08:33 deraadt Exp $ */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -35,10 +35,8 @@ int setdomainname(const char *name, size_t namelen) { - int mib[2]; + const int mib[2] = { CTL_KERN, KERN_DOMAINNAME }; - mib[0] = CTL_KERN; - mib[1] = KERN_DOMAINNAME; if (sysctl(mib, 2, NULL, NULL, (void *)name, namelen) == -1) return (-1); return (0); diff --git a/lib/libc/gen/sethostname.c b/lib/libc/gen/sethostname.c index 571db3969ee..0dc77ad14d8 100644 --- a/lib/libc/gen/sethostname.c +++ b/lib/libc/gen/sethostname.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sethostname.c,v 1.9 2015/01/16 16:48:51 deraadt Exp $ */ +/* $OpenBSD: sethostname.c,v 1.10 2020/10/12 22:08:33 deraadt Exp $ */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -35,10 +35,8 @@ int sethostname(const char *name, size_t namelen) { - int mib[2]; + const int mib[2] = { CTL_KERN, KERN_HOSTNAME }; - mib[0] = CTL_KERN; - mib[1] = KERN_HOSTNAME; if (sysctl(mib, 2, NULL, NULL, (void *)name, namelen) == -1) return (-1); return (0); diff --git a/lib/libc/gen/setproctitle.c b/lib/libc/gen/setproctitle.c index 22b1547253b..f76327852d9 100644 --- a/lib/libc/gen/setproctitle.c +++ b/lib/libc/gen/setproctitle.c @@ -1,4 +1,4 @@ -/* $OpenBSD: setproctitle.c,v 1.15 2016/03/13 18:34:20 guenther Exp $ */ +/* $OpenBSD: setproctitle.c,v 1.16 2020/10/12 22:08:33 deraadt Exp $ */ /* * Copyright (c) 1994, 1995 Christopher G. Demetriou * All rights reserved. @@ -64,11 +64,9 @@ setproctitle(const char *fmt, ...) if (ps == NULL) { struct _ps_strings _ps; - int mib[2]; + const int mib[2] = { CTL_VM, VM_PSSTRINGS }; size_t len; - mib[0] = CTL_VM; - mib[1] = VM_PSSTRINGS; len = sizeof(_ps); if (sysctl(mib, 2, &_ps, &len, NULL, 0) != 0) return; diff --git a/lib/libc/gmon/gmon.c b/lib/libc/gmon/gmon.c index c17fcc52bd1..1ce0a1c289e 100644 --- a/lib/libc/gmon/gmon.c +++ b/lib/libc/gmon/gmon.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gmon.c,v 1.31 2019/06/28 13:32:41 deraadt Exp $ */ +/* $OpenBSD: gmon.c,v 1.32 2020/10/12 22:08:33 deraadt Exp $ */ /*- * Copyright (c) 1983, 1992, 1993 * The Regents of the University of California. All rights reserved. @@ -146,7 +146,7 @@ _mcleanup(void) struct gmonparam *p = &_gmonparam; struct gmonhdr gmonhdr, *hdr; struct clockinfo clockinfo; - int mib[2]; + const int mib[2] = { CTL_KERN, KERN_CLOCKRATE }; size_t size; char *profdir; char *proffile; @@ -160,8 +160,6 @@ _mcleanup(void) ERR("_mcleanup: tos overflow\n"); size = sizeof(clockinfo); - mib[0] = CTL_KERN; - mib[1] = KERN_CLOCKRATE; if (sysctl(mib, 2, &clockinfo, &size, NULL, 0) == -1) { /* * Best guess diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c index a62bfac3e5e..86670fca876 100644 --- a/lib/libc/stdlib/malloc.c +++ b/lib/libc/stdlib/malloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: malloc.c,v 1.265 2020/10/09 16:01:48 otto Exp $ */ +/* $OpenBSD: malloc.c,v 1.266 2020/10/12 22:08:33 deraadt Exp $ */ /* * Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek <otto@drijf.net> * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org> @@ -406,7 +406,8 @@ static void omalloc_init(void) { char *p, *q, b[16]; - int i, j, mib[2]; + int i, j; + const int mib[2] = { CTL_VM, VM_MALLOC_CONF }; size_t sb; /* @@ -419,8 +420,6 @@ omalloc_init(void) for (i = 0; i < 3; i++) { switch (i) { case 0: - mib[0] = CTL_VM; - mib[1] = VM_MALLOC_CONF; sb = sizeof(b); j = sysctl(mib, 2, b, &sb, NULL, 0); if (j != 0) diff --git a/lib/libcrypto/arc4random/getentropy_freebsd.c b/lib/libcrypto/arc4random/getentropy_freebsd.c index 30cd68e97d6..ea90ffe2022 100644 --- a/lib/libcrypto/arc4random/getentropy_freebsd.c +++ b/lib/libcrypto/arc4random/getentropy_freebsd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getentropy_freebsd.c,v 1.3 2016/08/07 03:27:21 tb Exp $ */ +/* $OpenBSD: getentropy_freebsd.c,v 1.4 2020/10/12 22:08:33 deraadt Exp $ */ /* * Copyright (c) 2014 Pawel Jakub Dawidek <pjd@FreeBSD.org> @@ -32,11 +32,9 @@ static size_t getentropy_sysctl(u_char *buf, size_t size) { - int mib[2]; + const int mib[2] = { CTL_KERN, KERN_ARND }; size_t len, done; - mib[0] = CTL_KERN; - mib[1] = KERN_ARND; done = 0; do { diff --git a/lib/libcrypto/arc4random/getentropy_netbsd.c b/lib/libcrypto/arc4random/getentropy_netbsd.c index 45d68c9fda4..5dc89594cd9 100644 --- a/lib/libcrypto/arc4random/getentropy_netbsd.c +++ b/lib/libcrypto/arc4random/getentropy_netbsd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getentropy_netbsd.c,v 1.3 2016/08/07 03:27:21 tb Exp $ */ +/* $OpenBSD: getentropy_netbsd.c,v 1.4 2020/10/12 22:08:33 deraadt Exp $ */ /* * Copyright (c) 2014 Pawel Jakub Dawidek <pjd@FreeBSD.org> @@ -32,11 +32,9 @@ static size_t getentropy_sysctl(u_char *buf, size_t size) { - int mib[2]; + const int mib[2] = { CTL_KERN, KERN_ARND }; size_t len, done; - mib[0] = CTL_KERN; - mib[1] = KERN_ARND; done = 0; do { diff --git a/lib/libkvm/kvm_proc.c b/lib/libkvm/kvm_proc.c index f2733ccfc26..96f1ae31c4b 100644 --- a/lib/libkvm/kvm_proc.c +++ b/lib/libkvm/kvm_proc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kvm_proc.c,v 1.60 2019/06/28 13:32:42 deraadt Exp $ */ +/* $OpenBSD: kvm_proc.c,v 1.61 2020/10/12 22:08:33 deraadt Exp $ */ /* $NetBSD: kvm_proc.c,v 1.30 1999/03/24 05:50:50 mrg Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -436,11 +436,9 @@ kvm_doargv(kvm_t *kd, const struct kinfo_proc *p, int nchr, int isenv, if (ps == NULL) { struct _ps_strings _ps; - int mib[2]; + const int mib[2] = { CTL_VM, VM_PSSTRINGS }; size_t len; - mib[0] = CTL_VM; - mib[1] = VM_PSSTRINGS; len = sizeof(_ps); sysctl(mib, 2, &_ps, &len, NULL, 0); ps = (struct ps_strings *)_ps.val; diff --git a/lib/librthread/rthread_np.c b/lib/librthread/rthread_np.c index 64bd2db5aea..0b3f821ca7b 100644 --- a/lib/librthread/rthread_np.c +++ b/lib/librthread/rthread_np.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_np.c,v 1.21 2019/02/04 17:18:08 tedu Exp $ */ +/* $OpenBSD: rthread_np.c,v 1.22 2020/10/12 22:08:34 deraadt Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org> * Copyright (c) 2005 Otto Moerbeek <otto@openbsd.org> @@ -90,14 +90,12 @@ pthread_stackseg_np(pthread_t thread, stack_t *sinfo) _rthread_init(); if (gotself == 0) { - int mib[2]; + const int mib[2] = { CTL_VM, VM_PSSTRINGS }; size_t len; if (getrlimit(RLIMIT_STACK, &rl) != 0) return (EAGAIN); - mib[0] = CTL_VM; - mib[1] = VM_PSSTRINGS; len = sizeof(_ps); if (sysctl(mib, 2, &_ps, &len, NULL, 0) != 0) return (EAGAIN); diff --git a/lib/libutil/fmt_scaled.c b/lib/libutil/fmt_scaled.c index f9f644d53e5..ecf1bec62f1 100644 --- a/lib/libutil/fmt_scaled.c +++ b/lib/libutil/fmt_scaled.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fmt_scaled.c,v 1.18 2019/01/14 23:52:06 bluhm Exp $ */ +/* $OpenBSD: fmt_scaled.c,v 1.19 2020/10/12 22:08:34 deraadt Exp $ */ /* * Copyright (c) 2001, 2002, 2003 Ian F. Darwin. All rights reserved. @@ -50,9 +50,9 @@ typedef enum { } unit_type; /* These three arrays MUST be in sync! XXX make a struct */ -static unit_type units[] = { NONE, KILO, MEGA, GIGA, TERA, PETA, EXA }; -static char scale_chars[] = "BKMGTPE"; -static long long scale_factors[] = { +static const unit_type units[] = { NONE, KILO, MEGA, GIGA, TERA, PETA, EXA }; +static const char scale_chars[] = "BKMGTPE"; +static const long long scale_factors[] = { 1LL, 1024LL, 1024LL*1024, diff --git a/lib/libutil/getmaxpartitions.c b/lib/libutil/getmaxpartitions.c index dd9d2bc6b3b..7a9d7c5fd97 100644 --- a/lib/libutil/getmaxpartitions.c +++ b/lib/libutil/getmaxpartitions.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getmaxpartitions.c,v 1.10 2019/06/28 13:32:43 deraadt Exp $ */ +/* $OpenBSD: getmaxpartitions.c,v 1.11 2020/10/12 22:08:34 deraadt Exp $ */ /* $NetBSD: getmaxpartitions.c,v 1.1 1996/05/16 07:03:31 thorpej Exp $ */ /*- @@ -39,11 +39,10 @@ int getmaxpartitions(void) { - int maxpart, mib[2]; + const int mib[2] = { CTL_KERN, KERN_MAXPARTITIONS }; + int maxpart; size_t varlen; - mib[0] = CTL_KERN; - mib[1] = KERN_MAXPARTITIONS; varlen = sizeof(maxpart); if (sysctl(mib, 2, &maxpart, &varlen, NULL, (size_t)0) == -1) return (-1); diff --git a/lib/libutil/getrawpartition.c b/lib/libutil/getrawpartition.c index bc7fa06d5f1..cd52bfc60f8 100644 --- a/lib/libutil/getrawpartition.c +++ b/lib/libutil/getrawpartition.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getrawpartition.c,v 1.10 2019/06/28 13:32:43 deraadt Exp $ */ +/* $OpenBSD: getrawpartition.c,v 1.11 2020/10/12 22:08:34 deraadt Exp $ */ /* $NetBSD: getrawpartition.c,v 1.1 1996/05/16 07:03:33 thorpej Exp $ */ /*- @@ -39,11 +39,10 @@ int getrawpartition(void) { - int rawpart, mib[2]; + const int mib[2] = { CTL_KERN, KERN_RAWPARTITION }; + int rawpart; size_t varlen; - mib[0] = CTL_KERN; - mib[1] = KERN_RAWPARTITION; varlen = sizeof(rawpart); if (sysctl(mib, 2, &rawpart, &varlen, NULL, (size_t)0) == -1) return (-1); |