From: Ivan Maidanski Date: Mon, 12 Nov 2018 07:30:18 +0000 (+0300) Subject: Eliminate 'casting signed to bigger unsigned int' CSA warning X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5407e712dd7c381c857827cdaf2902158213e07d;p=gc Eliminate 'casting signed to bigger unsigned int' CSA warning * 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). --- diff --git a/cord/cordprnt.c b/cord/cordprnt.c index d9d9f536..0195cce0 100644 --- a/cord/cordprnt.c +++ b/cord/cordprnt.c @@ -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); diff --git a/cord/tests/cordtest.c b/cord/tests/cordtest.c index c3ad01f4..73ab82aa 100644 --- a/cord/tests/cordtest.c +++ b/cord/tests/cordtest.c @@ -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++; } diff --git a/dbg_mlc.c b/dbg_mlc.c index a8bd8154..d09f309b 100644 --- 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; diff --git a/include/private/dbg_mlc.h b/include/private/dbg_mlc.h index 33e810e8..e38475a6 100644 --- a/include/private/dbg_mlc.h +++ b/include/private/dbg_mlc.h @@ -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 ced405bd..d45b9b57 100644 --- 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);