Possiple Bug in GNU awk, please verify this 
Author Message
 Possiple Bug in GNU awk, please verify this

Just in case someone else wants to chase the bug:

BEGIN { f=ARGV[1] }
END {
  while ( (getline < f) > 0 ) print 1, $0 ; close(f);
  while ( (getline < f) > 0 ) print 2, $0 ; close(f);
  while ( (getline < f) > 0 ) print 3, $0 ; close(f);

Quote:
}

A necessary condition of the appearance of the bug is the END
pattern.

This script should print the contents of the file three times.
But GNU AWK prints it only once. I did tests with versions 3.0.3,
3.0.44 and 3.1.80.



Tue, 06 Nov 2001 03:00:00 GMT  
 Possiple Bug in GNU awk, please verify this

Quote:

> Just in case someone else wants to chase the bug:

> BEGIN { f=ARGV[1] }
> END {
>   while ( (getline < f) > 0 ) print 1, $0 ; close(f);
>   while ( (getline < f) > 0 ) print 2, $0 ; close(f);
>   while ( (getline < f) > 0 ) print 3, $0 ; close(f);
> }

> A necessary condition of the appearance of the bug is the END
> pattern.

> This script should print the contents of the file three times.
> But GNU AWK prints it only once. I did tests with versions 3.0.3,
> 3.0.44 and 3.1.80.

Works correctly on 3.0.0

--
Dan Mercer

Opinions expressed herein are my own and may not represent those of my employer.



Tue, 06 Nov 2001 03:00:00 GMT  
 Possiple Bug in GNU awk, please verify this


Quote:
>Just in case someone else wants to chase the bug:

>BEGIN { f=ARGV[1] }
>END {
>  while ( (getline < f) > 0 ) print 1, $0 ; close(f);
>  while ( (getline < f) > 0 ) print 2, $0 ; close(f);
>  while ( (getline < f) > 0 ) print 3, $0 ; close(f);
>}

>A necessary condition of the appearance of the bug is the END
>pattern.

>This script should print the contents of the file three times.
>But GNU AWK prints it only once. I did tests with versions 3.0.3,
>3.0.44 and 3.1.80.

Confirmed in gawk 3.0.3 (DJGPP/DOS port).  I put the program into a
file, "gawkbug.awk", and fed it to itself with this commandline and
results:

D:\TEMP>gawk -f gawkbug.awk gawkbug.awk
1 BEGIN { f=ARGV[1] }
1 END {
1     while ( (getline < f) > 0 ) print 1, $0 ; close(f);
1     while ( (getline < f) > 0 ) print 2, $0 ; close(f);
1     while ( (getline < f) > 0 ) print 3, $0 ; close(f);
1 }

These are the first few lines returned for the --version parameter by
the DJGPP/DOS port:

D:\TEMP>gawk --version
GNU Awk 3.0.3
Copyright (C) 1989, 1991-1997 Free Software Foundation.

I also get a different failure from this version of the program,
WITHOUT the END pattern:

BEGIN { f=ARGV[1] }
{
    while ( (getline < f) > 0 ) print 1, $0 ; close(f);
    while ( (getline < f) > 0 ) print 2, $0 ; close(f);
    while ( (getline < f) > 0 ) print 3, $0 ; close(f);

Quote:
}

This program (I called it gawkbug3.awk) gives this result when fed to
itself:

