123f24377SWarner Loshecho T.overflow: test some overflow conditions 223f24377SWarner Losh 323f24377SWarner Loshawk=${awk-../a.out} 423f24377SWarner Losh 523f24377SWarner Losh$awk 'BEGIN { 623f24377SWarner Losh for (i = 0; i < 1000; i++) printf("abcdefghijklmnopqsrtuvwxyz") 723f24377SWarner Losh printf("\n") 823f24377SWarner Losh exit 923f24377SWarner Losh}' >foo1 1023f24377SWarner Losh$awk '{print}' foo1 >foo2 1123f24377SWarner Loshcmp -s foo1 foo2 || echo 'BAD: T.overflow record 1' 1223f24377SWarner Losh 1323f24377SWarner Loshecho 'abcdefghijklmnopqsrtuvwxyz' >foo1 1423f24377SWarner Loshecho hello | $awk ' 1523f24377SWarner Losh { for (i = 1; i < 500; i++) s = s "abcdefghijklmnopqsrtuvwxyz " 1623f24377SWarner Losh $0 = s 1723f24377SWarner Losh print $1 1823f24377SWarner Losh }' >foo2 1923f24377SWarner Loshcmp -s foo1 foo2 || echo 'BAD: T.overflow abcdef' 2023f24377SWarner Losh 2123f24377SWarner Losh# default input record 3072, fields 200: 2223f24377SWarner Losh$awk ' 2323f24377SWarner LoshBEGIN { 2423f24377SWarner Losh for (j = 0; j < 2; j++) { 2523f24377SWarner Losh for (i = 0; i < 500; i++) 2623f24377SWarner Losh printf(" 123456789") 2723f24377SWarner Losh printf("\n"); 2823f24377SWarner Losh } 2923f24377SWarner Losh} ' >foo1 3023f24377SWarner Losh$awk '{$1 = " 123456789"; print}' foo1 >foo2 3123f24377SWarner Loshcmp -s foo1 foo2 || echo 'BAD: T.overflow -mr -mf set $1' 3223f24377SWarner Losh 3323f24377SWarner Losh$awk ' 3423f24377SWarner LoshBEGIN { 3523f24377SWarner Losh for (j = 0; j < 2; j++) { 3623f24377SWarner Losh for (i = 0; i < 500; i++) 3723f24377SWarner Losh printf(" 123456789") 3823f24377SWarner Losh printf("\n"); 3923f24377SWarner Losh } 4023f24377SWarner Losh} ' >foo 4123f24377SWarner Losh$awk '{print NF}' foo >foo1 4223f24377SWarner Loshecho '500 4323f24377SWarner Losh500' >foo2 4423f24377SWarner Loshcmp -s foo1 foo2 || echo 'BAD: T.overflow -mr -mf NF' 4523f24377SWarner Losh 4623f24377SWarner Loshrm -f core 4723f24377SWarner Losh# this should not drop core 4823f24377SWarner Losh$awk 'BEGIN { 4923f24377SWarner Losh for (i = 1; i < 1000; i++) s = s "a-z" 5023f24377SWarner Losh if ("x" ~ "[" s "]") 5123f24377SWarner Losh print "ugh" 5223f24377SWarner Losh}' >foo 2>foo 5323f24377SWarner Loshtest -r core && echo 1>&2 "BAD: T.overflow too long char class dropped core" 5423f24377SWarner Losh 5523f24377SWarner Loshecho 4000004 >foo1 5623f24377SWarner Losh$awk ' 5723f24377SWarner LoshBEGIN { 5823f24377SWarner Losh x1 = sprintf("%1000000s\n", "hello") 5923f24377SWarner Losh x2 = sprintf("%-1000000s\n", "world") 6023f24377SWarner Losh x3 = sprintf("%1000000.1000000s\n", "goodbye") 6123f24377SWarner Losh x4 = sprintf("%-1000000.1000000s\n", "goodbye") 6223f24377SWarner Losh print length(x1 x2 x3 x4) 6323f24377SWarner Losh}' >foo2 6423f24377SWarner Loshcmp -s foo1 foo2 || echo 'BAD: T.overflow huge sprintfs' 6523f24377SWarner Losh 6623f24377SWarner Loshecho 0 >foo1 6723f24377SWarner Losh$awk ' 6823f24377SWarner LoshBEGIN { 6923f24377SWarner Losh for (i = 0; i < 100000; i++) 7023f24377SWarner Losh x[i] = i 7123f24377SWarner Losh for (i in x) 7223f24377SWarner Losh delete x[i] 7323f24377SWarner Losh n = 0 7423f24377SWarner Losh for (i in x) 7523f24377SWarner Losh n++ 7623f24377SWarner Losh print n 7723f24377SWarner Losh}' >foo2 7823f24377SWarner Loshcmp -s foo1 foo2 || echo 'BAD: T.overflow big array' 7923f24377SWarner Losh 8023f24377SWarner Loshecho x >foo1 8123f24377SWarner Losh$awk '{print $40000000000000}' <foo1 >foo2 2>foo 8223f24377SWarner Loshgrep "out of range field" foo >/dev/null || echo 1>&2 "BAD: T.overflow \$400000" 8323f24377SWarner Losh 8423f24377SWarner Loshrm -rf /tmp/awktestfoo* 8523f24377SWarner Losh$awk 'BEGIN { for (i=1; i <= 1000; i++) print i >("/tmp/awktestfoo" i) }' 8623f24377SWarner Loshls /tmp/awktestfoo* | grep '1000' >/dev/null || echo 1>&2 "BAD: T.overflow openfiles" 87*f32a6403SWarner Loshrm -rf /tmp/awktestfoo* 88*f32a6403SWarner Loshexit 0 89