Source-Changes-HG archive

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

[src/trunk]: src Explicitly cast pointers to uintptr_t before casting to enum...



details:   https://anonhg.NetBSD.org/src/rev/f6f2269bc206
branches:  trunk
changeset: 745015:f6f2269bc206
user:      joerg <joerg%NetBSD.org@localhost>
date:      Fri Feb 21 00:26:21 2020 +0000

description:
Explicitly cast pointers to uintptr_t before casting to enums. They are
not necessarily the same size. Don't cast pointers to bool, check for
NULL instead.

diffstat:

 external/bsd/libevent/dist/test/regress_http.c   |   6 +++---
 external/bsd/libevent/dist/test/regress_ssl.c    |  12 ++++++------
 external/bsd/wpa/dist/src/radius/radius_client.c |   2 +-
 external/cddl/osnet/dist/tools/ctf/cvt/iidesc.c  |   2 +-
 sys/arch/x86/x86/spectre.c                       |  12 ++++++------
 sys/arch/x86/x86/tsc.c                           |   6 +++---
 sys/dev/clockctl.c                               |   8 ++++----
 sys/dev/nvmm/x86/nvmm_x86_svm.c                  |   6 +++---
 sys/dev/nvmm/x86/nvmm_x86_vmx.c                  |   6 +++---
 sys/dist/pf/net/pf_ioctl.c                       |   6 +++---
 sys/external/bsd/ipf/netinet/ip_fil_netbsd.c     |   6 +++---
 sys/kern/kern_ktrace.c                           |   6 +++---
 sys/kern/kern_proc.c                             |   6 +++---
 sys/kern/kern_resource.c                         |   6 +++---
 sys/kern/kern_veriexec.c                         |   8 ++++----
 sys/kern/sys_pset.c                              |   8 ++++----
 sys/kern/sysv_ipc.c                              |   6 +++---
 sys/kern/uipc_socket.c                           |   6 +++---
 sys/kern/vfs_init.c                              |   6 +++---
 sys/net/if.c                                     |   6 +++---
 sys/netsmb/smb_conn.c                            |   6 +++---
 sys/secmodel/extensions/secmodel_extensions.c    |  10 +++++-----
 sys/secmodel/keylock/secmodel_keylock.c          |  12 ++++++------
 sys/secmodel/securelevel/secmodel_securelevel.c  |  12 ++++++------
 sys/secmodel/suser/secmodel_suser.c              |  12 ++++++------
 25 files changed, 91 insertions(+), 91 deletions(-)

diffs (truncated from 816 to 300 lines):

