From: Andre Noll Date: Sun, 16 Jun 2013 12:22:06 +0000 (+0200) Subject: gui: Fix off-by-one in add_spaces(). X-Git-Tag: v0.4.13~28 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=100600d8f23b5b1ef6bb78b64f9817733eb02441 gui: Fix off-by-one in add_spaces(). Commit e90c6c0a (Speed up add_spaces().) changed add_spaces() to print space characters in chunks rather than one at a time. It introduced space[], an array of whitespace characters, which is written entirely if there are more spaces to print than the size of the array. However, in the calculation of how much was printed so far, we missed the fact that sizeof(space) includes the terminating NULL byte, so this number is in fact the number of space characters *plus one*. Consequently, we printed too few space characters. This resulted in parts of the previous string still being visible in the top window of para_gui. --- diff --git a/gui.c b/gui.c index 096beb93..0361347e 100644 --- a/gui.c +++ b/gui.c @@ -293,7 +293,7 @@ static char *configfile_exists(void) static void add_spaces(WINDOW* win, unsigned int num) { char space[] = " "; - unsigned sz = sizeof(space); + unsigned sz = sizeof(space) - 1; /* number of spaces */ while (num >= sz) { waddstr(win, space);