]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
Avoid comparisons of different signs
authorChristian Göttsche <cgzones@googlemail.com>
Tue, 24 Jan 2023 15:05:20 +0000 (16:05 +0100)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Wed, 25 Jan 2023 11:31:17 +0000 (12:31 +0100)
Comparisons if different signedness can result in unexpected results.
Add casts to ensure operants are of the same type.

    gettime.c: In function 'gettime':
    gettime.c:58:26: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'time_t' {aka 'long int'} [-Wsign-compare]
       58 |         } else if (epoch > fallback) {
          |                          ^

Cast to time_t, since epoch is less than ULONG_MAX at this point.

    idmapping.c: In function 'write_mapping':
    idmapping.c:202:48: warning: comparison of integer expressions of different signedness: 'int' and 'long unsigned int' [-Wsign-compare]
      202 |                 if ((written <= 0) || (written >= (bufsize - (pos - buf)))) {
          |                                                ^~

    newgidmap.c: In function ‘main’:
    newgidmap.c:178:40: warning: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Wsign-compare]
      178 |         if ((written <= 0) || (written >= sizeof(proc_dir_name))) {
          |                                        ^~
    newuidmap.c: In function ‘main’:
    newuidmap.c:107:40: warning: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Wsign-compare]
      107 |         if ((written <= 0) || (written >= sizeof(proc_dir_name))) {
          |                                        ^~

libmisc/gettime.c
libmisc/idmapping.c
src/newgidmap.c
src/newuidmap.c

index b2884022c213ad9475f89f8b9dba091133d66320..5bdc71c15eaf8f990092d157a19c8f1f74228508 100644 (file)
@@ -55,7 +55,7 @@
                fprintf (shadow_logfd,
                         _("Environment variable $SOURCE_DATE_EPOCH: value must be smaller than or equal to %lu but was found to be: %llu\n"),
                         ULONG_MAX, epoch);
-       } else if (epoch > fallback) {
+       } else if ((time_t)epoch > fallback) {
                fprintf (shadow_logfd,
                         _("Environment variable $SOURCE_DATE_EPOCH: value must be smaller than or equal to the current time (%lu) but was found to be: %llu\n"),
                         fallback, epoch);
index 30eb89fde068b7a5f658e53013fed440e4235ee0..64985f82c88b013880ee57e86fedffb5f71c0c4c 100644 (file)
@@ -199,7 +199,7 @@ void write_mapping(int proc_dir_fd, int ranges, const struct map_range *mappings
                        mapping->upper,
                        mapping->lower,
                        mapping->count);
-               if ((written <= 0) || (written >= (bufsize - (pos - buf)))) {
+               if ((written <= 0) || ((size_t)written >= (bufsize - (pos - buf)))) {
                        fprintf(log_get_logfd(), _("%s: snprintf failed!\n"), log_get_progname());
                        exit(EXIT_FAILURE);
                }
index 5b42431b5d2fb2814df37d4bd276c4240164cbb3..01d0fe90a85cca11b812661e2e4fecfcbcde7500 100644 (file)
@@ -175,7 +175,7 @@ int main(int argc, char **argv)
        /* max string length is 6 + 10 + 1 + 1 = 18, allocate 32 bytes */
        written = snprintf(proc_dir_name, sizeof(proc_dir_name), "/proc/%u/",
                target);
-       if ((written <= 0) || (written >= sizeof(proc_dir_name))) {
+       if ((written <= 0) || ((size_t)written >= sizeof(proc_dir_name))) {
                fprintf(stderr, "%s: snprintf of proc path failed: %s\n",
                        Prog, strerror(errno));
        }
index 546856a215afb4959133ab03da63ea3680e5eb0d..e8798409bc042c36a9feb944997be23c6b559d47 100644 (file)
@@ -104,7 +104,7 @@ int main(int argc, char **argv)
        /* max string length is 6 + 10 + 1 + 1 = 18, allocate 32 bytes */
        written = snprintf(proc_dir_name, sizeof(proc_dir_name), "/proc/%u/",
                target);
-       if ((written <= 0) || (written >= sizeof(proc_dir_name))) {
+       if ((written <= 0) || ((size_t)written >= sizeof(proc_dir_name))) {
                fprintf(stderr, "%s: snprintf of proc path failed: %s\n",
                        Prog, strerror(errno));
        }