Skip Menu |
Report information
Id: 131725
Status: open
Priority: 0/
Queue: perl5

Owner: Nobody
Requestors: ruud.vantol [at] booking.com
Cc:
AdminCc:

Operating System: (no value)
PatchStatus: (no value)
Severity: low
Type: core
Perl Version: (no value)
Fixed In: (no value)

Attachments
0001-perl-131725-ignore-the-exponent-on-a-decimal-float-i.patch



Subject: number parsing
To: perlbug [...] perl.org
From: ruud.vantol [...] booking.com
Date: Sun, 9 Jul 2017 13:56:09 +0200 (CEST)
Download (untitled) / with headers
text/plain 495b
This is a bug report for perl from ruud.vantol@booking.com, generated with the help of perlbug 1.39 running under perl 5.18.2. ----------------------------------------------------------------- [Please describe your issue here] perl -wE'say 1e--5' -4 I think it should die if there is no digit directly after the 'e' and sign. [Please do not change anything below this line] ----------------------------------------------------------------- --- Flags: category=core severity=low ---
RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 263b
On Sun, 09 Jul 2017 05:11:37 -0700, ruud.vantol@booking.com wrote: Show quoted text
> > perl -wE'say 1e--5' > -4 > > I think it should die if there is no digit directly after the 'e' and sign.
The attached prevents consuming the "e-" if there's no digits in the exponent. Tony
Subject: 0001-perl-131725-ignore-the-exponent-on-a-decimal-float-i.patch
From 01378fadacb66c3905dd881fc28f30f573547aee Mon Sep 17 00:00:00 2001 From: Tony Cook <tony@develop-help.com> Date: Thu, 3 Aug 2017 12:11:56 +1000 Subject: (perl #131725) ignore the exponent on a decimal float if no digits Previously the "1e-" in "1e--5" would be treated as "1", but consumed the "e-". This wasn't an issue for hex floats. I considered (and implemented) croaking instead, but this was inconsistent with the behaviour for hex floats, which only reach this code if a full hex float has been parsed. --- t/lib/croak/toke | 10 ++++++++++ toke.c | 21 +++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/t/lib/croak/toke b/t/lib/croak/toke index 2603224..c477be0 100644 --- a/t/lib/croak/toke +++ b/t/lib/croak/toke @@ -394,3 +394,13 @@ $a = <<~ ; EXPECT Use of bare << to mean <<"" is forbidden at - line 1. +######## +# NAME incomplete floating point decimal exponent (#131725) +1e--5 +EXPECT +Bareword found where operator expected at - line 1, near "1e" + (Missing operator before e?) +Number found where operator expected at - line 1, near "--5" + (Missing operator before 5?) +syntax error at - line 1, near "1e" +Execution of - aborted due to compilation errors. diff --git a/toke.c b/toke.c index 6aa5f26..6de7d09 100644 --- a/toke.c +++ b/toke.c @@ -11182,9 +11182,11 @@ Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp) || UNLIKELY(hexfp && isALPHA_FOLD_EQ(*s, 'p'))) && strchr("+-0123456789_", s[1])) { - floatit = TRUE; + int exp_digits = 0; + const char *save_s = s; + char * save_d = d; - /* regardless of whether user said 3E5 or 3e5, use lower 'e', + /* regardless of whether user said 3E5 or 3e5, use lower 'e', ditto for p (hexfloats) */ if ((isALPHA_FOLD_EQ(*s, 'e'))) { /* At least some Mach atof()s don't grok 'E' */ @@ -11216,6 +11218,7 @@ Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp) /* read digits of exponent */ while (isDIGIT(*s) || *s == '_') { if (isDIGIT(*s)) { + ++exp_digits; if (d >= e) Perl_croak(aTHX_ "%s", number_too_long); *d++ = *s++; @@ -11227,6 +11230,20 @@ Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp) lastub = s++; } } + + if (!exp_digits) { + /* no exponent digits, the [eEpP] could be for something else, + * though in practice we don't get here for p since that's preparsed + * earlier, and results in only the 0xX being consumed, so behave similarly + * for decimal floats and consume only the D.DD, leaving the [eE] to the + * next token. + */ + s = save_s; + d = save_d; + } + else { + floatit = TRUE; + } } -- 2.1.4
RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 475b
On Wed, 02 Aug 2017 19:15:25 -0700, tonyc wrote: Show quoted text
> On Sun, 09 Jul 2017 05:11:37 -0700, ruud.vantol@booking.com wrote:
> > > > perl -wE'say 1e--5' > > -4 > > > > I think it should die if there is no digit directly after the 'e' and > > sign.
> > The attached prevents consuming the "e-" if there's no digits in the > exponent.
Applied as adb0f5c46e10ac97fd958f4cd5526ea6d4b058f6. If it ends up causing lots of CPAN failures it may need to be changed to a deprecation. Tony
To: perlbug-followup [...] perl.org
Date: Mon, 14 Aug 2017 15:01:35 +0200
CC: perl5-porters [...] perl.org
Subject: Re: [perl #131725] number parsing
From: Sawyer X <xsawyerx [...] gmail.com>
Download (untitled) / with headers
text/plain 551b
On 08/14/2017 07:59 AM, Tony Cook via RT wrote: Show quoted text
> On Wed, 02 Aug 2017 19:15:25 -0700, tonyc wrote:
>> On Sun, 09 Jul 2017 05:11:37 -0700, ruud.vantol@booking.com wrote:
>>> perl -wE'say 1e--5' >>> -4 >>> >>> I think it should die if there is no digit directly after the 'e' and >>> sign.
>> The attached prevents consuming the "e-" if there's no digits in the >> exponent.
> Applied as adb0f5c46e10ac97fd958f4cd5526ea6d4b058f6. > > If it ends up causing lots of CPAN failures it may need to be changed to a deprecation.
I think that's a good idea.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org