diff options
| author | raysan5 <raysan5@gmail.com> | 2016-07-06 20:02:15 +0200 |
|---|---|---|
| committer | raysan5 <raysan5@gmail.com> | 2016-07-06 20:02:15 +0200 |
| commit | 8fd450784799d553a649a69df92497d32415140b (patch) | |
| tree | 9b684739cbc7c37b69f382c66e2333ec12397eaa /src | |
| parent | 09cc27ca7a6d29434bd5f6274788d5a6a8de4ad6 (diff) | |
| download | raylib-8fd450784799d553a649a69df92497d32415140b.tar.gz raylib-8fd450784799d553a649a69df92497d32415140b.zip | |
Corrected bug on Raspberry Pi with strcat()
Diffstat (limited to 'src')
| -rw-r--r-- | src/text.c | 17 |
1 files changed, 10 insertions, 7 deletions
@@ -782,12 +782,15 @@ static SpriteFont LoadBMFont(const char *fileName) char *texPath = NULL; char *lastSlash = NULL; - lastSlash = strrchr(fileName, '/'); // you need escape character - texPath = malloc(strlen(fileName) - strlen(lastSlash) + 1 + strlen(texFileName) + 1); - memcpy(texPath, fileName, strlen(fileName) - strlen(lastSlash)); - strcat(texPath, "/"); - strcat(texPath, texFileName); - strcat(texPath, "\0"); + lastSlash = strrchr(fileName, '/'); + + // NOTE: We need some extra space to avoid memory corruption on next allocations! + texPath = malloc(strlen(fileName) - strlen(lastSlash) + strlen(texFileName) + 4); + + // NOTE: strcat() and strncat() required a '\0' terminated string to work! + *texPath = '\0'; + strncat(texPath, fileName, strlen(fileName) - strlen(lastSlash) + 1); + strncat(texPath, texFileName, strlen(texFileName)); TraceLog(DEBUG, "[%s] Font texture loading path: %s", fileName, texPath); @@ -828,7 +831,7 @@ static SpriteFont LoadBMFont(const char *fileName) else if (unorderedChars) TraceLog(WARNING, "BMFont not supported: unordered chars data, falling back to default font"); // NOTE: Font data could be not ordered by charId: 32,33,34,35... raylib does not support unordered BMFonts - if ((firstChar != FONT_FIRST_CHAR) || (unorderedChars)) + if ((firstChar != FONT_FIRST_CHAR) || (unorderedChars) || (font.texture.id == 0)) { UnloadSpriteFont(font); font = GetDefaultFont(); |
