bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] [bug report] gawk doesn???t work correctly when assign sp


From: Hermann Peifer
Subject: Re: [bug-gawk] [bug report] gawk doesn???t work correctly when assign special value to variable
Date: Mon, 10 Aug 2015 07:41:19 +0200
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.1.0

On 2015-08-10 2:02, Andrew J. Schorr wrote:
I debugged it.  In main.c:arg_assign, the variable is initially created
with these flags: MALLOC|STRING|STRCUR|MAYBE_NUM.  But a bit later in the
function, there is a call to force_number.  That results in the variable's
having the following flags: MALLOC|STRING|STRCUR|NUMCUR|NUMBER.  That's
what typeof sees.  I believe the comparison occurs in eval.c:cmp_nodes.
At that point, the command-line-assigned variable has flags
MALLOC|STRING|STRCUR|NUMCUR|NUMBER, and the value read from the file has
flags MALLOC|STRING|STRCUR|MAYBE_NUM.  As a result, a numeric comparison
is performed (since force_number on the $2 value sets the NUMBER flag).

I'm not sure what to conclude.  Perhaps the do_typeof function should
be patched to treat the flag combination STRING|NUMBER as "strnum", as
attached.


My patched gawk results into [1] where typeof results would now explain why a numerical comparison has been made. There were some new compiler warnings which might be relevant -- or not [2]. Another side-effect was that 3 TESTS FAILED (_dbugtypedre1, _typedregex2, _typeof1). I guess these can easily be fixed later, if needed.

Does this behaviour (initially created with some flags > call to force_number which changes flags) also occur when handling input data, so that a similar patch would be needed for fixing typeof() results for fields?

Hermann

[1]

$ ./gawk.patched -v var="00e1" '$2==var{print $0, typeof(var), typeof($2)}' 1.txt
00e1 00e1 strnum strnum
00e2 00e4 strnum strnum


[2]

builtin.c:3895:20: warning: '&' within '|' [-Wbitwise-op-parentheses]
                        if ((arg->flags & MAYBE_NUM|NUMBER) != 0)
                             ~~~~~~~~~~~^~~~~~~~~~~~
builtin.c:3895:20: note: place parentheses around the '&' expression to silence this warning
                        if ((arg->flags & MAYBE_NUM|NUMBER) != 0)
                             ~~~~~~~~~~~^~~~~~~~~~~



reply via email to

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