From: Ivan Maidanski Date: Fri, 12 Feb 2016 18:12:40 +0000 (+0300) Subject: Fix missing numeric casts in cord X-Git-Tag: gc7_4_4~37 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c7756f2d92c9d20880bc91cdcfe13fe3fed20b69;p=gc Fix missing numeric casts in cord * cord/cordprnt.c (CORD_vsprintf): Explicitly cast "prec" to unsigned (to avoid assignment of a signed value to a variable of a bigger unsigned integer type). * cord/cordxtra.c (CORD_nul_func, CORD_chars): Cast between pointer and char via GC_word (instead of long); explicitly cast char to unsigned char (to avoid a signed value cast to a bigger unsigned one). * cord/tests/de.c (replace_line): Explicitly cast COLS to unsigned (when compared to "len" local variable). --- diff --git a/cord/cordprnt.c b/cord/cordprnt.c index d7eb62bb..16313565 100644 --- a/cord/cordprnt.c +++ b/cord/cordprnt.c @@ -228,7 +228,7 @@ int CORD_vsprintf(CORD * out, CORD format, va_list args) if (prec != NONE && len > (size_t)prec) { if (prec < 0) return(-1); arg = CORD_substr(arg, 0, prec); - len = prec; + len = (unsigned)prec; } if (width != NONE && len < (size_t)width) { char * blanks = GC_MALLOC_ATOMIC(width-len+1); diff --git a/cord/cordxtra.c b/cord/cordxtra.c index 6be86b2b..be336a5a 100644 --- a/cord/cordxtra.c +++ b/cord/cordxtra.c @@ -443,13 +443,12 @@ void CORD_ec_append_cord(CORD_ec x, CORD s) char CORD_nul_func(size_t i CORD_ATTR_UNUSED, void * client_data) { - return((char)(unsigned long)client_data); + return (char)(GC_word)client_data; } - CORD CORD_chars(char c, size_t i) { - return(CORD_from_fn(CORD_nul_func, (void *)(unsigned long)c, i)); + return CORD_from_fn(CORD_nul_func, (void *)(GC_word)(unsigned char)c, i); } CORD CORD_from_file_eager(FILE * f) diff --git a/cord/tests/de.c b/cord/tests/de.c index c1ef726a..1587980e 100644 --- a/cord/tests/de.c +++ b/cord/tests/de.c @@ -224,7 +224,7 @@ void replace_line(int i, CORD s) } # if !defined(MACINTOSH) /* A gross workaround for an apparent curses bug: */ - if (i == LINES-1 && len == COLS) { + if (i == LINES-1 && len == (unsigned)COLS) { s = CORD_substr(s, 0, len - 1); } # endif