aboutsummaryrefslogtreecommitdiff
path: root/src/text.c
diff options
context:
space:
mode:
authorRay <raysan5@gmail.com>2016-07-15 19:44:18 +0200
committerGitHub <noreply@github.com>2016-07-15 19:44:18 +0200
commita2794379a0e1e2ab1486888aaa710f65d492e0fc (patch)
treeacd8185cf8574ccba8fab46ccdbca30f9a3cd895 /src/text.c
parent1c98e6b698b8002e0c6c769c6d9f23a6e15f3bdf (diff)
parentfc19e24eba4358b3afb052f80425af4947b172d6 (diff)
downloadraylib-a2794379a0e1e2ab1486888aaa710f65d492e0fc.tar.gz
raylib-a2794379a0e1e2ab1486888aaa710f65d492e0fc.zip
Merge pull request #132 from raysan5/develop
Develop branch integration
Diffstat (limited to 'src/text.c')
-rw-r--r--src/text.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/text.c b/src/text.c
index b5f7ad0c..ec2480e3 100644
--- a/src/text.c
+++ b/src/text.c
@@ -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();