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

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

Re: SIGSEGV in gawk 3.1.3


From: Aharon Robbins
Subject: Re: SIGSEGV in gawk 3.1.3
Date: Wed, 3 Mar 2004 17:15:49 +0200

Greetings. Re: this:

> Date: Tue, 02 Mar 2004 13:41:51 -0500
> From: Rick Ace <address@hidden>
> Subject: SIGSEGV in gawk 3.1.3
> To: address@hidden
>
> Hi folks,
>
> I  am using gawk to reformat and sort (via >> redirection) the records of
> a 22 megabyte ASCII data file.  Somewhere between the 10,000,000th
> and 11,000,000th byte, gawk 3.1.3 gets a SIGSEGV at line 610 of io.c.
>
>     mode = (rp->mode[1] == 'b') ? "ab" : "a";
>
> When run under gdb, the "mode" field of the struct pointed to by rp is
> null (0x0) at the time of the segmentation fault.  Not being familiar with
> the gawk code, it wasn't clear exactly what needs to be fixed.
>
> My one stab at paring down the input failed.  I split the file near the
> 10,000,000th byte to create two files, both of which passed through
> without a problem.
>
> So if you could please advise what to do next, I'd appreciate it.  You
> are welcome to have a copy of the script and the large input file
> (about 6 megabytes of tar.gz) - just let me know where to send it.
>
> Thanks
>
> Rick Ace
> address@hidden

Thanks for the script and data.  It was indeed a bug.  Here's the fix.

Enjoy,

Arnold
-----------------------------------------------------------
Wed Mar  3 17:10:16 2004  Arnold D. Robbins  <address@hidden>

        * io.c (close_one): Don't close stdout or stderr; can happen if
        /dev/stdout or /dev/stderr are used in redirections and all the
        open files get used.

--- ../gawk-3.1.3/io.c  2003-07-04 20:50:58.000000000 +0300
+++ io.c        2004-03-03 17:10:10.000000000 +0200
@@ -769,8 +783,12 @@
        for (rp = red_head; rp != NULL; rp = rp->next)
                rplast = rp;
        /* now work back up through the list */
-       for (rp = rplast; rp != NULL; rp = rp->prev)
-               if (rp->fp != NULL && (rp->flag & RED_FILE) != 0) {
+       for (rp = rplast; rp != NULL; rp = rp->prev) {
+               /* don't close standard files! */
+               if (rp->fp == NULL || rp->fp == stdout || rp->fp == stderr)
+                       continue;
+
+               if ((rp->flag & RED_FILE) != 0) {
                        rp->flag |= RED_USED;
                        errno = 0;
                        if (/* do_lint && */ fclose(rp->fp) != 0)
@@ -779,6 +797,7 @@
                        rp->fp = NULL;
                        break;
                }
+       }
        if (rp == NULL)
                /* surely this is the only reason ??? */
                fatal(_("too many pipes or input files open")); 




reply via email to

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