]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
gui: Fix off-by-one in add_spaces().
authorAndre Noll <maan@systemlinux.org>
Sun, 16 Jun 2013 12:22:06 +0000 (14:22 +0200)
committerAndre Noll <maan@systemlinux.org>
Sun, 16 Jun 2013 12:22:06 +0000 (14:22 +0200)
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.

gui.c

diff --git a/gui.c b/gui.c
index 096beb93bfd82f91a68c454779edaa6c59e8a565..0361347e54375b18165a16f7d8dc747499561a6b 100644 (file)
--- 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);