Commit 9b8ec5c6 authored by Sam Lantinga's avatar Sam Lantinga

Don't need to use strlen() to determine if there's text.

Use the SDL safe strcpy() function
parent 43cd4e54
...@@ -136,7 +136,7 @@ static void RenderText(SDL_Surface *sur, ...@@ -136,7 +136,7 @@ static void RenderText(SDL_Surface *sur,
int x, int y, int x, int y,
SDL_Color color) SDL_Color color)
{ {
if (text && strlen(text)) { if (text && *text) {
SDL_Surface *textSur = TTF_RenderUTF8_Blended(font, text, color); SDL_Surface *textSur = TTF_RenderUTF8_Blended(font, text, color);
SDL_Rect dest = { x, y, textSur->w, textSur->h }; SDL_Rect dest = { x, y, textSur->w, textSur->h };
...@@ -154,7 +154,7 @@ void Redraw() ...@@ -154,7 +154,7 @@ void Redraw()
SDL_FillRect(screen, &textRect, backColor); SDL_FillRect(screen, &textRect, backColor);
#ifdef HAVE_SDL_TTF #ifdef HAVE_SDL_TTF
if (strlen(text)) if (*text)
{ {
RenderText(screen, font, text, textRect.x, textRect.y, textColor); RenderText(screen, font, text, textRect.x, textRect.y, textColor);
TTF_SizeUTF8(font, text, &w, &h); TTF_SizeUTF8(font, text, &w, &h);
...@@ -295,7 +295,7 @@ int main(int argc, char *argv[]) ...@@ -295,7 +295,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "Keyboard: text input \"%s\"\n", event.text.text); fprintf(stderr, "Keyboard: text input \"%s\"\n", event.text.text);
if (SDL_strlen(text) + SDL_strlen(event.text.text) < sizeof(text)) if (SDL_strlen(text) + SDL_strlen(event.text.text) < sizeof(text))
strcpy(text + SDL_strlen(text), event.text.text); SDL_strlcpy(text + SDL_strlen(text), event.text.text, sizeof(text));
fprintf(stderr, "text inputed: %s\n", text); fprintf(stderr, "text inputed: %s\n", text);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment