]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
msw! didn't allocate enough memory
authorewt <ewt>
Mon, 29 Oct 2001 23:09:48 +0000 (23:09 +0000)
committerewt <ewt>
Mon, 29 Oct 2001 23:09:48 +0000 (23:09 +0000)
textbox.c

index dc42dc558f77bc2ead32a6aee872e286fa929904..06fa47c754a513d294af8c70182828c3f19bbe4c 100644 (file)
--- a/textbox.c
+++ b/textbox.c
@@ -159,8 +159,8 @@ static void doReflow(const char * text, char ** resultPtr, int width,
     int kanji = 0;
 
     if (resultPtr) {
-       /* XXX I think this will work */
-       result = malloc(strlen(text) + (strlen(text) / width) + 2);
+       /* worst case is a \n after every character */
+       result = malloc((strlen(text) * 2) + 1);
        *result = '\0';
     }
     
@@ -227,6 +227,8 @@ static void doReflow(const char * text, char ** resultPtr, int width,
        }
     }
 
+    result = realloc(result, strlen(result) + 1);
+
     if (badness) *badness = howbad;
     if (resultPtr) *resultPtr = result;
     if (heightPtr) *heightPtr = height;