Don't need to use strlen() to determine if there's text.
authorSam Lantinga <slouken@libsdl.org>
Sun, 22 Aug 2010 11:56:07 -0700
changeset 463808d22c54a21f
parent 4637 8c229370ddba
child 4694 c24ba2cc9583
Don't need to use strlen() to determine if there's text.
Use the SDL safe strcpy() function
test/testime.c
     1.1 --- a/test/testime.c	Thu Aug 12 16:00:47 2010 +0200
     1.2 +++ b/test/testime.c	Sun Aug 22 11:56:07 2010 -0700
     1.3 @@ -136,7 +136,7 @@
     1.4                          int x, int y,
     1.5                          SDL_Color color)
     1.6  {
     1.7 -    if (text && strlen(text)) {
     1.8 +    if (text && *text) {
     1.9          SDL_Surface *textSur = TTF_RenderUTF8_Blended(font, text, color);
    1.10          SDL_Rect dest = { x, y, textSur->w, textSur->h };
    1.11  
    1.12 @@ -154,7 +154,7 @@
    1.13      SDL_FillRect(screen, &textRect, backColor);
    1.14  
    1.15  #ifdef HAVE_SDL_TTF
    1.16 -    if (strlen(text))
    1.17 +    if (*text)
    1.18      {
    1.19          RenderText(screen, font, text, textRect.x, textRect.y, textColor);
    1.20          TTF_SizeUTF8(font, text, &w, &h);
    1.21 @@ -295,7 +295,7 @@
    1.22              fprintf(stderr, "Keyboard: text input \"%s\"\n", event.text.text);
    1.23  
    1.24              if (SDL_strlen(text) + SDL_strlen(event.text.text) < sizeof(text))
    1.25 -                strcpy(text + SDL_strlen(text), event.text.text);
    1.26 +                SDL_strlcpy(text + SDL_strlen(text), event.text.text, sizeof(text));
    1.27  
    1.28              fprintf(stderr, "text inputed: %s\n", text);
    1.29