bug-gawk
[Top][All Lists]
Advanced

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

[bug-gawk] Bug: invalid evaluation of variable in for statement


From: Wolfgang Laun
Subject: [bug-gawk] Bug: invalid evaluation of variable in for statement
Date: Tue, 2 Feb 2016 20:07:01 +0100

Since searches like  "evaluation and variable and for statement" didn't turn up anything, I may have found a new bug in GNU Awk 4.0.1.

A for statement like the one below doesn't work correctly:
   for( i=0; i < hashsizes[hsidx]; i++ ){

After adding "+0" to the upper limit, it works fine. The code has worked fine for years, using GNU Awk 3.x. Below is the full program to demonstrate the problem.

Regards
Wolfgang

function demo( ) {
    print "demo";
    split("", tosigarr);    # init
    tosigarr[1] = 12;
    tosigarr[2] = 23;
    nsig = 2;
 
    tohsizeparam = "10v,13s";
    gsub( / /, "", tohsizeparam );
    hsnr = split(tohsizeparam, hashsizes, ",");
    for( hsidx=1; hsidx <= hsnr; hsidx++ ){

        gsub(/[^0-9]*$/, "", hashsizes[hsidx]);

        print "hashsizes[" hsidx "]=" hashsizes[hsidx] "!";

        split("", tosighash);    # init
        for( idx=1; idx <= nsig; idx++ ) {
            h = tosigarr[idx] % hashsizes[hsidx];
            tosighash[h] = "" tosighash[h] tosigarr[idx] " ";
        }

        print "hashsizes[" hsidx "]=" (hashsizes[hsidx]+1) "!";

### need to force conversion to number for the loop to work correctly
    for( i=0; i < hashsizes[hsidx]; i++ ){
###    for( i=0; i < hashsizes[hsidx] + 0; i++ ){
        if( i in tosighash ) {
        hstr = hstr "  " tosighash[i] ",\n";
        hused++;
        } else {
        hstr = hstr "  -1,\n";
        }
    }
        print hstr;
    }
}

BEGIN {
    demo();
}


reply via email to

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