From 6af4254868e50fc3a44720e494041adc12ba2840 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Sat, 14 Jun 2014 20:30:42 +0400 Subject: [PATCH] Eliminate warnings detected by Cppcheck in cord de[_win] * 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 | 12 ++++++++---- cord/tests/de_win.c | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/cord/tests/de.c b/cord/tests/de.c index 068848c4..5f0508b7 100644 --- a/cord/tests/de.c +++ b/cord/tests/de.c @@ -122,13 +122,15 @@ void prune_map() 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) { diff --git a/cord/tests/de_win.c b/cord/tests/de_win.c index 9f39cad3..84a5bc70 100644 --- a/cord/tests/de_win.c +++ b/cord/tests/de_win.c @@ -261,7 +261,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); } -- 2.40.0