diff -r 756a7139eea7 -r f6f2269bc206 external/bsd/libevent/dist/test/regress_http.c
--- a/external/bsd/libevent/dist/test/regress_http.c    Thu Feb 20 23:57:16 2020 +0000
+++ b/external/bsd/libevent/dist/test/regress_http.c    Fri Feb 21 00:26:21 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: regress_http.c,v 1.5 2017/01/31 23:17:40 christos Exp $        */
+/*     $NetBSD: regress_http.c,v 1.6 2020/02/21 00:26:21 joerg Exp $   */
 /*
  * Copyright (c) 2003-2007 Niels Provos <provos%citi.umich.edu@localhost>
  * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
@@ -35,7 +35,7 @@
 
 #include "event2/event-config.h"
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: regress_http.c,v 1.5 2017/01/31 23:17:40 christos Exp $");
+__RCSID("$NetBSD: regress_http.c,v 1.6 2020/02/21 00:26:21 joerg Exp $");
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -1426,7 +1426,7 @@
        struct event_base *base_to_fill = data->base;
 
        enum http_cancel_test_type type =
-               (enum http_cancel_test_type)data->setup_data;
+               (enum http_cancel_test_type)(uintptr_t)data->setup_data;
        struct evhttp *http = http_setup(&port, data->base, 0);
 
        if (type & BY_HOST) {
diff -r 756a7139eea7 -r f6f2269bc206 external/bsd/libevent/dist/test/regress_ssl.c
--- a/external/bsd/libevent/dist/test/regress_ssl.c     Thu Feb 20 23:57:16 2020 +0000
+++ b/external/bsd/libevent/dist/test/regress_ssl.c     Fri Feb 21 00:26:21 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: regress_ssl.c,v 1.3 2017/01/31 23:17:40 christos Exp $ */
+/*     $NetBSD: regress_ssl.c,v 1.4 2020/02/21 00:26:21 joerg Exp $    */
 /*
  * Copyright (c) 2009-2012 Niels Provos and Nick Mathewson
  *
@@ -265,7 +265,7 @@
        int n;
 
        enum regress_openssl_type type;
-       type = (enum regress_openssl_type)ctx;
+       type = (enum regress_openssl_type)(uintptr_t)ctx;
 
        line = evbuffer_readln(b, NULL, EVBUFFER_EOL_LF);
        if (! line)
@@ -306,7 +306,7 @@
 eventcb(struct bufferevent *bev, short what, void *ctx)
 {
        enum regress_openssl_type type;
-       type = (enum regress_openssl_type)ctx;
+       type = (enum regress_openssl_type)(uintptr_t)ctx;
 
        TT_BLATHER(("Got event %d", (int)what));
        if (what & BEV_EVENT_CONNECTED) {
@@ -407,7 +407,7 @@
        evutil_socket_t *fd_pair = NULL;
 
        enum regress_openssl_type type;
-       type = (enum regress_openssl_type)data->setup_data;
+       type = (enum regress_openssl_type)(uintptr_t)data->setup_data;
 
        tt_assert(cert);
        tt_assert(key);
@@ -526,7 +526,7 @@
        enum regress_openssl_type type;
        SSL *ssl = SSL_new(get_ssl_ctx());
 
-       type = (enum regress_openssl_type)data->setup_data;
+       type = (enum regress_openssl_type)(uintptr_t)data->setup_data;
 
        SSL_use_certificate(ssl, ssl_getcert());
        SSL_use_PrivateKey(ssl, ssl_getkey());
@@ -678,7 +678,7 @@
        struct rwcount rw = { -1, 0, 0 };
        enum regress_openssl_type type;
 
-       type = (enum regress_openssl_type)data->setup_data;
+       type = (enum regress_openssl_type)(uintptr_t)data->setup_data;
 
        init_ssl();
 
diff -r 756a7139eea7 -r f6f2269bc206 external/bsd/wpa/dist/src/radius/radius_client.c
--- a/external/bsd/wpa/dist/src/radius/radius_client.c  Thu Feb 20 23:57:16 2020 +0000
+++ b/external/bsd/wpa/dist/src/radius/radius_client.c  Fri Feb 21 00:26:21 2020 +0000
@@ -791,7 +791,7 @@
 {
        struct radius_client_data *radius = eloop_ctx;
        struct hostapd_radius_servers *conf = radius->conf;
-       RadiusType msg_type = (RadiusType) sock_ctx;
+       RadiusType msg_type = (RadiusType)(uintptr_t) sock_ctx;
        int len, roundtrip;
        unsigned char buf[3000];
        struct radius_msg *msg;
diff -r 756a7139eea7 -r f6f2269bc206 external/cddl/osnet/dist/tools/ctf/cvt/iidesc.c
--- a/external/cddl/osnet/dist/tools/ctf/cvt/iidesc.c   Thu Feb 20 23:57:16 2020 +0000
+++ b/external/cddl/osnet/dist/tools/ctf/cvt/iidesc.c   Fri Feb 21 00:26:21 2020 +0000
@@ -183,7 +183,7 @@
 iidesc_count_type(void *data, void *private)
 {
        iidesc_t *ii = data;
-       iitype_t match = (iitype_t)private;
+       iitype_t match = (iitype_t)(uintptr_t)private;
 
        return (ii->ii_type == match);
 }
diff -r 756a7139eea7 -r f6f2269bc206 sys/arch/x86/x86/spectre.c
--- a/sys/arch/x86/x86/spectre.c        Thu Feb 20 23:57:16 2020 +0000
+++ b/sys/arch/x86/x86/spectre.c        Fri Feb 21 00:26:21 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: spectre.c,v 1.33 2020/01/31 08:55:38 maxv Exp $        */
+/*     $NetBSD: spectre.c,v 1.34 2020/02/21 00:26:22 joerg Exp $       */
 
 /*
  * Copyright (c) 2018-2019 NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: spectre.c,v 1.33 2020/01/31 08:55:38 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spectre.c,v 1.34 2020/02/21 00:26:22 joerg Exp $");
 
 #include "opt_spectre.h"
 
@@ -277,7 +277,7 @@
 mitigation_v2_change_cpu(void *arg1, void *arg2)
 {
        struct cpu_info *ci = curcpu();
-       bool enabled = (bool)arg1;
+       bool enabled = arg1 != NULL;
        u_long psl = 0;
 
        /* Rendez-vous 1 (IBRS only). */
@@ -488,7 +488,7 @@
 static void
 mitigation_v4_change_cpu(void *arg1, void *arg2)
 {
-       bool enabled = (bool)arg1;
+       bool enabled = arg1 != NULL;
 
        mitigation_v4_apply_cpu(enabled);
 }
