Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern Signed overflow is undefined behavior, and one vers...
details: https://anonhg.NetBSD.org/src/rev/548d6f64b647
branches: trunk
changeset: 783243:548d6f64b647
user: pooka <pooka%NetBSD.org@localhost>
date: Wed Dec 12 11:10:56 2012 +0000
description:
Signed overflow is undefined behavior, and one version of gcc
clearly tells us:
kern_rate.c:98: warning: assuming signed overflow does not
occur when assuming that (X + c) > X is always true
Check value against INT_MAX instead. Also, for good measure throw
in a __predict() to flag the assumed common case.
diffstat:
sys/kern/kern_rate.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diffs (27 lines):
diff -r b393ff14af55 -r 548d6f64b647 sys/kern/kern_rate.c
--- a/sys/kern/kern_rate.c Wed Dec 12 09:20:35 2012 +0000
+++ b/sys/kern/kern_rate.c Wed Dec 12 11:10:56 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_rate.c,v 1.1 2008/09/25 17:17:10 pooka Exp $ */
+/* $NetBSD: kern_rate.c,v 1.2 2012/12/12 11:10:56 pooka Exp $ */
/*-
* Copyright (c) 2000, 2004, 2005, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_rate.c,v 1.1 2008/09/25 17:17:10 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_rate.c,v 1.2 2012/12/12 11:10:56 pooka Exp $");
#include <sys/param.h>
#include <sys/time.h>
@@ -95,7 +95,7 @@
#if 1 /*DIAGNOSTIC?*/
/* be careful about wrap-around */
- if (*curpps + 1 > *curpps)
+ if (__predict_true(*curpps != INT_MAX))
*curpps = *curpps + 1;
#else
/*
Home |
Main Index |
Thread Index |
Old Index