Date: Wed, 9 Jul 2008 20:09:36 GMT From: "Pedro F. Giffuni" <pfgshield-freebsd@yahoo.com> To: freebsd-gnats-submit@FreeBSD.org Subject: bin/125449: /usr/bin/awk fails mawk's FPE test Message-ID: <200807092009.m69K9aHm063903@www.freebsd.org> Resent-Message-ID: <200807092010.m69KA1kY068710@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 125449 >Category: bin >Synopsis: /usr/bin/awk fails mawk's FPE test >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Wed Jul 09 20:10:01 UTC 2008 >Closed-Date: >Last-Modified: >Originator: Pedro F. Giffuni >Release: FreeBSD-6.3-Release >Organization: >Environment: FreeBSD kakumen.cable.net.co 6.3-RELEASE FreeBSD 6.3-RELEASE #10: Sat Jan 19 01:13:55 COT 2008 root@kakumen.cable.net.co:/usr/src/sys/amd64/compile/SMP amd64 >Description: The historic behavior in 386BSD and FreeBSD 2.x was to trap all Floating Point Exceptions. Now we are supporting IEEE754 properly so we don't trap FPE's anymore but for some unknown reason printing the result of a division from zero in the one-true-awk returns an inconsistent code so we are failing mawk's fpe_test. Restoring the historic behavior for awk (nawk used to pass this test in FreeBSD 2.x) gives a consistent result: it is also arguable that it's better to know when you are doing stupid things in your script instead of trying to find out the inconsistency later. >How-To-Repeat: Switching to nawk the fpe_test included in lang/mawk we get: kakumen# ./fpe_test testing division by zero nawk BEGIN{ print 4/0 } nawk: division by zero source line number 1 testing overflow nawk BEGIN { x = 100 do { y = x ; x *= 1000 } while ( y != x ) print "loop terminated" } loop terminated testing domain error nawk BEGIN{ print log(-8) } nan ============================== return1 = 2 return2 = 0 return3 = 0 results are not consistent return values should all be 0 if ignoring FPEs (e.g. with IEEE754) or all 2 if trapping FPEs compilation defines for floating point are incorrect >Fix: --- main.c.orig 2007-05-01 16:05:28.000000000 -0500 +++ main.c 2008-07-08 15:33:37.000000000 -0500 @@ -34,6 +34,8 @@ #include "awk.h" #include "ytab.h" +#include <fenv.h> + extern char **environ; extern int nfields; @@ -67,6 +69,7 @@ exit(1); } signal(SIGFPE, fpecatch); + feenableexcept(FE_DIVBYZERO|FE_INEXACT|FE_OVERFLOW); yyin = NULL; symtab = makesymtab(NSYMTAB/NSYMTAB); while (argc > 1 && argv[1][0] == '-' && argv[1][1] != '\0') { >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200807092009.m69K9aHm063903>