diff options
author | Philip Guenther <guenther@cvs.openbsd.org> | 2020-06-08 03:22:24 +0000 |
---|---|---|
committer | Philip Guenther <guenther@cvs.openbsd.org> | 2020-06-08 03:22:24 +0000 |
commit | 8f362563d8e3edaf51e661f18685f44716781993 (patch) | |
tree | a7637b4822e440d61abeca41fad37a83215ab478 /usr.bin/awk/run.c | |
parent | c8e65cadafc42120f23008a6a1237d9831b25f50 (diff) |
The errcheck() function treats an errno of ERANGE or EDOM as something
to report, so make sure errno is set to zero before invoking a
function to check so that a previous such errno value won't result
in a false positive. This could happen simply due to input line fields
that looked enough like floating-point input to trigger ERANGE.
Problem noted by Jordan Geoghegan (jordan (at) geoghegan.ca), with
clue from Ze' Loff (zeloff (at) zeloff.org)
ok millert@
Diffstat (limited to 'usr.bin/awk/run.c')
-rw-r--r-- | usr.bin/awk/run.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/usr.bin/awk/run.c b/usr.bin/awk/run.c index 20e169cdd40..bb0038555e9 100644 --- a/usr.bin/awk/run.c +++ b/usr.bin/awk/run.c @@ -1,4 +1,4 @@ -/* $OpenBSD: run.c,v 1.44 2019/08/13 10:45:56 fcambus Exp $ */ +/* $OpenBSD: run.c,v 1.45 2020/06/08 03:22:23 guenther Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -26,6 +26,7 @@ THIS SOFTWARE. #define DEBUG #include <stdio.h> #include <ctype.h> +#include <errno.h> #include <setjmp.h> #include <limits.h> #include <math.h> @@ -1041,8 +1042,10 @@ Cell *arith(Node **a, int n) /* a[0] + a[1], etc. also -a[0] */ case POWER: if (j >= 0 && modf(j, &v) == 0.0) /* pos integer exponent */ i = ipow(i, (int) j); - else + else { + errno = 0; i = errcheck(pow(i, j), "pow"); + } break; default: /* can't happen */ FATAL("illegal arithmetic operator %d", n); @@ -1135,8 +1138,10 @@ Cell *assign(Node **a, int n) /* a[0] = a[1], a[0] += a[1], etc. */ case POWEQ: if (yf >= 0 && modf(yf, &v) == 0.0) /* pos integer exponent */ xf = ipow(xf, (int) yf); - else + else { + errno = 0; xf = errcheck(pow(xf, yf), "pow"); + } break; default: FATAL("illegal assignment operator %d", n); @@ -1499,12 +1504,15 @@ Cell *bltin(Node **a, int n) /* builtin functions. a[0] is type, a[1] is arg lis u = strlen(getsval(x)); break; case FLOG: + errno = 0; u = errcheck(log(getfval(x)), "log"); break; case FINT: modf(getfval(x), &u); break; case FEXP: + errno = 0; u = errcheck(exp(getfval(x)), "exp"); break; case FSQRT: + errno = 0; u = errcheck(sqrt(getfval(x)), "sqrt"); break; case FSIN: u = sin(getfval(x)); break; |