Browse Source

Calling llabs(LLONG_MIN) is undefined behavior, llvm 7.0.1 does not

work with our old code.  In fmt_scaled() move the check before
calling llabs().
found by regress/lib/libutil/fmt_scaled; OK deraadt@ millert@ tedu@
OPENBSD_6_5
bluhm 5 years ago
parent
commit
df4fda1761
1 changed files with 9 additions and 5 deletions
  1. +9
    -5
      src/lib/libutil/fmt_scaled.c

+ 9
- 5
src/lib/libutil/fmt_scaled.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: fmt_scaled.c,v 1.17 2018/05/14 04:39:04 djm Exp $ */
/* $OpenBSD: fmt_scaled.c,v 1.18 2019/01/14 23:52:06 bluhm Exp $ */
/* /*
* Copyright (c) 2001, 2002, 2003 Ian F. Darwin. All rights reserved. * Copyright (c) 2001, 2002, 2003 Ian F. Darwin. All rights reserved.
@ -218,12 +218,16 @@ fmt_scaled(long long number, char *result)
unsigned int i; unsigned int i;
unit_type unit = NONE; unit_type unit = NONE;
/* Not every negative long long has a positive representation. */
if (number == LLONG_MIN) {
errno = ERANGE;
return -1;
}
abval = llabs(number); abval = llabs(number);
/* Not every negative long long has a positive representation.
* Also check for numbers that are just too darned big to format
*/
if (abval < 0 || abval / 1024 >= scale_factors[SCALE_LENGTH-1]) {
/* Also check for numbers that are just too darned big to format. */
if (abval / 1024 >= scale_factors[SCALE_LENGTH-1]) {
errno = ERANGE; errno = ERANGE;
return -1; return -1;
} }


Loading…
Cancel
Save