[Top][All Lists]

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

Re: [bug-gawk] exit in END block

From: Andrew J. Schorr
Subject: Re: [bug-gawk] exit in END block
Date: Tue, 24 Mar 2015 10:34:01 -0400
User-agent: Mutt/1.5.23 (2014-03-12)

On Tue, Mar 24, 2015 at 07:29:28AM +0100, isabella parakiss wrote:
> "If an expression is specified in an exit statement, its numeric value
> shall be the exit status of awk, unless subsequent errors are encounte-
> red or a subsequent exit statement with an expression is executed."
> This is from the POSIX standard.  I believe that gawk is wrong on it:
> $ gawk 'BEGIN { exit 42 } END { exit }'; echo $?
> 0
> $ mawk 'BEGIN { exit 42 } END { exit }'; echo $?
> 42
> An expression was specified, and no subsequent exit statement with an
> expression was encountered.  According to the standard, this should
> exit with 42, right?  With --posix I get the same result.
> Is there a reason for this?

This used to work correctly in gawk 3.1.8.  It appears that this bug was
introduced in version 4.

I'm not sure whether the attached patch is ideal, but it seems to fix
the problem.  Arnold -- does this look right to you?  I'm a bit queasy
about that comparison to Nnull_string, but it seems to work.  I first
tried patching the LEX_EXIT rule to set $$->nexti->memory to NULL instead
of dupnode(Nnull_string), but that resulted in a crash...

I guess we should probably add a test case for this.


Attachment: exit.patch
Description: Text document

reply via email to

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