It looks like this bug was almost fixed nearly 20 years ago.
Unfortunately that fix only addressed the case where the floating point
value was exactly zero and not the case where the integer conversion
would coerce it to zero.

I've tested locally that this resolves the issue that Jan Stary
reported on misc but haven't done any testing beyond that.

A simple example of the bug is:

$ awk 'BEGIN { printf("%c", 0.1) }' | hexdump -C
$ awk-patched 'BEGIN { printf("%c", 0.1) }' | hexdump -C
00000000  00                                                |.|
00000001
$ gawk 'BEGIN { printf("%c", 0.1) }' | hexdump -C
00000000  00                                                |.|
00000001
$ mawk 'BEGIN { printf("%c", 0.1) }' | hexdump -C
00000000  00                                                |.|
00000001


Index: run.c
===================================================================
RCS file: /cvs/src/usr.bin/awk/run.c,v
retrieving revision 1.34
diff -u -p -u -p -r1.34 run.c
--- run.c       29 Sep 2013 15:42:25 -0000      1.34
+++ run.c       30 Nov 2014 23:38:00 -0000
@@ -921,7 +921,7 @@ int format(char **pbuf, int *pbufsize, c
                        break;
                case 'c':
                        if (isnum(x)) {
-                               if (getfval(x))
+                               if ((int)getfval(x))
                                        snprintf(p, buf + bufsize - p,
fmt, (int) getfval(x));
                                else {
                                        *p++ = '\0'; /* explicit null byte */

Reply via email to