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 |
1.1 --- a/src/game.c Mon Apr 07 17:39:46 2014 +0200 1.2 +++ b/src/game.c Tue Apr 08 21:13:28 2014 +0200 1.3 @@ -154,6 +154,7 @@ 1.4 1.5 const size_t buflen = 8; 1.6 char movestr[buflen]; 1.7 + movestr[0] = '\0'; 1.8 1.9 int inputy = getmaxy(stdscr) - 6; 1.10 while (1) { 1.11 @@ -205,6 +206,7 @@ 1.12 } 1.13 clrtoeol(); 1.14 } 1.15 + movestr[0] = '\0'; /* reset string for next input */ 1.16 } 1.17 } 1.18 }
2.1 --- a/src/input.c Mon Apr 07 17:39:46 2014 +0200 2.2 +++ b/src/input.c Tue Apr 08 21:13:28 2014 +0200 2.3 @@ -28,6 +28,7 @@ 2.4 */ 2.5 2.6 #include "input.h" 2.7 +#include <ctype.h> 2.8 2.9 void init_colorpairs() { 2.10 init_pair(COL_YB, COLOR_YELLOW, COLOR_BLUE); 2.11 @@ -70,6 +71,7 @@ 2.12 static size_t pos = 0; 2.13 2.14 if (*str == '\0') { 2.15 + memset(str, 0, len); 2.16 pos = 0; 2.17 } 2.18 2.19 @@ -88,7 +90,7 @@ 2.20 str[--pos] = '\0'; 2.21 break; 2.22 default: 2.23 - if (c < 255 && pos < len-1) { 2.24 + if (isprint(c) && pos < len-1) { 2.25 str[pos++] = (char) c; 2.26 } 2.27 }
3.1 --- a/src/main.c Mon Apr 07 17:39:46 2014 +0200 3.2 +++ b/src/main.c Tue Apr 08 21:13:28 2014 +0200 3.3 @@ -40,7 +40,7 @@ 3.4 uint8_t timeunit = 60; 3.5 size_t len; 3.6 3.7 - for (char opt ; (opt = getopt(argc, argv, "a:bhp:rst:")) != -1 ;) { 3.8 + for (int opt ; (opt = getopt(argc, argv, "a:bhp:rst:")) != -1 ;) { 3.9 switch (opt) { 3.10 case 'b': 3.11 settings->gameinfo.servercolor = BLACK;