diff --git a/test/testime.c b/test/testime.c index b5a901efae..972774961d 100644 --- a/test/testime.c +++ b/test/testime.c @@ -21,7 +21,10 @@ #include #include "testutils.h" +#ifdef HAVE_SDL_TTF #define DEFAULT_PTSIZE 30 +#endif + #ifdef HAVE_SDL_TTF #ifdef __MACOS__ #define DEFAULT_FONT "/System/Library/Fonts/华文细黑.ttf" @@ -56,7 +59,7 @@ static TTF_Font *font; #define UNIFONT_TEXTURE_SIZE (UNIFONT_TEXTURE_WIDTH * UNIFONT_TEXTURE_WIDTH * 4) #define UNIFONT_TEXTURE_PITCH (UNIFONT_TEXTURE_WIDTH * 4) #define UNIFONT_DRAW_SCALE 2 -struct UnifontGlyph +static struct UnifontGlyph { Uint8 width; Uint8 data[32]; @@ -104,7 +107,7 @@ static int unifont_init(const char *fontname) Uint8 hexBuffer[65]; Uint32 numGlyphs = 0; int lineNumber = 1; - size_t bytesRead; + Sint64 bytesRead; SDL_RWops *hexFile; const size_t unifontGlyphSize = UNIFONT_NUM_GLYPHS * sizeof(struct UnifontGlyph); const size_t unifontTextureSize = UNIFONT_NUM_TEXTURES * state->num_windows * sizeof(void *); @@ -141,11 +144,16 @@ static int unifont_init(const char *fontname) /* Read all the glyph data into memory to make it accessible later when textures are created. */ do { int i, codepointHexSize; - size_t bytesOverread; + Sint64 bytesOverread; Uint8 glyphWidth; Uint32 codepoint; - bytesRead = (size_t)SDL_RWread(hexFile, hexBuffer, 9); + bytesRead = SDL_RWread(hexFile, hexBuffer, 9); + if (bytesRead < 0) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "error SDL_RWread\n"); + return -1; + } + if (numGlyphs > 0 && bytesRead == 0) { break; /* EOF */ } @@ -181,7 +189,13 @@ static int unifont_init(const char *fontname) if (codepointHexSize < 8) { SDL_memmove(hexBuffer, hexBuffer + codepointHexSize + 1, bytesOverread); } - bytesRead = (size_t)SDL_RWread(hexFile, hexBuffer + bytesOverread, 33 - bytesOverread); + bytesRead = SDL_RWread(hexFile, hexBuffer + bytesOverread, 33 - bytesOverread); + if (bytesRead < 0) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "error SDL_RWread\n"); + return -1; + } + + if (bytesRead < (33 - bytesOverread)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Unexpected end of hex file.\n"); return -1; @@ -190,7 +204,12 @@ static int unifont_init(const char *fontname) glyphWidth = 8; } else { glyphWidth = 16; - bytesRead = (size_t)SDL_RWread(hexFile, hexBuffer + 33, 32); + bytesRead = SDL_RWread(hexFile, hexBuffer + 33, 32); + if (bytesRead < 0) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "error SDL_RWread\n"); + return -1; + } + if (bytesRead < 32) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Unexpected end of hex file.\n"); return -1; @@ -329,7 +348,7 @@ static Sint32 unifont_draw_glyph(Uint32 codepoint, int rendererID, SDL_Rect *dst return unifontGlyph[codepoint].width; } -static void unifont_cleanup() +static void unifont_cleanup(void) { int i, j; for (i = 0; i < state->num_windows; ++i) { @@ -356,7 +375,7 @@ static void unifont_cleanup() /* Unifont code end */ #endif -size_t utf8_length(unsigned char c) +static size_t utf8_length(unsigned char c) { c = (unsigned char)(0xff & c); if (c < 0x80) { @@ -371,7 +390,8 @@ size_t utf8_length(unsigned char c) return 0; } -char *utf8_next(char *p) +#ifdef HAVE_SDL_TTF +static char *utf8_next(char *p) { size_t len = utf8_length(*p); size_t i = 0; @@ -388,7 +408,8 @@ char *utf8_next(char *p) return p; } -char *utf8_advance(char *p, size_t distance) + +static char *utf8_advance(char *p, size_t distance) { size_t i = 0; for (; i < distance && p; ++i) { @@ -396,8 +417,9 @@ char *utf8_advance(char *p, size_t distance) } return p; } +#endif -Uint32 utf8_decode(char *p, size_t len) +static Uint32 utf8_decode(char *p, size_t len) { Uint32 codepoint = 0; size_t i = 0; @@ -421,12 +443,12 @@ Uint32 utf8_decode(char *p, size_t len) return codepoint; } -void usage() +static void usage(void) { SDL_Log("usage: testime [--font fontfile]\n"); } -void InitInput() +static void InitInput(void) { /* Prepare a rect for text input */ textRect.x = textRect.y = 100; @@ -440,7 +462,7 @@ void InitInput() SDL_StartTextInput(); } -void CleanupVideo() +static void CleanupVideo(void) { SDL_StopTextInput(); #ifdef HAVE_SDL_TTF @@ -451,7 +473,7 @@ void CleanupVideo() #endif } -void _Redraw(int rendererID) +static void _Redraw(int rendererID) { SDL_Renderer *renderer = state->renderers[rendererID]; SDL_Rect drawnTextRect, cursorRect, underlineRect; @@ -593,7 +615,7 @@ void _Redraw(int rendererID) SDL_SetTextInputRect(&markedRect); } -void Redraw() +static void Redraw(void) { int i; for (i = 0; i < state->num_windows; ++i) {