[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gawk bug?
From: |
Aharon Robbins |
Subject: |
Re: gawk bug? |
Date: |
Tue, 9 Sep 2003 16:10:16 +0300 |
Greetings. Re this:
> From: "Laurent Vogel" <address@hidden>
> To: <address@hidden>
> Subject: gawk bug?
> Date: Mon, 8 Sep 2003 23:02:53 +0200
>
> Hi,
>
> GNU Awk 3.1.2 (cygwin version) displays weird error messages
> on scripts having long lines:
>
> first, unterminated strings: BEGIN{x="...}
>
> $ perl -e 'print "BEGIN{x=\"", "." x 249, "}";' > foo
> $ awk -f foo
> awk: foo:1:
> BEGIN{x="...........................................................
> ............................................................BEGIN{x=".......
> ....
> ............................................................................
> ....
> ............................................................................
> ....
> ............................................................................
> ..}
> awk: foo:1: fatal error: internal error
> Aborted (core dumped)
>
> $ perl -e 'print "BEGIN{x=\"", "." x 149, "}";' > foo
> $ awk -f foo
> awk: foo:1:
> BEGIN{x="...........................................................
> ............................................................BEGIN{x=".......
> ....
> ............................................................................
> ....
> ..........................................................}
> awk: foo:1: fatal: yyerror: buf: can't allocate -1 bytes of memory (Not
> enough core)
>
> then, terminated strings: BEGIN{x="..."}
>
> $ perl -e 'print "BEGIN{x=\"", "." x 7157, "\"}";' > foo
> $ awk -f foo
> awk: foo:1: fatal error: internal error
> Aborted (core dumped)
>
> I admit that some of the inputs are not necessarily valid, but I don't
> think it is a valid reason for Gawk dumping core.
>
> best regards,
>
> Laurent Vogel
This is indeed a bug, thanks for the report. It was rather nasty to
track down and fix, consisting of several related problems. The following
patch fixes the problem for me: `make check' runs and your examples give
reasonable error messages instead of core dumps.
The patch is relative to 3.1.3, which is the current release, but it
should drop into 3.1.2 as well.
Thanks,
Arnold
----------------- cut here --------------------
Tue Sep 9 15:57:38 2003 Arnold D. Robbins <address@hidden>
* awkgram.y (get_src_buf): Fix calculation of `offset' when shifting
source lines around. In general, improve handling of things when
moving the source code line around. What a mess this code is.
--- ../gawk-3.1.3/awkgram.y 2003-07-04 20:25:23.000000000 +0300
+++ awkgram.y 2003-09-09 15:56:39.000000000 +0300
@@ -1308,21 +1317,21 @@
int offset;
int linelen;
- offset = lexptr - lexeme;
+ offset = lexeme - lexptr;
for (scan = lexeme; scan > lexptr_begin; scan--)
if (*scan == '\n') {
scan++;
break;
}
linelen = lexptr - scan;
- if (linelen > SLOP)
- linelen = SLOP;
- thisline = buf + SLOP - linelen;
- memcpy(thisline, scan, linelen);
- lexeme = buf + SLOP - offset;
+ thisline = buf;
+ memmove(thisline, scan, linelen);
+ lexeme = thisline + (lexeme - lexptr_begin);
+ lexptr = thisline + (lexptr - lexptr_begin);
+ lexend = thisline + (lexend - lexptr_begin);
lexptr_begin = thisline;
}
- n = read(fd, buf + SLOP, len);
+ n = read(fd, lexptr_begin, len);
if (n == -1)
fatal(_("can't read sourcefile `%s' (%s)"),
source, strerror(errno));
@@ -1339,13 +1348,11 @@
close(fd);
samefile = FALSE;
nextfile++;
- if (lexeme)
- *lexeme = '\0';
len = 0;
goto again;
}
- lexptr = buf + SLOP;
+ lexptr = lexptr_begin;
lexend = lexptr + n;
return buf;
}
/* tokadd --- add a character to the token buffer */
- gawk bug?, Laurent Vogel, 2003/09/08
- Re: gawk bug?,
Aharon Robbins <=