This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #125381] fix -Cnn parsing
authorHugo van der Sanden <hv@crypt.org>
Thu, 11 Jun 2015 11:25:40 +0000 (12:25 +0100)
committerHugo van der Sanden <hv@crypt.org>
Thu, 11 Jun 2015 12:33:09 +0000 (13:33 +0100)
Commit 22ff313068 for [perl #123814] inadvertently changed the logic when
parsing a numeric parameter to the -C option, such that the successfully
parsed number was not saved as the option value if it parsed to the end
of the argument.

t/run/switchC.t
util.c

index f6aa868..4f63c3b 100644 (file)
@@ -11,7 +11,7 @@ BEGIN {
     skip_all_if_miniperl('-C and $ENV{PERL_UNICODE} are disabled on miniperl');
 }
 
-plan(tests => 13);
+plan(tests => 14);
 
 my $r;
 
@@ -25,6 +25,11 @@ $r = runperl( switches => [ '-CO', '-w' ],
               stderr   => 1 );
 like( $r, qr/^$b(?:\r?\n)?$/s, '-CO: no warning on UTF-8 output' );
 
+$r = runperl( switches => [ '-C2', '-w' ],
+             prog     => 'print chr(256)',
+              stderr   => 1 );
+like( $r, qr/^$b(?:\r?\n)?$/s, '-C2: no warning on UTF-8 output' );
+
 SKIP: {
     if (exists $ENV{PERL_UNICODE} &&
        ($ENV{PERL_UNICODE} eq "" || $ENV{PERL_UNICODE} =~ /[SO]/)) {
diff --git a/util.c b/util.c
index bc2af99..990c083 100644 (file)
--- a/util.c
+++ b/util.c
@@ -4423,16 +4423,15 @@ Perl_parse_unicode_opts(pTHX_ const char **popt)
        if (isDIGIT(*p)) {
             const char* endptr;
             UV uv;
-            if (grok_atoUV(p, &uv, &endptr)
-                && uv <= U32_MAX
-                && (p = endptr)
-                && *p && *p != '\n' && *p != '\r'
-            ) {
+            if (grok_atoUV(p, &uv, &endptr) && uv <= U32_MAX) {
                 opt = (U32)uv;
-                if (isSPACE(*p))
-                    goto the_end_of_the_opts_parser;
-                else
-                    Perl_croak(aTHX_ "Unknown Unicode option letter '%c'", *p);
+                p = endptr;
+                if (p && *p && *p != '\n' && *p != '\r') {
+                    if (isSPACE(*p))
+                        goto the_end_of_the_opts_parser;
+                    else
+                        Perl_croak(aTHX_ "Unknown Unicode option letter '%c'", *p);
+                }
             }
         }
         else {