Tue, 08 Apr 2014 21:13:28 +0200
fixed some type bugs, uninitialized memory and async input function
src/game.c | file | annotate | diff | comparison | revisions | |
src/input.c | file | annotate | diff | comparison | revisions | |
src/main.c | file | annotate | diff | comparison | revisions |
--- a/src/game.c Mon Apr 07 17:39:46 2014 +0200 +++ b/src/game.c Tue Apr 08 21:13:28 2014 +0200 @@ -154,6 +154,7 @@ const size_t buflen = 8; char movestr[buflen]; + movestr[0] = '\0'; int inputy = getmaxy(stdscr) - 6; while (1) { @@ -205,6 +206,7 @@ } clrtoeol(); } + movestr[0] = '\0'; /* reset string for next input */ } } }
--- a/src/input.c Mon Apr 07 17:39:46 2014 +0200 +++ b/src/input.c Tue Apr 08 21:13:28 2014 +0200 @@ -28,6 +28,7 @@ */ #include "input.h" +#include <ctype.h> void init_colorpairs() { init_pair(COL_YB, COLOR_YELLOW, COLOR_BLUE); @@ -70,6 +71,7 @@ static size_t pos = 0; if (*str == '\0') { + memset(str, 0, len); pos = 0; } @@ -88,7 +90,7 @@ str[--pos] = '\0'; break; default: - if (c < 255 && pos < len-1) { + if (isprint(c) && pos < len-1) { str[pos++] = (char) c; } }
--- a/src/main.c Mon Apr 07 17:39:46 2014 +0200 +++ b/src/main.c Tue Apr 08 21:13:28 2014 +0200 @@ -40,7 +40,7 @@ uint8_t timeunit = 60; size_t len; - for (char opt ; (opt = getopt(argc, argv, "a:bhp:rst:")) != -1 ;) { + for (int opt ; (opt = getopt(argc, argv, "a:bhp:rst:")) != -1 ;) { switch (opt) { case 'b': settings->gameinfo.servercolor = BLACK;