Changed markedText to have its own storage to resolve multiple bugs.
authordewyatt
Sat, 24 Jul 2010 20:48:50 -0400
changeset 4756 b99b1024607a
parent 4755 436183eb30c8
child 4757 140be6839185
Changed markedText to have its own storage to resolve multiple bugs. Changed an odd strcpy to a more appropriate strcat.
test/testime.c
--- a/test/testime.c	Sun Jul 18 13:48:23 2010 -0400
+++ b/test/testime.c	Sat Jul 24 20:48:50 2010 -0400
@@ -25,7 +25,7 @@
 SDL_Rect textRect, markedRect;
 Uint32 lineColor, backColor;
 SDL_Color textColor = { 0, 0, 0 };
-char text[MAX_TEXT_LENGTH], *markedText;
+char text[MAX_TEXT_LENGTH], markedText[SDL_TEXTEDITINGEVENT_TEXT_SIZE];
 
 void usage()
 {
@@ -124,7 +124,7 @@
 
     text[0] = 0;
     markedRect = textRect;
-    markedText = NULL;
+    markedText[0] = 0;
 
     SDL_StartTextInput();
 }
@@ -178,7 +178,7 @@
     cursorRect.h = h;
 
     SDL_FillRect(screen, &markedRect, backColor);
-    if (markedText)
+    if (markedText[0])
     {
 #ifdef HAVE_SDL_TTF
         RenderText(screen, font, markedText, markedRect.x, markedRect.y, textColor);
@@ -293,13 +293,13 @@
             fprintf(stderr, "Keyboard: text input \"%s\"\n", event.text.text);
 
             if (SDL_strlen(text) + SDL_strlen(event.text.text) < sizeof(text))
-                strcpy(text + SDL_strlen(text), event.text.text);
+                strcat(text, event.text.text);
 
             fprintf(stderr, "text inputed: %s\n", text);
 
             // After text inputed, we can clear up markedText because it
             // is committed
-            markedText = NULL;
+            markedText[0] = 0;
             Redraw();
             break;
 
@@ -307,7 +307,7 @@
             fprintf(stderr, "text editing \"%s\", selected range (%d, %d)\n",
                     event.edit.text, event.edit.start, event.edit.length);
 
-            markedText = event.edit.text;
+            strcpy(markedText, event.edit.text);
             Redraw();
             break;