bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: match() prevents numeric strings from beeing treated numerically


From: Aharon Robbins
Subject: Re: match() prevents numeric strings from beeing treated numerically
Date: Wed, 30 Jul 2008 22:53:52 +0300

Greetings. Re this:

> Date: Mon, 28 Jul 2008 17:25:32 +0200
> From: Dirk Zimoch <address@hidden>
> Subject: match() prevents numeric strings from beeing treated numerically
> To: address@hidden
>
> In gawk version 3.1.5, numeric user input that is parsed with match() is not 
> recognized as "numeric string" any more. I.e. mixed string-numeric comparison 
> does not work any more. In version 3.1.1, it worked. (Even though the 
> documentation never explicitly mentioned this behavior for match(), as it 
> does 
> for split(). But is says that "user input" should be treated that way.)
>
> awk 'BEGIN{match(".5",/.*/,a);print a[0]==.5?"OK":"FAULT"}'
>
> Version 3.1.1 prints OK, version 3.1.5 prints FAULT.
>
> awk '{match($0,/.*/,a);print a[0]==a[0]+0?"OK":"FAULT"}' << EOF
> 5
> 5.0
> 0.5
> .5
> EOF
>
> Version 3.1.1 prints
> OK
> OK
> OK
> OK
>
> Version 3.1.5 prints
> OK
> FAULT
> OK
> FAULT
>
> -- 
> Dr. Dirk Zimoch
> Paul Scherrer Institut, WBGB/006
> 5232 Villigen PSI, Switzerland
> Phone +41 56 310 5182

I agree, I think it's a bug. The behavior changed between 3.1.1 and
3.1.2 which was quite a long time ago, so who knows what caused it. In
any case, the below patch fixes the problem. This will make its way to
the gawk CVS repository shortly.  Thank you for the excellent bug report.

Arnold
---------------------------------------------------

Wed Jul 30 22:27:20 2008  Arnold D. Robbins  <address@hidden>

        * builtin.c (do_match): Add MAYBE_NUM flag to elements of array
        created by `match' since data could come from user. Similar
        semantics to `split'. Thanks to Dr. Dirk Zimoch <address@hidden>
        for reporting the bug.

--- builtin.c   14 May 2008 02:57:38 -0000      1.26
+++ builtin.c   30 Jul 2008 19:22:18 -0000
@@ -2169,6 +2169,7 @@
 #endif
        
                                        it = make_string(start, len);
+                                       it->flags |= MAYBE_NUM; /* user input */
                                        /*
                                         * assoc_lookup() does free_temp() on 
2nd arg.
                                         */




reply via email to

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