Source-Changes-HG archive

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

[src/trunk]: src/sys kern: Work around spurious -Wtype-limits warnings.



details:   https://anonhg.NetBSD.org/src/rev/ef40dc3c8f88
branches:  trunk
changeset: 368355:ef40dc3c8f88
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Wed Jul 06 13:52:24 2022 +0000

description:
kern: Work around spurious -Wtype-limits warnings.

This useless garbage warning is apparently designed to make it
painful to write portable safe arithmetic and I think we ought to
just disable it.

diffstat:

 sys/kern/vfs_vnops.c |  12 ++++++++----
 sys/uvm/uvm_device.c |   6 ++++--
 2 files changed, 12 insertions(+), 6 deletions(-)

diffs (62 lines):

diff -r 74d6f7692890 -r ef40dc3c8f88 sys/kern/vfs_vnops.c
--- a/sys/kern/vfs_vnops.c      Wed Jul 06 13:10:49 2022 +0000
+++ b/sys/kern/vfs_vnops.c      Wed Jul 06 13:52:24 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_vnops.c,v 1.232 2022/07/06 01:15:32 riastradh Exp $        */
+/*     $NetBSD: vfs_vnops.c,v 1.233 2022/07/06 13:52:24 riastradh Exp $        */
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_vnops.c,v 1.232 2022/07/06 01:15:32 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_vnops.c,v 1.233 2022/07/06 13:52:24 riastradh Exp $");
 
 #include "veriexec.h"
 
@@ -930,8 +930,12 @@
        if (vp->v_type != VCHR && off < 0) {
                return EINVAL;
        }
-       if (vp->v_type != VCHR &&
-           (size > __type_max(off_t) || off > __type_max(off_t) - size)) {
+#if SIZE_MAX > UINT32_MAX      /* XXX -Wtype-limits */
+       if (vp->v_type != VCHR && size > __type_max(off_t)) {
+               return EOVERFLOW;
+       }
+#endif
+       if (vp->v_type != VCHR && off > __type_max(off_t) - size) {
                /* no offset wrapping */
                return EOVERFLOW;
        }
diff -r 74d6f7692890 -r ef40dc3c8f88 sys/uvm/uvm_device.c
--- a/sys/uvm/uvm_device.c      Wed Jul 06 13:10:49 2022 +0000
+++ b/sys/uvm/uvm_device.c      Wed Jul 06 13:52:24 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_device.c,v 1.77 2022/07/06 01:16:36 riastradh Exp $        */
+/*     $NetBSD: uvm_device.c,v 1.78 2022/07/06 13:52:24 riastradh Exp $        */
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_device.c,v 1.77 2022/07/06 01:16:36 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_device.c,v 1.78 2022/07/06 13:52:24 riastradh Exp $");
 
 #include "opt_uvmhist.h"
 
@@ -139,8 +139,10 @@
        if ((cdev->d_flag & D_NEGOFFSAFE) == 0 && off != UVM_UNKNOWN_OFFSET) {
                if (off < 0)
                        return NULL;
+#if SIZE_MAX > UINT32_MAX      /* XXX -Wtype-limits */
                if (size > __type_max(voff_t))
                        return NULL;
+#endif
                if (off > __type_max(voff_t) - size)
                        return NULL;
        }



Home | Main Index | Thread Index | Old Index