This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix: local variable hiding parameter of same name
authorJames E Keenan <jkeenan@cpan.org>
Fri, 8 Nov 2019 15:17:50 +0000 (10:17 -0500)
committerJames E Keenan <jkeenan@cpan.org>
Tue, 12 Nov 2019 19:50:59 +0000 (19:50 +0000)
LGTM provides static code analysis and recommendations for code quality
improvements.  Their recent run over the Perl 5 core distribution
identified 12 instances where a local variable hid a parameter of
the same name in an outer scope.  The LGTM rule governing this situation
can be found here:

Per: https://lgtm.com/rules/2156240606/

This patch renames local variables in approximately 8 of those instances
to comply with the LGTM recommendation.  Suggestions for renamed
variables were made by Tony Cook.

For: https://github.com/Perl/perl5/pull/17281

hv.c
mg.c
mro_core.c
sv.c
toke.c
utf8.c
util.c

diff --git a/hv.c b/hv.c
index da0014c..d34a79b 100644 (file)
--- a/hv.c
+++ b/hv.c
@@ -2396,17 +2396,17 @@ Perl_hv_name_set(pTHX_ HV *hv, const char *name, U32 len, U32 flags)
        if (iter->xhv_name_u.xhvnameu_name) {
            if(iter->xhv_name_count) {
              if(flags & HV_NAME_SETALL) {
-               HEK ** const name = HvAUX(hv)->xhv_name_u.xhvnameu_names;
-               HEK **hekp = name + (
+               HEK ** const this_name = HvAUX(hv)->xhv_name_u.xhvnameu_names;
+               HEK **hekp = this_name + (
                    iter->xhv_name_count < 0
                     ? -iter->xhv_name_count
                     :  iter->xhv_name_count
                   );
-               while(hekp-- > name+1) 
+               while(hekp-- > this_name+1)
                    unshare_hek_or_pvn(*hekp, 0, 0, 0);
                /* The first elem may be null. */
-               if(*name) unshare_hek_or_pvn(*name, 0, 0, 0);
-               Safefree(name);
+               if(*this_name) unshare_hek_or_pvn(*this_name, 0, 0, 0);
+               Safefree(this_name);
                 iter = HvAUX(hv); /* may been realloced */
                spot = &iter->xhv_name_u.xhvnameu_name;
                iter->xhv_name_count = 0;
diff --git a/mg.c b/mg.c
index 7d2314f..295ffc6 100644 (file)
--- a/mg.c
+++ b/mg.c
@@ -1933,8 +1933,8 @@ Perl_magic_methcall(pTHX_ SV *sv, const MAGIC *mg, SV *meth, U32 flags,
        va_start(args, argc);
 
        do {
-           SV *const sv = va_arg(args, SV *);
-           PUSHs(sv);
+           SV *const this_sv = va_arg(args, SV *);
+           PUSHs(this_sv);
        } while (--argc);
 
        va_end(args);
index ffcbba6..1fc7c7c 100644 (file)
@@ -859,15 +859,15 @@ Perl_mro_package_moved(pTHX_ HV * const stash, HV * const oldstash,
        mro_isa_changed_in on each. */
     hv_iterinit(stashes);
     while((iter = hv_iternext(stashes))) {
-       HV * const stash = *(HV **)HEK_KEY(HeKEY_hek(iter));
-       if(HvENAME(stash)) {
+       HV * const this_stash = *(HV **)HEK_KEY(HeKEY_hek(iter));
+       if(HvENAME(this_stash)) {
            /* We have to restore the original meta->isa (that
               mro_gather_and_rename set aside for us) this way, in case
               one class in this list is a superclass of a another class
               that we have already encountered. In such a case, meta->isa
               will have been overwritten without old entries being deleted
               from PL_isarev. */
-           struct mro_meta * const meta = HvMROMETA(stash);
+           struct mro_meta * const meta = HvMROMETA(this_stash);
            if(meta->isa != (HV *)HeVAL(iter)){
                SvREFCNT_dec(meta->isa);
                meta->isa
@@ -876,7 +876,7 @@ Perl_mro_package_moved(pTHX_ HV * const stash, HV * const oldstash,
                    : (HV *)HeVAL(iter);
                HeVAL(iter) = NULL; /* We donated our reference count. */
            }
-           mro_isa_changed_in(stash);
+           mro_isa_changed_in(this_stash);
        }
     }
 }
diff --git a/sv.c b/sv.c
index 8a08197..69ff0d7 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -12188,15 +12188,15 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p
             /* the asterisk specified a width */
             {
                 int i = 0;
-                SV *sv = NULL;
+                SV *width_sv = NULL;
                 if (args)
                     i = va_arg(*args, int);
                 else {
                     ix = ix ? ix - 1 : svix++;
-                    sv = (ix < sv_count) ? svargs[ix]
+                    width_sv = (ix < sv_count) ? svargs[ix]
                                       : (arg_missing = TRUE, (SV*)NULL);
                 }
-                width = S_sprintf_arg_num_val(aTHX_ args, i, sv, &left);
+                width = S_sprintf_arg_num_val(aTHX_ args, i, width_sv, &left);
             }
         }
        else if (*q == 'v') {
@@ -12243,17 +12243,17 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p
 
                 {
                     int i = 0;
-                    SV *sv = NULL;
+                    SV *width_sv = NULL;
                     bool neg = FALSE;
 
                     if (args)
                         i = va_arg(*args, int);
                     else {
                         ix = ix ? ix - 1 : svix++;
-                        sv = (ix < sv_count) ? svargs[ix]
+                        width_sv = (ix < sv_count) ? svargs[ix]
                                           : (arg_missing = TRUE, (SV*)NULL);
                     }
-                    precis = S_sprintf_arg_num_val(aTHX_ args, i, sv, &neg);
+                    precis = S_sprintf_arg_num_val(aTHX_ args, i, width_sv, &neg);
                     has_precis = !neg;
                     /* ignore negative precision */
                     if (!has_precis)
diff --git a/toke.c b/toke.c
index 24df24d..6dcb6fe 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -9712,11 +9712,11 @@ S_parse_ident(pTHX_ char **s, char **d, char * const e, int allow_package,
     }
     if (UNLIKELY(tick_warn && saw_tick && PL_lex_state == LEX_INTERPNORMAL
               && !PL_lex_brackets && ckWARN(WARN_SYNTAX))) {
-        char *d;
+        char *this_d;
        char *d2;
-        Newx(d, *s - olds + saw_tick + 2, char); /* +2 for $# */
-        d2 = d;
-        SAVEFREEPV(d);
+        Newx(this_d, *s - olds + saw_tick + 2, char); /* +2 for $# */
+        d2 = this_d;
+        SAVEFREEPV(this_d);
         Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
                          "Old package separator used in string");
         if (olds[-1] == '#')
@@ -9732,7 +9732,7 @@ S_parse_ident(pTHX_ char **s, char **d, char * const e, int allow_package,
         }
         Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
                          "\t(Did you mean \"%" UTF8f "\" instead?)\n",
-                          UTF8fARG(is_utf8, d2-d, d));
+                          UTF8fARG(is_utf8, d2-this_d, this_d));
     }
     return;
 }
diff --git a/utf8.c b/utf8.c
index 1594039..2aeb0fa 100644 (file)
--- a/utf8.c
+++ b/utf8.c
@@ -3884,8 +3884,8 @@ Perl__to_utf8_fold_flags(pTHX_ const U8 *p,
            /* Look at every character in the result; if any cross the
            * boundary, the whole thing is disallowed */
            U8* s = ustrp;
-           U8* e = ustrp + *lenp;
-           while (s < e) {
+           U8* send = ustrp + *lenp;
+           while (s < send) {
                if (isASCII(*s)) {
                    /* Crossed, have to return the original */
                    original = valid_utf8_to_uvchr(p, lenp);
diff --git a/util.c b/util.c
index 76f6ef4..caba9f0 100644 (file)
--- a/util.c
+++ b/util.c
@@ -2377,23 +2377,23 @@ Perl_my_popen_list(pTHX_ const char *mode, int n, SV **args)
     /* If we managed to get status pipe check for exec fail */
     if (did_pipes && pid > 0) {
        int errkid;
-       unsigned n = 0;
+       unsigned read_total = 0;
 
-       while (n < sizeof(int)) {
+       while (read_total < sizeof(int)) {
             const SSize_t n1 = PerlLIO_read(pp[0],
-                             (void*)(((char*)&errkid)+n),
-                             (sizeof(int)) - n);
+                             (void*)(((char*)&errkid)+read_total),
+                             (sizeof(int)) - read_total);
            if (n1 <= 0)
                break;
-           n += n1;
+           read_total += n1;
        }
        PerlLIO_close(pp[0]);
        did_pipes = 0;
-       if (n) {                        /* Error */
+       if (read_total) {                       /* Error */
            int pid2, status;
            PerlLIO_close(p[This]);
-           if (n != sizeof(int))
-               Perl_croak(aTHX_ "panic: kid popen errno read, n=%u", n);
+           if (read_total != sizeof(int))
+               Perl_croak(aTHX_ "panic: kid popen errno read, n=%u", read_total);
            do {
                pid2 = wait4pid(pid, &status, 0);
            } while (pid2 == -1 && errno == EINTR);