From b163cf8017dc649b4e83764fac490235352b2130 Mon Sep 17 00:00:00 2001 From: christos Date: Sat, 15 Jan 2011 15:42:10 +0000 Subject: [PATCH] Fix reversed oveflow check. --- lib/libc/time/localtime.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/libc/time/localtime.c b/lib/libc/time/localtime.c index aec206530d09..194fd9cd5d53 100644 --- a/lib/libc/time/localtime.c +++ b/lib/libc/time/localtime.c @@ -1,4 +1,4 @@ -/* $NetBSD: localtime.c,v 1.53 2011/01/15 12:31:57 martin Exp $ */ +/* $NetBSD: localtime.c,v 1.54 2011/01/15 15:42:10 christos Exp $ */ /* ** This file is in the public domain, so clarified as of @@ -10,7 +10,7 @@ #if 0 static char elsieid[] = "@(#)localtime.c 8.9"; #else -__RCSID("$NetBSD: localtime.c,v 1.53 2011/01/15 12:31:57 martin Exp $"); +__RCSID("$NetBSD: localtime.c,v 1.54 2011/01/15 15:42:10 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -1704,8 +1704,10 @@ increment_overflow(int *number, int delta) int number0; number0 = *number; + if (delta < 0 ? number0 < INT_MIN - delta : INT_MAX - delta < number0) + return 1; *number += delta; - return (*number < number0) != (delta < 0); + return 0; } static int @@ -1714,8 +1716,10 @@ long_increment_overflow(long *number, int delta) long number0; number0 = *number; + if (delta < 0 ? number0 < LONG_MIN - delta : LONG_MAX - delta < number0) + return 1; *number += delta; - return (*number < number0) != (delta < 0); + return 0; } static int