bin/125449: /usr/bin/awk fails mawk's FPE test

Pedro F. Giffuni pfgshield-freebsd at yahoo.com
Wed Jul 9 20:10:02 UTC 2008


>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 at 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:


More information about the freebsd-bugs mailing list