Eliminate 'casting signed to bigger unsigned int' CSA warning
authorIvan Maidanski <ivmai@mail.ru>
Mon, 12 Nov 2018 07:30:18 +0000 (10:30 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Mon, 12 Nov 2018 17:45:19 +0000 (20:45 +0300)
* cord/cordprnt.c (CORD_vsprintf): Cast prec, width, max_size, res
local variables to unsigned.
* cord/tests/cordtest.c (test_basics): Change type of i local variable
from int to size_t; cast c local variable to unsigned char.
* dbg_mlc.c (GC_store_debug_info_inner): Do not cast linenum parameter.
* include/private/dbg_mlc.h (oh.oh_string, oh.oh_int): Refine comment.
* include/private/dbg_mlc.h (oh.oh_int): Change type from word to
signed_word.
* misc.c [!GC_GET_HEAP_USAGE_NOT_NEEDED] (fill_prof_stats): Cast
GC_markers_m1 to signed_word first.
* misc.c (GC_init): Cast space_divisor local variable to unsigned
(instead of word).
* misc.c [!MSWIN32 && !MSWINCE && !OS2 && !MACOS && !GC_ANDROID_LOG]
(GC_write): Cast bytes_written local variable to unsigned (instead of
size_t).

cord/cordprnt.c
cord/tests/cordtest.c
dbg_mlc.c
include/private/dbg_mlc.h
misc.c

index d9d9f53..0195cce 100644 (file)
@@ -241,18 +241,18 @@ int CORD_vsprintf(CORD * out, CORD format, va_list args)
                         if (prec == VARIABLE) prec = va_arg(args, int);
                         arg = va_arg(args, CORD);
                         len = CORD_len(arg);
-                        if (prec != NONE && len > (size_t)prec) {
+                        if (prec != NONE && len > (unsigned)prec) {
                           if (prec < 0) return(-1);
-                          arg = CORD_substr(arg, 0, prec);
+                          arg = CORD_substr(arg, 0, (unsigned)prec);
                           len = (unsigned)prec;
                         }
-                        if (width != NONE && len < (size_t)width) {
-                          char * blanks =
-                                (char *)GC_MALLOC_ATOMIC(width - len + 1);
+                        if (width != NONE && len < (unsigned)width) {
+                          char * blanks = (char *)GC_MALLOC_ATOMIC(
+                                                (unsigned)width - len + 1);
 
                           if (NULL == blanks) OUT_OF_MEMORY;
-                          memset(blanks, ' ', width-len);
-                          blanks[width-len] = '\0';
+                          memset(blanks, ' ', (unsigned)width - len);
+                          blanks[(unsigned)width - len] = '\0';
                           if (left_adj) {
                             arg = CORD_cat(arg, blanks);
                           } else {
@@ -307,7 +307,7 @@ int CORD_vsprintf(CORD * out, CORD format, va_list args)
                     if (prec != NONE && prec > max_size) max_size = prec;
                     max_size += CONV_RESULT_LEN;
                     if (max_size >= CORD_BUFSZ) {
-                        buf = (char *)GC_MALLOC_ATOMIC(max_size + 1);
+                        buf = (char *)GC_MALLOC_ATOMIC((unsigned)max_size + 1);
                         if (NULL == buf) OUT_OF_MEMORY;
                     } else {
                         if (CORD_BUFSZ - (result[0].ec_bufptr-result[0].ec_buf)
@@ -352,7 +352,7 @@ int CORD_vsprintf(CORD * out, CORD format, va_list args)
                            && !defined(__EMX__))
                       va_end(vsprintf_args);
 #                   endif
-                    len = (size_t)res;
+                    len = (unsigned)res;
                     if ((char *)(GC_word)res == buf) {
                         /* old style vsprintf */
                         len = strlen(buf);
index c3ad01f..73ab82a 100644 (file)
@@ -65,7 +65,7 @@ char id_cord_fn(size_t i, void * client_data)
 void test_basics(void)
 {
     CORD x = CORD_from_char_star("ab");
-    int i;
+    size_t i;
     CORD y;
     CORD_pos p;
 
@@ -128,7 +128,8 @@ void test_basics(void)
     while(CORD_pos_valid(p)) {
         char c = CORD_pos_fetch(p);
 
-        if(c != i) ABORT("Traversal of function node failed");
+        if ((unsigned char)c != i)
+            ABORT("Traversal of function node failed");
         CORD_next(p);
         i++;
     }
index a8bd815..d09f309 100644 (file)
--- a/dbg_mlc.c
+++ b/dbg_mlc.c
@@ -287,7 +287,7 @@ GC_INNER void *GC_store_debug_info_inner(void *p, word sz GC_ATTR_UNUSED,
       ((oh *)p) -> oh_bg_ptr = HIDE_BACK_PTR((ptr_t)0);
 #   endif
     ((oh *)p) -> oh_string = string;
-    ((oh *)p) -> oh_int = (word)linenum;
+    ((oh *)p) -> oh_int = linenum;
 #   ifndef SHORT_DBG_HDRS
       ((oh *)p) -> oh_sz = sz;
       ((oh *)p) -> oh_sf = START_FLAG ^ (word)result;
index 33e810e..e38475a 100644 (file)
@@ -95,8 +95,8 @@ typedef struct {
       word oh_dummy;
 #   endif
 # endif
-  const char * oh_string;       /* object descriptor string     */
-  word oh_int;                  /* object descriptor integers   */
+  const char * oh_string;       /* object descriptor string (file name)    */
+  signed_word oh_int;           /* object descriptor integer (line number) */
 # ifdef NEED_CALLINFO
     struct callinfo oh_ci[NFRAMES];
 # endif
diff --git a/misc.c b/misc.c
index ced405b..d45b9b5 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -545,7 +545,7 @@ GC_API void GC_CALL GC_get_heap_usage_safe(GC_word *pheap_size,
     pstats->non_gc_bytes = GC_non_gc_bytes;
     pstats->gc_no = GC_gc_no; /* could be -1 */
 #   ifdef PARALLEL_MARK
-      pstats->markers_m1 = (word)GC_markers_m1;
+      pstats->markers_m1 = (word)((signed_word)GC_markers_m1);
 #   else
       pstats->markers_m1 = 0; /* one marker */
 #   endif
@@ -1154,7 +1154,7 @@ GC_API void GC_CALL GC_init(void)
         if (space_divisor_string != NULL) {
           int space_divisor = atoi(space_divisor_string);
           if (space_divisor > 0)
-            GC_free_space_divisor = (word)space_divisor;
+            GC_free_space_divisor = (unsigned)space_divisor;
         }
     }
 #   ifdef USE_MUNMAP
@@ -1753,7 +1753,7 @@ GC_API void GC_CALL GC_enable_incremental(void)
       IF_CANCEL(int cancel_state;)
 
       DISABLE_CANCEL(cancel_state);
-      while ((size_t)bytes_written < len) {
+      while ((unsigned)bytes_written < len) {
 #        ifdef GC_SOLARIS_THREADS
              int result = syscall(SYS_write, fd, buf + bytes_written,
                                              len - bytes_written);