diff --git a/src/opengl.c b/src/opengl.c index c83ce34..28052f4 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -562,7 +562,7 @@ glx_init_blur(session_t *ps) { const char *texture_func = (use_texture_rect ? "texture2DRect": "texture2D"); const char *shader_add = FRAG_SHADER_BLUR_ADD; - char *extension = strdup(""); + char *extension = NULL; if (use_texture_rect) mstrextend(&extension, "#extension GL_ARB_texture_rectangle : require\n"); if (ps->o.glx_use_gpushader4) { diff --git a/src/string_utils.c b/src/string_utils.c index 064db9c..df0ac8d 100644 --- a/src/string_utils.c +++ b/src/string_utils.c @@ -11,33 +11,32 @@ * Allocate the space and join two strings. */ char *mstrjoin(const char *src1, const char *src2) { - auto str = ccalloc(strlen(src1)+strlen(src2)+1, char); + auto len1 = strlen(src1); + auto len2 = strlen(src2); + auto len = len1 + len2 + 1; + auto str = ccalloc(len, char); - strcpy(str, src1); - strcat(str, src2); + strncpy(str, src1, len1); + strncpy(str + len1, src2, len2); + str[len - 1] = '\0'; - return str; -} - -/** - * Allocate the space and join two strings; - */ -char * -mstrjoin3(const char *src1, const char *src2, const char *src3) { - auto str = ccalloc(strlen(src1)+strlen(src2)+strlen(src3)+1, char); - - strcpy(str, src1); - strcat(str, src2); - strcat(str, src3); - - return str; + return str; } /** * Concatenate a string on heap with another string. */ void mstrextend(char **psrc1, const char *src2) { - *psrc1 = crealloc(*psrc1, (*psrc1 ? strlen(*psrc1) : 0)+strlen(src2)+1); + if (!*psrc1) { + *psrc1 = strdup(src2); + return; + } - strcat(*psrc1, src2); + auto len1 = strlen(*psrc1); + auto len2 = strlen(src2); + auto len = len1 + len2 + 1; + *psrc1 = crealloc(*psrc1, len); + + strncpy(*psrc1 + len1, src2, len2); + (*psrc1)[len - 1] = '\0'; }