summaryrefslogtreecommitdiff
path: root/openbsd-compat/fmt_scaled.c
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2017-03-29 16:34:02 +1100
committerDarren Tucker <dtucker@zip.com.au>2017-03-29 16:34:02 +1100
commitc73a229e4edf98920f395e19fd310684fc6bb951 (patch)
tree4eb66783ee12d8a47a7f26ca010eed0d32f73ffe /openbsd-compat/fmt_scaled.c
parentd427b73bf5a564f663d16546dbcbd84ba8b9d4af (diff)
Import fmt_scaled.c rev 1.15 from OpenBSD.
Collapse underflow and overflow checks into a single block. ok djm@ millert@
Diffstat (limited to 'openbsd-compat/fmt_scaled.c')
-rw-r--r--openbsd-compat/fmt_scaled.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/openbsd-compat/fmt_scaled.c b/openbsd-compat/fmt_scaled.c
index 7e6a57d4..8af86601 100644
--- a/openbsd-compat/fmt_scaled.c
+++ b/openbsd-compat/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.
@@ -170,12 +170,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;
}