Use strncpy for string_utils functions

Also removed mstrjoin3 since it's not used.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2019-01-30 00:12:12 +00:00
parent 9d64decf2a
commit f7d4dff099
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
2 changed files with 20 additions and 21 deletions

View File

@ -562,7 +562,7 @@ glx_init_blur(session_t *ps) {
const char *texture_func = (use_texture_rect ? const char *texture_func = (use_texture_rect ?
"texture2DRect": "texture2D"); "texture2DRect": "texture2D");
const char *shader_add = FRAG_SHADER_BLUR_ADD; const char *shader_add = FRAG_SHADER_BLUR_ADD;
char *extension = strdup(""); char *extension = NULL;
if (use_texture_rect) if (use_texture_rect)
mstrextend(&extension, "#extension GL_ARB_texture_rectangle : require\n"); mstrextend(&extension, "#extension GL_ARB_texture_rectangle : require\n");
if (ps->o.glx_use_gpushader4) { if (ps->o.glx_use_gpushader4) {

View File

@ -11,33 +11,32 @@
* Allocate the space and join two strings. * Allocate the space and join two strings.
*/ */
char *mstrjoin(const char *src1, const char *src2) { 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); strncpy(str, src1, len1);
strcat(str, src2); strncpy(str + len1, src2, len2);
str[len - 1] = '\0';
return str; 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;
} }
/** /**
* Concatenate a string on heap with another string. * Concatenate a string on heap with another string.
*/ */
void mstrextend(char **psrc1, const char *src2) { 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';
} }