1e6d6c189SCody Peter Mello#!/bin/bash 2e6d6c189SCody Peter Mello 3e6d6c189SCody Peter Melloif [[ -z "$AWK" || -z "$WORKDIR" ]]; then 4e6d6c189SCody Peter Mello printf '$AWK and $WORKDIR must be set\n' >&2 5e6d6c189SCody Peter Mello exit 1 6e6d6c189SCody Peter Mellofi 7e6d6c189SCody Peter Mello 8e6d6c189SCody Peter MelloTEMP0=$WORKDIR/test.temp.0 9e6d6c189SCody Peter MelloTEMP1=$WORKDIR/test.temp.1 10e6d6c189SCody Peter MelloTEMP2=$WORKDIR/test.temp.2 11e6d6c189SCody Peter Mello 12e6d6c189SCody Peter MelloRESULT=0 13e6d6c189SCody Peter Mello 14e6d6c189SCody Peter Mellofail() { 15e6d6c189SCody Peter Mello echo "$1" >&2 16e6d6c189SCody Peter Mello RESULT=1 17e6d6c189SCody Peter Mello} 18e6d6c189SCody Peter Mello 19e6d6c189SCody Peter Melloecho T.overflow: test some overflow conditions 20e6d6c189SCody Peter Mello 21e6d6c189SCody Peter Mello$AWK 'BEGIN { 22e6d6c189SCody Peter Mello for (i = 0; i < 1000; i++) printf("abcdefghijklmnopqsrtuvwxyz") 23e6d6c189SCody Peter Mello printf("\n") 24e6d6c189SCody Peter Mello exit 25e6d6c189SCody Peter Mello}' > $TEMP1 26e6d6c189SCody Peter Mello$AWK '{print}' $TEMP1 > $TEMP2 27e6d6c189SCody Peter Mellocmp -s $TEMP1 $TEMP2 || fail 'BAD: T.overflow record 1' 28e6d6c189SCody Peter Mello 29e6d6c189SCody Peter Melloecho 'abcdefghijklmnopqsrtuvwxyz' > $TEMP1 30e6d6c189SCody Peter Melloecho hello | $AWK ' 31e6d6c189SCody Peter Mello { for (i = 1; i < 500; i++) s = s "abcdefghijklmnopqsrtuvwxyz " 32e6d6c189SCody Peter Mello $0 = s 33e6d6c189SCody Peter Mello print $1 34e6d6c189SCody Peter Mello }' > $TEMP2 35e6d6c189SCody Peter Mellocmp -s $TEMP1 $TEMP2 || fail 'BAD: T.overflow abcdef' 36e6d6c189SCody Peter Mello 37e6d6c189SCody Peter Mello# default input record 3072, fields 200: 38e6d6c189SCody Peter Mello$AWK ' 39e6d6c189SCody Peter MelloBEGIN { 40e6d6c189SCody Peter Mello for (j = 0; j < 2; j++) { 41e6d6c189SCody Peter Mello for (i = 0; i < 500; i++) 42e6d6c189SCody Peter Mello printf(" 123456789") 43e6d6c189SCody Peter Mello printf("\n"); 44e6d6c189SCody Peter Mello } 45e6d6c189SCody Peter Mello} ' > $TEMP1 46e6d6c189SCody Peter Mello$AWK '{$1 = " 123456789"; print}' $TEMP1 > $TEMP2 47e6d6c189SCody Peter Mellocmp -s $TEMP1 $TEMP2 || fail 'BAD: T.overflow -mr -mf set $1' 48e6d6c189SCody Peter Mello 49e6d6c189SCody Peter Mello$AWK ' 50e6d6c189SCody Peter MelloBEGIN { 51e6d6c189SCody Peter Mello for (j = 0; j < 2; j++) { 52e6d6c189SCody Peter Mello for (i = 0; i < 500; i++) 53e6d6c189SCody Peter Mello printf(" 123456789") 54e6d6c189SCody Peter Mello printf("\n"); 55e6d6c189SCody Peter Mello } 56e6d6c189SCody Peter Mello} ' > $TEMP0 57e6d6c189SCody Peter Mello$AWK '{print NF}' $TEMP0 > $TEMP1 58e6d6c189SCody Peter Melloecho '500 59e6d6c189SCody Peter Mello500' > $TEMP2 60e6d6c189SCody Peter Mellocmp -s $TEMP1 $TEMP2 || fail 'BAD: T.overflow -mr -mf NF' 61e6d6c189SCody Peter Mello 62e6d6c189SCody Peter Mellorm -f core 63e6d6c189SCody Peter Mello# this should not drop core 64e6d6c189SCody Peter Mello$AWK 'BEGIN { 65e6d6c189SCody Peter Mello for (i = 1; i < 1000; i++) s = s "a-z" 66e6d6c189SCody Peter Mello if ("x" ~ "[" s "]") 67e6d6c189SCody Peter Mello print "ugh" 68e6d6c189SCody Peter Mello}' > $TEMP0 2> $TEMP0 69e6d6c189SCody Peter Mello[[ $? -eq 139 ]] && fail "BAD: T.overflow too long char class dropped core" 70e6d6c189SCody Peter Mello 71e6d6c189SCody Peter Melloecho 4000004 > $TEMP1 72e6d6c189SCody Peter Mello$AWK ' 73e6d6c189SCody Peter MelloBEGIN { 74e6d6c189SCody Peter Mello x1 = sprintf("%1000000s\n", "hello") 75e6d6c189SCody Peter Mello x2 = sprintf("%-1000000s\n", "world") 76e6d6c189SCody Peter Mello x3 = sprintf("%1000000.1000000s\n", "goodbye") 77e6d6c189SCody Peter Mello x4 = sprintf("%-1000000.1000000s\n", "goodbye") 78e6d6c189SCody Peter Mello print length(x1 x2 x3 x4) 79e6d6c189SCody Peter Mello}' > $TEMP2 80e6d6c189SCody Peter Mellocmp -s $TEMP1 $TEMP2 || fail 'BAD: T.overflow huge sprintfs' 81e6d6c189SCody Peter Mello 82e6d6c189SCody Peter Melloecho 0 > $TEMP1 83e6d6c189SCody Peter Mello$AWK ' 84e6d6c189SCody Peter MelloBEGIN { 85e6d6c189SCody Peter Mello for (i = 0; i < 100000; i++) 86e6d6c189SCody Peter Mello x[i] = i 87e6d6c189SCody Peter Mello for (i in x) 88e6d6c189SCody Peter Mello delete x[i] 89e6d6c189SCody Peter Mello n = 0 90e6d6c189SCody Peter Mello for (i in x) 91e6d6c189SCody Peter Mello n++ 92e6d6c189SCody Peter Mello print n 93e6d6c189SCody Peter Mello}' > $TEMP2 94e6d6c189SCody Peter Mellocmp -s $TEMP1 $TEMP2 || fail 'BAD: T.overflow big array' 95e6d6c189SCody Peter Mello 96*3ee4fc2aSCody Peter Melloecho x > $TEMP1 97*3ee4fc2aSCody Peter Mello$AWK '{print $40000000000000}' < $TEMP1 > $TEMP2 2> $TEMP0 98*3ee4fc2aSCody Peter Mellogrep "out of range field" $TEMP0 >/dev/null || fail "BAD: T.overflow \$400000" 99*3ee4fc2aSCody Peter Mello 100*3ee4fc2aSCody Peter Mellorm -rf /tmp/awktestfoo* 101*3ee4fc2aSCody Peter Mello$AWK 'BEGIN { for (i=1; i <= 1000; i++) print i >("/tmp/awktestfoo" i) }' 102*3ee4fc2aSCody Peter Mellols /tmp/awktestfoo* | grep '1000' >/dev/null || fail "BAD: T.overflow openfiles" 103*3ee4fc2aSCody Peter Mello 104e6d6c189SCody Peter Melloexit $RESULT 105