bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

apparent array reference bug


From: michael humphrey
Subject: apparent array reference bug
Date: Mon, 25 Aug 2003 19:49:56 -0000

 
this program shows what seems to be an array reference bug in gawk.
 
in the function xxhyr_():
 
1) references to the variable hyr[wn], where wn == 1,
  return the incorrect value of 0.
 
2) the 1st while loop should never be entered, since hyr[3] <= hyr[1].
 
note that the incorrect references occur where it is the second reference to hyr[] on the line.
they do not occur when there is only one reference to hyr[] on a line.
 
below i give the program and the printf output it produces.
 
this is the cygwin port of gawk on a win2k system.
 
$ gawk --version
GNU Awk 3.1.1
Copyright (C) 1989, 1991-2002 Free Software Foundation.
 
 
 
 
 
 
 
 
 
$ cat xhyr-awk
# gawk 3.1.1
function xxhyr_(pn, qn,    un, vn, wn, _wyr)
{
     wn = (pn + qn) / 2;
     un = pn;
     vn = qn;
 
printf "IN xxhyr un= %d, vn= %d, wn= %d\n", un, vn, wn;
printf "INA1 xxhyr hyr[%d] =%d hyr[%d]= %d\n", vn,  hyr[vn], wn, hyr[wn];
 
printf "INA2 xxhyr hyr[%d] =%d hyr[%d]= %d\n", wn, hyr[wn], vn,  hyr[vn];
printf "INA3 xxhyr hyr[%d] =%d hyr[%d]= %d\n", 2, hyr[2], 0,  hyr[0];
printf "INA4 xxhyr hyr[%d]= %d\n", 1,  hyr[1];
     prhyr();
 
     while (hyr[vn] > hyr[wn])
{
printf "INW1 xxhyr hyr[%d] =%d hyr[%d]= %d\n", vn,  hyr[vn], wn, hyr[wn];
       vn--;
 
}
     while (hyr[wn] > hyr[un])
{
printf "INW2 xxhyr hyr[%d] =%d hyr[%d]= %d\n", wn,  hyr[wn], un, hyr[un];
       un++;
}
printf "INX xxhyr un= %d, vn= %d\n", un, vn
     prhyr();
     }
 
function prhyr(       hn)
{
     hn  = 0;
     while (hn < hyrn) {
printf "hyr[%d] = %d\n", hn, hyr[hn]
       hn++;
       }
printf "\n"
    }
 
function ldhyr()
{
 
hyr[0] =14;
hyr[1] =44;
hyr[2] =2;
hyr[3] =32;
     hyrn = 4;
    }
 
BEGIN {
     ldhyr();
 
xxhyr_(0, 3);
 
     exit 0;
     }
 
 
 
 
 
 
 
 
 
$ cat 1xxhyr.out
IN xxhyr un= 0, vn= 3, wn= 1
INA1 xxhyr hyr[3] =32 hyr[1]= 0
INA2 xxhyr hyr[1] =0 hyr[3]= 32
INA3 xxhyr hyr[2] =2 hyr[0]= 14
INA4 xxhyr hyr[1]= 44
hyr[0] = 14
hyr[1] = 44
hyr[2] = 2
hyr[3] = 32
 
INW1 xxhyr hyr[3] =32 hyr[1]= 0
INW1 xxhyr hyr[2] =2 hyr[1]= 0
INW1 xxhyr hyr[1] =44 hyr[1]= 0
INW1 xxhyr hyr[0] =14 hyr[1]= 0
INX xxhyr un= 0, vn= -1
hyr[0] = 14
hyr[1] = 44
hyr[2] = 2
hyr[3] = 32

reply via email to

[Prev in Thread] Current Thread [Next in Thread]