[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: awk bug?  (+ small question about nc and shell size)
From:       Denys Vlasenko <vda.linux () googlemail ! com>
Date:       2009-01-25 0:59:21
Message-ID: 200901250159.21921.vda.linux () googlemail ! com
[Download RAW message or body]

On Saturday 24 January 2009 21:56, Peter Renzland wrote:
> [Busybox v1.12.3, Netfilter v1.3.7, Tomato 1.23, Linux 2.4.20,  
> embedded in a WRT54GL router]
> 
> === awk ===
> 
> I wonder whether the following awk bug is more widespread than my my  
> particular implementation:
> 
> The following program:
> 
> awk '
>    BEGIN {
> 	print "NF:" NF ":"
> 	print "$0:" $0 ":"
> 	print "$1:" $1 ":"
> 	print "$2:" $2 ":"
>    }
> '
> 
> prints:
> 
> NF:1:
> $0:0:
> $1:0:
> $2::
> 
> instead of:
> 
> NF:0:
> $0::
> $1::
> $2::

Try attached patch.


> === nc and shell size ===
> 
> I wonder if adding "-l" to the capability of nc would increase the  
> executable size by much.

?!! nc already has -l option supported.

> Similarly with adding job control to the shell.

Same comment applies here.
--
vda

["a.patch" (text/x-diff)]

diff -d -urpN busybox.9/editors/awk.c busybox.a/editors/awk.c
--- busybox.9/editors/awk.c	2008-12-10 12:17:49.000000000 +0100
+++ busybox.a/editors/awk.c	2009-01-25 01:43:41.000000000 +0100
@@ -366,25 +366,22 @@ static const uint32_t tokeninfo[] = {
 enum {
 	CONVFMT,    OFMT,       FS,         OFS,
 	ORS,        RS,         RT,         FILENAME,
-	SUBSEP,     ARGIND,     ARGC,       ARGV,
-	ERRNO,      FNR,
-	NR,         NF,         IGNORECASE,
-	ENVIRON,    F0,         NUM_INTERNAL_VARS
+	SUBSEP,     F0,         ARGIND,     ARGC,
+	ARGV,       ERRNO,      FNR,        NR,
+	NF,         IGNORECASE,	ENVIRON,    NUM_INTERNAL_VARS
 };
 
 static const char vNames[] ALIGN1 =
 	"CONVFMT\0" "OFMT\0"    "FS\0*"     "OFS\0"
 	"ORS\0"     "RS\0*"     "RT\0"      "FILENAME\0"
-	"SUBSEP\0"  "ARGIND\0"  "ARGC\0"    "ARGV\0"
-	"ERRNO\0"   "FNR\0"
-	"NR\0"      "NF\0*"     "IGNORECASE\0*"
-	"ENVIRON\0" "$\0*"      "\0";
+	"SUBSEP\0"  "$\0*"      "ARGIND\0"  "ARGC\0"
+	"ARGV\0"    "ERRNO\0"   "FNR\0"     "NR\0"
+	"NF\0*"     "IGNORECASE\0*" "ENVIRON\0" "\0";
 
 static const char vValues[] ALIGN1 =
 	"%.6g\0"    "%.6g\0"    " \0"       " \0"
 	"\n\0"      "\n\0"      "\0"        "\0"
-	"\034\0"
-	"\377";
+	"\034\0"    "\0"        "\377";
 
 /* hash size may grow to these values */
 #define FIRST_PRIME 61
@@ -1856,7 +1853,6 @@ static int fmt_num(char *b, int size, co
 	return r;
 }
 
-
 /* formatted output into an allocated buffer, return ptr to buffer */
 static char *awk_printf(node *n)
 {
@@ -2866,18 +2862,18 @@ int awk_main(int argc, char **argv)
 			parse_program(s + 1);
 			free(s);
 		} while (list_f);
+		argc++;
 	} else { // no -f: take program from 1st parameter
 		if (!argc)
 			bb_show_usage();
 		g_progname = "cmd. line";
 		parse_program(*argv++);
-		argc--;
 	}
 	if (opt & 0x8) // -W
 		bb_error_msg("warning: unrecognized option '-W %s' ignored", opt_W);
 
 	/* fill in ARGV array */
-	setvar_i(intvar[ARGC], argc + 1);
+	setvar_i(intvar[ARGC], argc);
 	setari_u(intvar[ARGV], 0, "awk");
 	i = 0;
 	while (*argv)
diff -d -urpN busybox.9/testsuite/awk.tests busybox.a/testsuite/awk.tests
--- busybox.9/testsuite/awk.tests	2008-12-10 12:17:47.000000000 +0100
+++ busybox.a/testsuite/awk.tests	2009-01-25 01:57:28.000000000 +0100
@@ -29,4 +29,11 @@ testing "awk 'gcc build bug'" \
 	"" ""
 rm -rf awk_t1_*
 
+Q='":"'
+
+testing "awk NF in BEGIN" \
+	"awk 'BEGIN { print ${Q} NF ${Q} \$0 ${Q} \$1 ${Q} \$2 ${Q} }'" \
+	":0::::\n" \
+	"" ""
+
 exit $FAILCOUNT


_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic