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: Andrew J. Schorr
Subject: Re: [bug-gawk] [bug report] gawk doesn???t work correctly when assign special value to variable
Date: Sun, 9 Aug 2015 20:02:25 -0400
User-agent: Mutt/1.5.23 (2014-03-12)

On Sun, Aug 09, 2015 at 07:40:19PM -0400, Andrew J. Schorr wrote:
> On Fri, Aug 07, 2015 at 06:26:12PM +0200, Hermann Peifer wrote:
> > $ gawk -v var="00e1" '$2==var{print $0, typeof(var), typeof($2)}' 1.txt
> > 00e1 00e1 string strnum
> > 00e2 00e4 string strnum
> > 
> > Above, I just gave it a try using gawk/master which says that typeof(var) is
> > string, which in return should result into a string comparison according to
> > the manual. So I would also expect the comparison to fail in the 2nd line:
> > 
> > $2 = 00e4/strnum is not string-equal with var = 00e1/string
> 
> I noticed the same issue.  I'm guessing it's a bug in typeof, but I'm not 
> certain
> what's going on.  I guess this needs to be debugged.  The builtin.c:do_typeof 
> function
> tests for the MAYBE_NUM flag to decide whether it's a string or a strnum.
> And in main.c:arg_assign, it appears that MAYBE_NUM is set for command-line
> variable assignments.  But something strange is clearly happening...

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.

Regards,
Andy

Attachment: typeof.patch
Description: Text document


reply via email to

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