Subject: Too many [-Wsign-compare] warnings

From: Bjarni Ingi Gislason <[email-masked]>
Date: Thu, 9 Feb 2023 00:10:59 +0000

Compiling diffutils from git shows for example

In file included from ../../src/cmp.c:19:
../../src/cmp.c: In function 'cmp':
../../src/system.h:108:24: warning: comparison of integer expressions of different signedness: 'off_t' {aka 'long int'} and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
  108 | #define MIN(a, b) ((a) <= (b) ? (a) : (b))
      |                        ^~
../../src/cmp.c:419:38: note: in expansion of macro 'MIN'
  419 |               size_t bytes_to_read = MIN (ig, buf_size);
      |                                      ^~~
../../src/system.h:108:33: warning: operand of '?:' changes signedness from 'off_t' {aka 'long int'} to 'size_t' {aka 'long unsigned int'} due to unsignedness of other operand [-Wsign-compare]
  108 | #define MIN(a, b) ((a) <= (b) ? (a) : (b))
      |                                 ^~~
../../src/cmp.c:419:38: note: in expansion of macro 'MIN'
  419 |               size_t bytes_to_read = MIN (ig, buf_size);
      |                                      ^~~
../../src/cmp.c:439:25: warning: comparison of integer expressions of different signedness: 'intmax_t' {aka 'long int'} and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
  439 |           if (remaining < bytes_to_read)
      |                         ^

  Total number is 26.