D:\TEMP>gawk -f gawkbug3.awk gawkbug3.awk
1 BEGIN { f=ARGV[1] }
1 {
1     while ( (getline < f) > 0 ) print 1, $0 ; close(f);
1     while ( (getline < f) > 0 ) print 2, $0 ; close(f);
1     while ( (getline < f) > 0 ) print 3, $0 ; close(f);
1 }
gawk: gawkbug3.awk:5: (FILENAME=gawkbug3.awk FNR=6) fatal: error
reading input file `gawkbug3.awk': Bad file descriptor (EBADF)

Now, I think I may understand this one:  Since gawk needs to be able
to read the supplied file (ARGV[1]) itself, and the code here reads it
all and then closes the file, the error occurs when gawk tries to read
the input after the (unconditional) action, right?

But that doesn't explain why the file isn't printed three times first,
by the unconditional action.

Has anyone else manage to test this one with 3.0.3 or better?  Or have
a better explanation of why it should not work the way it seems it
should?

----------------------------------------------------




Sun, 11 Nov 2001 03:00:00 GMT  
 Possiple Bug in GNU awk, please verify this

Quote:
> These are the first few lines returned for the --version parameter by
> the DJGPP/DOS port:

> D:\TEMP>gawk --version
> GNU Awk 3.0.3
> Copyright (C) 1989, 1991-1997 Free Software Foundation.

Michael Mauch reported today that he applied Arnold Robbins'
patch (which I posted here yesterday) successfully to GAWK 3.0.3:

| Thank you for forwarding the patch, now I finally got the same results
| as you did (without the patch only the first loop, with it all three).

Quote:
> I also get a different failure from this version of the program,
> WITHOUT the END pattern:
..
> D:\TEMP>gawk -f gawkbug3.awk gawkbug3.awk
> 1 BEGIN { f=ARGV[1] }
> 1 {
> 1     while ( (getline < f) > 0 ) print 1, $0 ; close(f);
> 1     while ( (getline < f) > 0 ) print 2, $0 ; close(f);
> 1     while ( (getline < f) > 0 ) print 3, $0 ; close(f);
> 1 }
> gawk: gawkbug3.awk:5: (FILENAME=gawkbug3.awk FNR=6) fatal: error
> reading input file `gawkbug3.awk': Bad file descriptor (EBADF)

Confirmed for GAWK 3.0.3 and 3.0.44 on Linux 2.2.5.
Try applying Arnold Robbins' patch. GAWK wont crash, but
when it gives the correct result, it does so *three times*.
Which is not correct anymore.

Quote:
> Has anyone else manage to test this one with 3.0.3 or better?  Or have
> a better explanation of why it should not work the way it seems it
> should?

No, I dont know what happens here, and I dont have time to track
it down. If you can reproduce the trouble I had with your script
after applying the patch, you should post this problem to
gun.utils.bug with a copy to Arnold Robbins.

+---------------------------------------------------------------------+
| Juergen Kahrs,       STN Atlas Elektronik GmbH,   D-28305 Bremen    |
| Simulation Division  Sebaldsbruecker Heerstr. 235 +49/421/457-2819  |
+----------- http://home.t-online.de/home/Juergen.Kahrs/ -------------+



Sun, 11 Nov 2001 03:00:00 GMT  
 Possiple Bug in GNU awk, please verify this

Quote:

> Try applying Arnold Robbins' patch. GAWK wont crash, but
> when it gives the correct result, it does so *three times*.
> Which is not correct anymore.

Sorry, my mistake. The patched GAWK 3.0.3 behaves perfectly.
It is me who misunderstood your script. One shouldnt try to
do multiple things at one time. Please dont bother Arnold
Robbins with this problem.

+---------------------------------------------------------------------+
| Juergen Kahrs,       STN Atlas Elektronik GmbH,   D-28305 Bremen    |
| Simulation Division  Sebaldsbruecker Heerstr. 235 +49/421/457-2819  |
+----------- http://home.t-online.de/home/Juergen.Kahrs/ -------------+



Sun, 11 Nov 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Arrays in awk/awk help please!

2. /etc/passwd file verify parse script, PLEASE!

3. Please verify DM will generate SQL scripts

4. Please verify that you can access this Rexx file area

5. Verify your nominations here, please

6. GNU AWK networking booklet available soon

7. GNU awk 3.0.6 upload for DOS,Win32,OS/2

8. GNU Awk (gawk) 3.0.5 now available

9. Cross compiling GNU awk 3.0.4

10. GNU awk maintenance

11. GNU awk syntax on DOS

12. Alert: GNU Awk 3.0.4 for Win32 possibly broken

 

 
Powered by phpBB® Forum Software