Fix missing numeric casts in cord
authorIvan Maidanski <ivmai@mail.ru>
Fri, 12 Feb 2016 18:12:40 +0000 (21:12 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Fri, 12 Feb 2016 18:12:40 +0000 (21:12 +0300)
* 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).

cord/cordprnt.c
cord/cordxtra.c
cord/tests/de.c

index 6e36c09..a33e3f3 100644 (file)
@@ -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);
index 6be86b2..be336a5 100644 (file)
@@ -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)
index a933afb..c42de8e 100644 (file)
@@ -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