Fix signed vs unsigned comparison (#765)
authorserge-sans-paille <serge.guelton@telecom-bretagne.eu>
Thu, 2 Feb 2023 11:40:17 +0000 (11:40 +0000)
committerGitHub <noreply@github.com>
Thu, 2 Feb 2023 11:40:17 +0000 (06:40 -0500)
As reported by -Wsign-compare. In the case of getting the result of
comparing the result of sysconf (_SC_PAGESIZE) to other value, this also
correctly handles edge cases where the above fails and returns -1.

Co-authored-by: serge-sans-paille <sguelton@mozilla.com>
src/closures.c
src/prep_cif.c
src/tramp.c

index 9aafbec4b8c2a10ad77158fd5d58e46e17398a08..c42527795f212e9c6baf6b50d29cadaff4c60eed 100644 (file)
@@ -795,7 +795,7 @@ open_temp_exec_file (void)
 static int
 allocate_space (int fd, off_t offset, off_t len)
 {
-  static size_t page_size;
+  static long page_size;
 
   /* Obtain system page size. */
   if (!page_size)
index 2d0f2521f07e432ebf8821f0f2719bd76772e364..0e2d58e5e5c1c5d38767156d7e2b06c01e4db50f 100644 (file)
@@ -234,7 +234,7 @@ ffi_status ffi_prep_cif_var(ffi_cif *cif,
 {
   ffi_status rc;
   size_t int_size = ffi_type_sint.size;
-  int i;
+  unsigned int i;
 
   rc = ffi_prep_cif_core(cif, abi, 1, nfixedargs, ntotalargs, rtype, atypes);
 
index b9d273a1a389445c249e560505ed96539fbd1026..7e005b054d67cb758ddd69aa07f76c944fd73e76 100644 (file)
@@ -266,7 +266,7 @@ ffi_tramp_get_temp_file (void)
    * trampoline table to make sure that the temporary file can be mapped.
    */
   count = write(tramp_globals.fd, tramp_globals.text, tramp_globals.map_size);
-  if (count == tramp_globals.map_size && tramp_table_alloc ())
+  if (count >=0 && (size_t)count == tramp_globals.map_size && tramp_table_alloc ())
     return 1;
 
   close (tramp_globals.fd);
@@ -374,6 +374,8 @@ tramp_table_unmap (struct tramp_table *table)
 static int
 ffi_tramp_init (void)
 {
+  long page_size;
+
   if (tramp_globals.status == TRAMP_GLOBALS_PASSED)
     return 1;
 
@@ -396,7 +398,8 @@ ffi_tramp_init (void)
     &tramp_globals.map_size);
   tramp_globals.ntramp = tramp_globals.map_size / tramp_globals.size;
 
-  if (sysconf (_SC_PAGESIZE) > tramp_globals.map_size)
+  page_size = sysconf (_SC_PAGESIZE);
+  if (page_size >= 0 && (size_t)page_size > tramp_globals.map_size)
     return 0;
 
   if (ffi_tramp_init_os ())