Skip to content

Commit

Permalink
locale.c: Change type of a variable to silence compiler warning
Browse files Browse the repository at this point in the history
The variable `already_checked` in Perl_init_i18nl10n() never become
negative, and never exceed `C_trial` which is a small positive integer.
Thus `unsigned int` should be enough.

This fixes build warning on 32-bit target
(where sizeof(unsigned int) == sizeof(SSize_t)):
    locale.c: In function ‘Perl_init_i18nl10n’:
    locale.c:7370:40: warning: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘ssize_t’ {aka ‘int’} [-Wsign-compare]
     7370 |             for (unsigned int i = 0; i < already_checked; i++) {
          |                                        ^
  • Loading branch information
t-a-k authored and tonycoz committed Nov 28, 2023
1 parent 3ac05d1 commit 69a1e3a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion locale.c
Expand Up @@ -7288,7 +7288,7 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
} trials;

trials trial;
SSize_t already_checked = 0;
unsigned int already_checked = 0;
const char * checked[C_trial];

# ifdef LC_ALL
Expand Down Expand Up @@ -7374,6 +7374,7 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
}

/* And, for future iterations, indicate we've tried this locale */
assert(already_checked < C_ARRAY_LENGTH(checked));
checked[already_checked] = savepv(locale);
SAVEFREEPV(checked[already_checked]);
already_checked++;
Expand Down

0 comments on commit 69a1e3a

Please sign in to comment.