bug-gawk
[Top][All Lists]
Advanced

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

Re: readall bugs [PATCH]


From: Andrew J. Schorr
Subject: Re: readall bugs [PATCH]
Date: Fri, 30 Sep 2022 08:50:30 -0400
User-agent: Mutt/1.5.21 (2010-09-15)

Hi,

On Wed, Sep 28, 2022 at 08:53:24AM -0400, Andrew J. Schorr wrote:
> It turns out that readall has some big problems that were not exposed by the
> existing, inadequate test case. I need to dig in.

I think the attached patch against the master branch fixes the readall
problems. There were 3 causes of the brain damage:

1. The gawkapi.c:api_sym_update function was not correctly converting
untyped variables to arrays. It strangely worked in cases where such variables
were passed as arguments to functions, but not when the array was accessed
directly by its global name.

2. The parser awkgram.y had some inconsistent behavior when instantiating array
variables. If the first time the variable appeared in the program, it was used
with a subscript, then the variable was inserted into the global symbol table
as an array (with type Node_var_array). But if that wasn't the case, for
example if the first reference to the variable name was as a function call
argument, then it was created as an untyped variable (with type Node_var_new).
At execution time, gawk happily converts the untyped variable to an array as
needed, but this inconsistency in parsing made it impossible for the readall
function to understand whether the program was using the variable as an array
already whose contents shouldn't be stomped on. The fix is simply to modify the
parser to create the variable as untyped, even if the first instance is with a
subscript.

3. The extension/rwarray.c code had a hack that attempted to work around
the issue in #2 above, but it was not a solution that worked in all cases.
With #2 fixed, there's no need for the hack, and the readall code can
be simplified and should now be robust.

Please give this a try if you have a chance. I have enhanced the test cases
to expose some of the things that were broken previously.

It passes "make check" and "make valgrind" both with and without .developing
on CentOS 7.9.

Arnold -- please let me know if this is OK to commit.

Regards,
Andy

Attachment: readall.patch
Description: Text document


reply via email to

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