@@ -635,7 +635,7 @@
 mitigation_mds_change_cpu(void *arg1, void *arg2)
 {
        struct cpu_info *ci = curcpu();
-       bool enabled = (bool)arg1;
+       bool enabled = arg1 != NULL;
        u_long psl = 0;
 
        /* Rendez-vous 1. */
@@ -812,7 +812,7 @@
 mitigation_taa_change_cpu(void *arg1, void *arg2)
 {
        struct cpu_info *ci = curcpu();
-       bool enabled = (bool)arg1;
+       bool enabled = arg1 != NULL;
 
        mitigation_taa_apply_cpu(ci, enabled);
 }
diff -r 756a7139eea7 -r f6f2269bc206 sys/arch/x86/x86/tsc.c
--- a/sys/arch/x86/x86/tsc.c    Thu Feb 20 23:57:16 2020 +0000
+++ b/sys/arch/x86/x86/tsc.c    Fri Feb 21 00:26:21 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tsc.c,v 1.37 2017/10/02 19:23:16 maxv Exp $    */
+/*     $NetBSD: tsc.c,v 1.38 2020/02/21 00:26:22 joerg Exp $   */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.37 2017/10/02 19:23:16 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.38 2020/02/21 00:26:22 joerg Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -271,7 +271,7 @@
 static void
 tsc_apply_cpu(void *arg1, void *arg2)
 {
-       bool enable = (bool)arg1;
+       bool enable = arg1 != NULL;
        if (enable) {
                lcr4(rcr4() & ~CR4_TSD);
        } else {
diff -r 756a7139eea7 -r f6f2269bc206 sys/dev/clockctl.c
--- a/sys/dev/clockctl.c        Thu Feb 20 23:57:16 2020 +0000
+++ b/sys/dev/clockctl.c        Fri Feb 21 00:26:21 2020 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: clockctl.c,v 1.37 2019/03/01 11:06:56 pgoyette Exp $ */
+/*      $NetBSD: clockctl.c,v 1.38 2020/02/21 00:26:22 joerg Exp $ */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: clockctl.c,v 1.37 2019/03/01 11:06:56 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: clockctl.c,v 1.38 2020/02/21 00:26:22 joerg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ntp.h"
@@ -90,13 +90,13 @@
        bool device_context;
 
        result = KAUTH_RESULT_DEFER;
-       req = (enum kauth_system_req)arg0;
+       req = (enum kauth_system_req)(uintptr_t)arg0;
 
        if ((action != KAUTH_SYSTEM_TIME) ||
            (req != KAUTH_REQ_SYSTEM_TIME_SYSTEM))
                return result;
 
-       device_context = (bool)arg3;
+       device_context = arg3 != NULL;
 
        /* Device is controlled by permissions, so allow. */
        if (device_context)
diff -r 756a7139eea7 -r f6f2269bc206 sys/dev/nvmm/x86/nvmm_x86_svm.c
--- a/sys/dev/nvmm/x86/nvmm_x86_svm.c   Thu Feb 20 23:57:16 2020 +0000
+++ b/sys/dev/nvmm/x86/nvmm_x86_svm.c   Fri Feb 21 00:26:21 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nvmm_x86_svm.c,v 1.55 2019/12/10 18:06:50 ad Exp $     */
+/*     $NetBSD: nvmm_x86_svm.c,v 1.56 2020/02/21 00:26:22 joerg Exp $  */
 
 /*
  * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_svm.c,v 1.55 2019/12/10 18:06:50 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_svm.c,v 1.56 2020/02/21 00:26:22 joerg Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -2314,7 +2314,7 @@
 static void
 svm_change_cpu(void *arg1, void *arg2)
 {
-       bool enable = (bool)arg1;
+       bool enable = arg1 != NULL;
        uint64_t msr;
 
        msr = rdmsr(MSR_VMCR);
diff -r 756a7139eea7 -r f6f2269bc206 sys/dev/nvmm/x86/nvmm_x86_vmx.c
--- a/sys/dev/nvmm/x86/nvmm_x86_vmx.c   Thu Feb 20 23:57:16 2020 +0000
+++ b/sys/dev/nvmm/x86/nvmm_x86_vmx.c   Fri Feb 21 00:26:21 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nvmm_x86_vmx.c,v 1.48 2020/01/09 16:27:57 maxv Exp $   */
+/*     $NetBSD: nvmm_x86_vmx.c,v 1.49 2020/02/21 00:26:22 joerg Exp $  */
 
 /*
  * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_vmx.c,v 1.48 2020/01/09 16:27:57 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_vmx.c,v 1.49 2020/02/21 00:26:22 joerg Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -3115,7 +3115,7 @@
 vmx_change_cpu(void *arg1, void *arg2)
 {
        struct cpu_info *ci = curcpu();
-       bool enable = (bool)arg1;
+       bool enable = arg1 != NULL;
        uint64_t cr4;
 
        if (!enable) {
diff -r 756a7139eea7 -r f6f2269bc206 sys/dist/pf/net/pf_ioctl.c
--- a/sys/dist/pf/net/pf_ioctl.c        Thu Feb 20 23:57:16 2020 +0000
+++ b/sys/dist/pf/net/pf_ioctl.c        Fri Feb 21 00:26:21 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pf_ioctl.c,v 1.56 2018/08/10 07:16:13 maxv Exp $       */
+/*     $NetBSD: pf_ioctl.c,v 1.57 2020/02/21 00:26:22 joerg Exp $      */
 /*     $OpenBSD: pf_ioctl.c,v 1.182 2007/06/24 11:17:13 mcbride Exp $ */
 
 /*
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pf_ioctl.c,v 1.56 2018/08/10 07:16:13 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pf_ioctl.c,v 1.57 2020/02/21 00:26:22 joerg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -213,7 +213,7 @@
        enum kauth_network_req req;
 
        result = KAUTH_RESULT_DEFER;
-       req = (enum kauth_network_req)arg0;
+       req = (enum kauth_network_req)(uintptr_t)arg0;
 
        if (action != KAUTH_NETWORK_FIREWALL)



Home | Main Index | Thread Index | Old Index