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

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

Re: gawk long lines bug?


From: Aharon Robbins
Subject: Re: gawk long lines bug?
Date: Sun, 17 Feb 2002 15:09:18 +0200

Greetings.  Re this:

> Date: 17 Feb 2002 01:21:18 -0000
> From: address@hidden
> To: address@hidden, address@hidden
> Subject: gawk long lines bug?
>
> The enclosed uu-encoded gzip'd tar file documents a gawk crash on a "sub"
> function string replacement on a 200000-byte line that succeeds on a similar
> 100000-byte line.  The failure occurs with GNU Awk 3.1.0, 3.0.6, and 3.0.3
> on Intel PC's.  Note that I previously documented a similar bug in GNU sed.
>
> Any ideas on what is going on?
>
> Thanks,
>
> -- Dave Slate

The problem is that the regex routines return -2 indicating that they
couldn't allocate enough memory to handle the long string, but gawk
doesn't catch it.  The following patch "fixes" this, and gawk at least now
dies with a reasonable error message instead of with an internal error.

I notice that both the Bell Labs awk and mawk can handle your program
and data just fine.  That gawk can't is a problem in the regex routines.
Unfortunately, *that* code is way out of my league (fools rush in where
angels fear to tread, so to speak), and I don't expect a fix to regex
anytime soon.

I suspect that something similar is happening in GNU sed, but I haven't
looked at its code.

If you don't need any of the gawk extensions, I suggest you switch to
using mawk.

Thanks,

Arnold Robbins
------------------------------
Sun Feb 17 14:57:43 2002  Arnold D. Robbins  <address@hidden>

        * builtin.c (research): If re_search() returns -2, the
          match failed since regex couldn't allocate enough memory
          for what it needed.  Fail with a fatal message instead.
          This is a workaround, not a fix, but I don't mess with
          regex.[ch].

*** ../gawk-3.1.0/re.c  Sun Jan 28 21:06:38 2001
--- re.c        Sun Feb 17 14:55:23 2002
***************
*** 163,169 ****
                if (need_start || rp->dfa == FALSE || try_backref) {
                        int res = re_search(&(rp->pat), str, start+len,
                                        start, len, &(rp->regs));
!                       return res;
                } else
                        return 1;
        } else
--- 194,206 ----
                if (need_start || rp->dfa == FALSE || try_backref) {
                        int res = re_search(&(rp->pat), str, start+len,
                                        start, len, &(rp->regs));
! 
!                       /* if internal allocations failed, die. */
!                       if (res == -2)
!                               fatal(_("regex match failed, not enough memory 
to match string \"%.*s...\""),
!                                               len > 10 ? 10 : len, str + 
start);
!                       else
!                               return res;
                } else
                        return 1;
        } else



reply via email to

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