[git commit] awk: fix length(array)

Denys Vlasenko vda.linux at googlemail.com
Sat Oct 12 02:51:54 UTC 2013


commit: http://git.busybox.net/busybox/commit/?id=7985bc109e0d738644094f391d08d9848a2f2b50
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

function                                             old     new   delta
evaluate                                            3526    3548     +22

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 editors/awk.c       |   10 +++++++++-
 testsuite/awk.tests |    5 +++++
 2 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/editors/awk.c b/editors/awk.c
index 77784df..8848d94 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -2784,8 +2784,16 @@ static var *evaluate(node *op, var *res)
 				break;
 
 			case F_le:
-				if (!op1)
+				debug_printf_eval("length: L.s:'%s'\n", L.s);
+				if (!op1) {
 					L.s = getvar_s(intvar[F0]);
+					debug_printf_eval("length: L.s='%s'\n", L.s);
+				}
+				else if (L.v->type & VF_ARRAY) {
+					R_d = L.v->x.array->nel;
+					debug_printf_eval("length: array_len:%d\n", L.v->x.array->nel);
+					break;
+				}
 				R_d = strlen(L.s);
 				break;
 
diff --git a/testsuite/awk.tests b/testsuite/awk.tests
index 6af6072..a023024 100755
--- a/testsuite/awk.tests
+++ b/testsuite/awk.tests
@@ -274,6 +274,11 @@ testing "awk large integer" \
 	"2147483647 2147483647 0 2147483648 2147483648 0\n" \
 	"" ""
 
+testing "awk length(array)" \
+	"awk 'BEGIN{ A[1]=2; A["qwe"]="asd"; print length(A)}'" \
+	"2\n" \
+	"" ""
+
 # testing "description" "command" "result" "infile" "stdin"
 
 exit $FAILCOUNT


More information about the busybox-cvs mailing list