Hello,

Updated version of awk (Dec 20, 2012) [1] has a simplification
in fpecatch() function. I tried to test this to compare the
error output. 

Old version:
$ /usr/bin/awk '{}'
*** receive SIGFPE via kill(1) ***
floating point exception
 source line number 1

New version:
$ ./awk '{}'
*** receive SIGFPE via kill(1) ***
awk: floating point exception 8
 source line number 1

And with debugging flag set, the core dump still happens as expected...

Old version:
$ awk -d9 '{}'
awk version 20110810
program = |{}|
setsymtab set 0x7ac4f180: n=0 s="0" f=0 t=17
*** SNIP ***
lex token 123
lex token 59
lex token 125
errorflag=0
RS=<
>, FS=< >, ARGC=1, FILENAME=
argno=1, file=||
*** receive SIGFPE via kill(1) ***
floating point exception
 source line number 1
Abort trap (core dumped)

New version:
$ ./awk -d9 '{}'
awk version 20110810
program = |{}|
setsymtab set 0x80e58840: n=0 s="0" f=0 t=17
*** SNIP ***
lex token 123
lex token 59
lex token 125
errorflag=0
RS=<
>, FS=< >, ARGC=1, FILENAME=
argno=1, file=||
*** receive SIGFPE via kill(1) ***
awk: floating point exception 8
 source line number 1
Abort trap (core dumped)

No significant difference for this trivial test.
All I notice is the error now starts with command name.

- Michael


[1] http://www.cs.princeton.edu/~bwk/btl.mirror/awk.tar.gz

Index: lib.c
===================================================================
RCS file: /cvs/src/usr.bin/awk/lib.c,v
retrieving revision 1.22
diff -u -p -u -r1.22 lib.c
--- lib.c       12 Apr 2016 19:43:38 -0000      1.22
+++ lib.c       5 Sep 2017 04:59:58 -0000
@@ -529,39 +529,9 @@ void SYNTAX(const char *fmt, ...)
        eprint();
 }
 
-void fpecatch(int sig)
+void fpecatch(int n)
 {
-       extern Node *curnode;
-       char buf[1024];
-
-       snprintf(buf, sizeof buf, "floating point exception\n");
-       write(STDERR_FILENO, buf, strlen(buf));
-
-       if (compile_time != 2 && NR && *NR > 0) {
-               snprintf(buf, sizeof buf, " input record number %d", (int) 
(*FNR));
-               write(STDERR_FILENO, buf, strlen(buf));
-
-               if (strcmp(*FILENAME, "-") != 0) {
-                       snprintf(buf, sizeof buf, ", file %s", *FILENAME);
-                       write(STDERR_FILENO, buf, strlen(buf));
-               }
-               write(STDERR_FILENO, "\n", 1);
-       }
-       if (compile_time != 2 && curnode) {
-               snprintf(buf, sizeof buf, " source line number %d", 
curnode->lineno);
-               write(STDERR_FILENO, buf, strlen(buf));
-       } else if (compile_time != 2 && lineno) {
-               snprintf(buf, sizeof buf, " source line number %d", lineno);
-               write(STDERR_FILENO, buf, strlen(buf));
-       }
-       if (compile_time == 1 && cursource() != NULL) {
-               snprintf(buf, sizeof buf, " source file %s", cursource());
-               write(STDERR_FILENO, buf, strlen(buf));
-       }
-       write(STDERR_FILENO, "\n", 1);
-       if (dbg > 1)            /* core dump if serious debugging on */
-               abort();
-       _exit(1);
+       FATAL("floating point exception %d", n);
 }
 
 extern int bracecnt, brackcnt, parencnt;

Reply via email to