Eliminate warnings detected by Cppcheck in cord de[_win]
authorIvan Maidanski <ivmai@mail.ru>
Sat, 14 Jun 2014 16:30:42 +0000 (20:30 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Sat, 14 Jun 2014 16:30:42 +0000 (20:30 +0400)
* cord/tests/de.c (prune_map): Remove redundant first check of map for
NULL (as "map" variable has already been dereferenced at the point of
the check).
* cord/tests/de.c (replace_line): Do not define "len" local variable
if not used; eliminate duplicate CORD_len(s) call.
* cord/tests/de_win.c (WndProc): Cast char_width and char_height
global variables to unsigned int in division of unsigned xpos, ypos
local variables.

cord/tests/de.c
cord/tests/de_win.c

index ee01e3f..28182dd 100644 (file)
@@ -122,13 +122,15 @@ void prune_map(void)
     int start_line = map -> line;
 
     current_map_size = 0;
-    for(; map != 0; map = map -> previous) {
+    do {
         current_map_size++;
         if (map -> line < start_line - LINES && map -> previous != 0) {
             map -> previous = map -> previous -> previous;
         }
-    }
+        map = map -> previous;
+    } while (map != 0);
 }
+
 /* Add mapping entry */
 void add_map(int line, size_t pos)
 {
@@ -206,7 +208,9 @@ void replace_line(int i, CORD s)
 {
     register int c;
     CORD_pos p;
-    size_t len = CORD_len(s);
+#   if !defined(MACINTOSH)
+        size_t len = CORD_len(s);
+#   endif
 
     if (screen == 0 || LINES > screen_size) {
         screen_size = LINES;
@@ -215,7 +219,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) {
-            s = CORD_substr(s, 0, CORD_len(s) - 1);
+            s = CORD_substr(s, 0, len - 1);
         }
 #   endif
     if (CORD_cmp(screen[i], s) != 0) {
index 1179b8f..f33a5f2 100644 (file)
@@ -260,7 +260,8 @@ LRESULT CALLBACK WndProc (HWND hwnd, UINT message,
                unsigned xpos = LOWORD(lParam);  /* From left    */
                unsigned ypos = HIWORD(lParam);  /* from top */
 
-               set_position( xpos/char_width, ypos/char_height );
+               set_position(xpos / (unsigned)char_width,
+                            ypos / (unsigned)char_height);
                return(0);
            }