aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2016-05-12 18:38:23 +0300
committerArnold D. Robbins <arnold@skeeve.com>2016-05-12 18:38:23 +0300
commitfec6265dfb087ecc8a26a9d8917bcd05bb4b1860 (patch)
tree1951f472d48b71d92fbee21747995c43070a1c91
parent7458e696b5563f64e4da81ae95f88c7f36896ab8 (diff)
downloadegawk-fec6265dfb087ecc8a26a9d8917bcd05bb4b1860.tar.gz
egawk-fec6265dfb087ecc8a26a9d8917bcd05bb4b1860.tar.bz2
egawk-fec6265dfb087ecc8a26a9d8917bcd05bb4b1860.zip
Fix array indexing to disallow numeric string.
-rw-r--r--ChangeLog5
-rw-r--r--str_array.c9
-rw-r--r--test/ChangeLog5
-rw-r--r--test/Makefile.am5
-rw-r--r--test/Makefile.in10
-rw-r--r--test/Maketests5
-rwxr-xr-xtest/arrayind1.awk99
-rw-r--r--test/arrayind1.in2
-rw-r--r--test/arrayind1.ok9
9 files changed, 147 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 5b99d92c..44828d42 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2016-05-12 Arnold Robbins <arnold@skeeve.com>
+
+ * str_array.c (str_lookup): Remove MAYBE_NUM from subscript flags.
+ Bug reported by Andres Legarra <Andres.Legarra@toulouse.inra.fr>.
+
2016-05-12 Eli Zaretskii <eliz@gnu.org>
* nonposix.h: Add prototypes for Posix functions emulated in pc/*
diff --git a/str_array.c b/str_array.c
index db24980a..9514d515 100644
--- a/str_array.c
+++ b/str_array.c
@@ -168,6 +168,15 @@ str_lookup(NODE *symbol, NODE *subs)
subs = dupnode(subs);
}
+ /*
+ * Repeat after me: "Array indices are always strings."
+ * "Array indices are always strings."
+ * "Array indices are always strings."
+ * "Array indices are always strings."
+ * ....
+ */
+ subs->flags &= ~MAYBE_NUM;
+
getbucket(b);
b->ahnext = symbol->buckets[hash1];
symbol->buckets[hash1] = b;
diff --git a/test/ChangeLog b/test/ChangeLog
index 11908b40..e9ea5770 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,8 @@
+2016-05-12 Arnold D. Robbins <arnold@skeeve.com>
+
+ * Makefile.am (arrayind1): New test.
+ * arrayind1.awk, arrayind1.in, arrayind1.ok: New files.
+
2016-04-27 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.am (rscompat): New test.
diff --git a/test/Makefile.am b/test/Makefile.am
index 844c87fb..07637e12 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -52,6 +52,9 @@ EXTRA_DIST = \
argarray.ok \
argtest.awk \
argtest.ok \
+ arrayind1.awk \
+ arrayind1.in \
+ arrayind1.ok \
arrayparm.awk \
arrayparm.ok \
arrayprm2.awk \
@@ -1041,7 +1044,7 @@ CLEANFILES = core core.* fmtspcl.ok
# try to keep these sorted. each letter starts a new line
BASIC_TESTS = \
- addcomma anchgsub argarray arrayparm arrayprm2 arrayprm3 \
+ addcomma anchgsub argarray arrayind1 arrayparm arrayprm2 arrayprm3 \
arrayref arrymem1 arryref2 arryref3 arryref4 arryref5 arynasty \
arynocls aryprm1 aryprm2 aryprm3 aryprm4 aryprm5 aryprm6 aryprm7 \
aryprm8 aryprm9 arysubnm asgext awkpath \
diff --git a/test/Makefile.in b/test/Makefile.in
index 5e55b1b6..cb42bfed 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -309,6 +309,9 @@ EXTRA_DIST = \
argarray.ok \
argtest.awk \
argtest.ok \
+ arrayind1.awk \
+ arrayind1.in \
+ arrayind1.ok \
arrayparm.awk \
arrayparm.ok \
arrayprm2.awk \
@@ -1297,7 +1300,7 @@ CLEANFILES = core core.* fmtspcl.ok
# try to keep these sorted. each letter starts a new line
BASIC_TESTS = \
- addcomma anchgsub argarray arrayparm arrayprm2 arrayprm3 \
+ addcomma anchgsub argarray arrayind1 arrayparm arrayprm2 arrayprm3 \
arrayref arrymem1 arryref2 arryref3 arryref4 arryref5 arynasty \
arynocls aryprm1 aryprm2 aryprm3 aryprm4 aryprm5 aryprm6 aryprm7 \
aryprm8 aryprm9 arysubnm asgext awkpath \
@@ -2598,6 +2601,11 @@ anchgsub:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+arrayind1:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
arrayparm:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/Maketests b/test/Maketests
index 16b1e826..7f9fe1c5 100644
--- a/test/Maketests
+++ b/test/Maketests
@@ -10,6 +10,11 @@ anchgsub:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+arrayind1:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
arrayparm:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/arrayind1.awk b/test/arrayind1.awk
new file mode 100755
index 00000000..29fe80bc
--- /dev/null
+++ b/test/arrayind1.awk
@@ -0,0 +1,99 @@
+#!/usr/local/bin/awk -f
+# this script renums pedigrees with metafounders
+# so that they are added *before*regular animals
+# mf are ascertained because they are not in the 1st column
+# also ordered by generation assuming that all metafounders
+# start at generation 1
+#
+#
+ function maxval (a,b) {
+ max=b
+ if (a>b){max=a}
+ return max
+ }
+BEGIN{
+ pos[0]=0 # actual position in the original data file
+ changed=1
+ posout[0]=0 # position in the new file
+ last=0
+ cum[0]=0 #number of times it acts as parent
+ gen[0]=0
+}
+# read and store pedigree file
+{
+ pos[$1]=NR
+ dam[$1]=$2
+ sire[$1]=$3
+ included[$1]=0
+ gen[$1]=9999
+}
+END{
+ #printf("%10s%10s\n",NR,"animals") > "/dev/stderr"
+ # find out who is a genetic group
+ for (x in sire){
+ if(! (sire[x] in pos)){
+ is_group[sire[x]]=1
+ #printf("%10s%10s\n","sire",sire[x]) > "/dev/stderr"
+ cum[sire[x],"sire"]++
+ }
+ }
+ for (x in dam){
+ if(! (dam[x] in pos)){
+ is_group[dam[x]]=1
+ #printf("%10s%10s\n","dam",dam[x]) > "/dev/stderr"
+ cum[dam[x],"dam"]++
+ }
+ }
+ # compute numbers, but don't write them out
+ #printf("%16s\n","info on mf") > "/dev/stderr"
+ for (x in is_group){
+ nmf++
+ posout[x]=posout[last]+1
+ printf("%16s%16s%16s%16s%16s%16s%16s\n", posout[x],0,0,x,0,0,0)
+ included[x]=1
+ gen[x]=0
+ last=x
+ cumgen[0]++
+ #printf("%10s%16s%10s%16s%10s%10s%10s\n","group",last," included as",posout[x]," as sire, as dam",cum[x,"sire"],cum[x,"dam"]) > "/dev/stderr"
+ }
+ # regular individuals
+ printf("%16s\n","recoding animals") > "/dev/stderr"
+ iter=1
+ #--> comment next line and this element of the associative array becomes null
+ #printf("%s%16s\n","at the beginning it should be empty: ",posout["00000779770060"]) > "/dev/stderr"
+ #-->
+ while (changed){
+ changed=0
+ for (x in pos){
+ if(x!=0 && !included[x]){
+ # change to number of generation
+ # if(included[dam[x]] && included[sire[x]]){
+ if((gen[dam[x]]<iter) && (gen[sire[x]]<iter)){
+ # the new code is actually the order animals are printed
+ posout[x]=posout[last]+1
+ gen[x]=maxval(gen[dam[x]],gen[sire[x]])+1
+ printf("%16s%16s%16s%16s%16s%16s%16s\n", posout[x],posout[dam[x]],posout[sire[x]],x,dam[x],sire[x],gen[x])
+ included[x]=1
+ changed=1
+ last=x
+ nanim++
+ cumgen[gen[x]]++
+ }
+ # }
+ }
+ }
+ iter++
+ #-->
+ printf("%s%16s\n","in the loop: ",posout["00000779770060"]) > "/dev/stderr"
+ #-->
+ #printf("%10s%10s%10s%10s%16s%16s\n","round",iter,"included",posout[last],"last ",last) > "/dev/stderr"
+ }
+ #printf("%10s%10s%10s%10s%10s%10s\n","metafounders:",nmf," animals",nanim," total",posout[last]) > "/dev/stderr"
+ #printf("%16s%16s\n","pseudogenerations:",gen[last]) > "/dev/stderr"
+ for (x in cumgen){
+ #printf("%10s%16s%10s%16s\n","pseudogeneration:",x," including: ",cumgen[x]) > "/dev/stderr"
+ }
+ #--> this is the guilty line
+ printf("%s%16s\n","at the end: ",posout["00000779770060"]) > "/dev/stderr"
+ #-->
+}
diff --git a/test/arrayind1.in b/test/arrayind1.in
new file mode 100644
index 00000000..915d8657
--- /dev/null
+++ b/test/arrayind1.in
@@ -0,0 +1,2 @@
+64000757790003 00000779770060 00000757740011 1979 2 1975 0
+00000779770060 1975su1du1 1975su1du1 1975 1 1975 1975su1du1
diff --git a/test/arrayind1.ok b/test/arrayind1.ok
new file mode 100644
index 00000000..c68346ea
--- /dev/null
+++ b/test/arrayind1.ok
@@ -0,0 +1,9 @@
+recoding animals
+in the loop: 3
+in the loop: 3
+in the loop: 3
+at the end: 3
+ 1 0 0 00000757740011 0 0 0
+ 2 0 0 1975su1du1 0 0 0
+ 3 2 2 00000779770060 1975su1du1 1975su1du1 1
+ 4 3 1 64000757790003 00000779770060 00000757740011 2