diff --git a/src/OpenFontRender.cpp b/src/OpenFontRender.cpp index c1aa413..3acc397 100644 --- a/src/OpenFontRender.cpp +++ b/src/OpenFontRender.cpp @@ -440,11 +440,11 @@ FT_Error OpenFontRender::loadFont(const unsigned char *data, size_t size, uint8_ * @note Any better solutions are welcome. */ FT_Error OpenFontRender::loadFont(const char *fpath, uint8_t target_face_index) { - size_t len = strlen(fpath); + size_t len = strlen(fpath) + 1; // +1 is for NULL character because strlen do not include NULL character - _face_id.filepath = new char[len + 1]; // Release on unloadFont method + _face_id.filepath = new char[len](); // Release on unloadFont method strncpy(_face_id.filepath, fpath, len); - _face_id.filepath[len] = '\0'; + _face_id.filepath[len - 1] = '\0'; // Not required but explicitly stated. _face_id.face_index = target_face_index; return loadFont(OFR::FROM_FILE);