summaryrefslogtreecommitdiff
path: root/lib/libutil/fmt_scaled.c
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@cvs.openbsd.org>2017-03-15 05:25:57 +0000
committerDarren Tucker <dtucker@cvs.openbsd.org>2017-03-15 05:25:57 +0000
commit15d334b89177e3f8eef19f93f800b9db643460be (patch)
treef98a683d0055b509e96ea8e172565ce3b00fb2e7 /lib/libutil/fmt_scaled.c
parent8ec35da77540668e3278f64ab8bf1e9ae2ed4936 (diff)
Collapse underflow and overflow checks into a single block.
ok djm@ millert@
Diffstat (limited to 'lib/libutil/fmt_scaled.c')
-rw-r--r--lib/libutil/fmt_scaled.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/lib/libutil/fmt_scaled.c b/lib/libutil/fmt_scaled.c
index 76085153752..f43b77d5c3b 100644
--- a/lib/libutil/fmt_scaled.c
+++ b/lib/libutil/fmt_scaled.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fmt_scaled.c,v 1.14 2017/03/15 00:13:18 dtucker Exp $ */
+/* $OpenBSD: fmt_scaled.c,v 1.15 2017/03/15 05:25:56 dtucker Exp $ */
/*
* Copyright (c) 2001, 2002, 2003 Ian F. Darwin. All rights reserved.
@@ -166,12 +166,9 @@ scan_scaled(char *scaled, long long *result)
}
scale_fact = scale_factors[i];
- if (whole >= LLONG_MAX / scale_fact) {
- errno = ERANGE;
- return -1;
- }
-
- if (whole <= LLONG_MIN / scale_fact) {
+ /* check for overflow and underflow after scaling */
+ if (whole > LLONG_MAX / scale_fact ||
+ whole < LLONG_MIN / scale_fact) {
errno = ERANGE;
return -1;
}