Replace mstrcpy, mstrncpy with strdup, strndup
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
parent
b8912fa749
commit
b73dce1d6d
12
src/c2.c
12
src/c2.c
|
@ -632,7 +632,7 @@ c2_parse_target(session_t *ps, const char *pattern, int offset, c2_ptr_t *presul
|
||||||
}
|
}
|
||||||
if (!tgtlen)
|
if (!tgtlen)
|
||||||
c2_error("Empty target.");
|
c2_error("Empty target.");
|
||||||
pleaf->tgt = mstrncpy(&pattern[offset - tgtlen], tgtlen);
|
pleaf->tgt = strndup(&pattern[offset - tgtlen], tgtlen);
|
||||||
|
|
||||||
// Check for predefined targets
|
// Check for predefined targets
|
||||||
for (unsigned i = 1; i < sizeof(C2_PREDEFS) / sizeof(C2_PREDEFS[0]); ++i) {
|
for (unsigned i = 1; i < sizeof(C2_PREDEFS) / sizeof(C2_PREDEFS[0]); ++i) {
|
||||||
|
@ -657,7 +657,7 @@ c2_parse_target(session_t *ps, const char *pattern, int offset, c2_ptr_t *presul
|
||||||
|
|
||||||
// Alias for custom properties
|
// Alias for custom properties
|
||||||
#define TGTFILL(target, type, format) \
|
#define TGTFILL(target, type, format) \
|
||||||
(pleaf->target = mstrcpy(target), \
|
(pleaf->target = strdup(target), \
|
||||||
pleaf->type = type, \
|
pleaf->type = type, \
|
||||||
pleaf->format = format)
|
pleaf->format = format)
|
||||||
|
|
||||||
|
@ -939,7 +939,7 @@ c2_parse_pattern(session_t *ps, const char *pattern, int offset, c2_ptr_t *presu
|
||||||
case 'o':
|
case 'o':
|
||||||
case 'x':
|
case 'x':
|
||||||
{
|
{
|
||||||
char *tstr = mstrncpy(pattern + offset + 1, 2);
|
char *tstr = strndup(pattern + offset + 1, 2);
|
||||||
char *pstr = NULL;
|
char *pstr = NULL;
|
||||||
long val = strtol(tstr, &pstr,
|
long val = strtol(tstr, &pstr,
|
||||||
('o' == pattern[offset] ? 8: 16));
|
('o' == pattern[offset] ? 8: 16));
|
||||||
|
@ -962,7 +962,7 @@ c2_parse_pattern(session_t *ps, const char *pattern, int offset, c2_ptr_t *presu
|
||||||
c2_error("Premature end of pattern string.");
|
c2_error("Premature end of pattern string.");
|
||||||
++offset;
|
++offset;
|
||||||
*ptptnstr = '\0';
|
*ptptnstr = '\0';
|
||||||
pleaf->ptnstr = mstrcpy(tptnstr);
|
pleaf->ptnstr = strdup(tptnstr);
|
||||||
free(tptnstr);
|
free(tptnstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1055,7 +1055,7 @@ c2_parse_legacy(session_t *ps, const char *pattern, int offset, c2_ptr_t *presul
|
||||||
++offset;
|
++offset;
|
||||||
|
|
||||||
// Copy the pattern
|
// Copy the pattern
|
||||||
pleaf->ptnstr = mstrcpy(pattern + offset);
|
pleaf->ptnstr = strdup(pattern + offset);
|
||||||
|
|
||||||
if (!c2_l_postprocess(ps, pleaf))
|
if (!c2_l_postprocess(ps, pleaf))
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1483,7 +1483,7 @@ c2_match_once_leaf(session_t *ps, win *w, const c2_l_t *pleaf,
|
||||||
int nstr;
|
int nstr;
|
||||||
if (wid_get_text_prop(ps, wid, pleaf->tgtatom, &strlst,
|
if (wid_get_text_prop(ps, wid, pleaf->tgtatom, &strlst,
|
||||||
&nstr) && nstr > idx) {
|
&nstr) && nstr > idx) {
|
||||||
tgt_free = mstrcpy(strlst[idx]);
|
tgt_free = strdup(strlst[idx]);
|
||||||
tgt = tgt_free;
|
tgt = tgt_free;
|
||||||
}
|
}
|
||||||
if (strlst)
|
if (strlst)
|
||||||
|
|
|
@ -3932,9 +3932,9 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) {
|
||||||
while (-1 !=
|
while (-1 !=
|
||||||
(o = getopt_long(argc, argv, shortopts, longopts, &longopt_idx))) {
|
(o = getopt_long(argc, argv, shortopts, longopts, &longopt_idx))) {
|
||||||
if (256 == o)
|
if (256 == o)
|
||||||
ps->o.config_file = mstrcpy(optarg);
|
ps->o.config_file = strdup(optarg);
|
||||||
else if ('d' == o)
|
else if ('d' == o)
|
||||||
ps->o.display = mstrcpy(optarg);
|
ps->o.display = strdup(optarg);
|
||||||
else if ('S' == o)
|
else if ('S' == o)
|
||||||
ps->o.synchronize = true;
|
ps->o.synchronize = true;
|
||||||
else if (314 == o)
|
else if (314 == o)
|
||||||
|
@ -3957,7 +3957,7 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool shadow_enable = false, fading_enable = false;
|
bool shadow_enable = false, fading_enable = false;
|
||||||
char *lc_numeric_old = mstrcpy(setlocale(LC_NUMERIC, NULL));
|
char *lc_numeric_old = strdup(setlocale(LC_NUMERIC, NULL));
|
||||||
|
|
||||||
win_option_mask_t winopt_mask[NUM_WINTYPES] = {{0}};
|
win_option_mask_t winopt_mask[NUM_WINTYPES] = {{0}};
|
||||||
|
|
||||||
|
@ -4113,7 +4113,7 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) {
|
||||||
P_CASEBOOL(286, dbus);
|
P_CASEBOOL(286, dbus);
|
||||||
case 287:
|
case 287:
|
||||||
// --logpath
|
// --logpath
|
||||||
ps->o.logpath = mstrcpy(optarg);
|
ps->o.logpath = strdup(optarg);
|
||||||
break;
|
break;
|
||||||
case 288:
|
case 288:
|
||||||
// --invert-color-include
|
// --invert-color-include
|
||||||
|
@ -4188,7 +4188,7 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) {
|
||||||
P_CASELONG(309, unredir_if_possible_delay);
|
P_CASELONG(309, unredir_if_possible_delay);
|
||||||
case 310:
|
case 310:
|
||||||
// --write-pid-path
|
// --write-pid-path
|
||||||
ps->o.write_pid_path = mstrcpy(optarg);
|
ps->o.write_pid_path = strdup(optarg);
|
||||||
break;
|
break;
|
||||||
P_CASEBOOL(311, vsync_use_glfinish);
|
P_CASEBOOL(311, vsync_use_glfinish);
|
||||||
P_CASEBOOL(312, xrender_sync);
|
P_CASEBOOL(312, xrender_sync);
|
||||||
|
@ -4196,7 +4196,7 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) {
|
||||||
P_CASEBOOL(315, no_fading_destroyed_argb);
|
P_CASEBOOL(315, no_fading_destroyed_argb);
|
||||||
P_CASEBOOL(316, force_win_blend);
|
P_CASEBOOL(316, force_win_blend);
|
||||||
case 317:
|
case 317:
|
||||||
ps->o.glx_fshader_win_str = mstrcpy(optarg);
|
ps->o.glx_fshader_win_str = strdup(optarg);
|
||||||
printf_errf("(): --glx-fshader-win is being deprecated, and might be\n"
|
printf_errf("(): --glx-fshader-win is being deprecated, and might be\n"
|
||||||
" removed in the future. If you really need this feature, please report\n"
|
" removed in the future. If you really need this feature, please report\n"
|
||||||
"an issue to let us know\n");
|
"an issue to let us know\n");
|
||||||
|
@ -5300,7 +5300,7 @@ session_init(session_t *ps_old, int argc, char **argv) {
|
||||||
char *display_repr = DisplayString(ps->dpy);
|
char *display_repr = DisplayString(ps->dpy);
|
||||||
if (!display_repr)
|
if (!display_repr)
|
||||||
display_repr = "unknown";
|
display_repr = "unknown";
|
||||||
display_repr = mstrcpy(display_repr);
|
display_repr = strdup(display_repr);
|
||||||
|
|
||||||
// Convert all special characters in display_repr name to underscore
|
// Convert all special characters in display_repr name to underscore
|
||||||
{
|
{
|
||||||
|
|
|
@ -186,7 +186,7 @@ void parse_config_libconfig(session_t *ps, bool *shadow_enable,
|
||||||
{
|
{
|
||||||
// dirname() could modify the original string, thus we must pass a
|
// dirname() could modify the original string, thus we must pass a
|
||||||
// copy
|
// copy
|
||||||
char *path2 = mstrcpy(path);
|
char *path2 = strdup(path);
|
||||||
char *parent = dirname(path2);
|
char *parent = dirname(path2);
|
||||||
|
|
||||||
if (parent)
|
if (parent)
|
||||||
|
|
|
@ -516,7 +516,7 @@ glx_init_blur(session_t *ps) {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
char *lc_numeric_old = mstrcpy(setlocale(LC_NUMERIC, NULL));
|
char *lc_numeric_old = strdup(setlocale(LC_NUMERIC, NULL));
|
||||||
// Enforce LC_NUMERIC locale "C" here to make sure decimal point is sane
|
// Enforce LC_NUMERIC locale "C" here to make sure decimal point is sane
|
||||||
// Thanks to hiciu for reporting.
|
// Thanks to hiciu for reporting.
|
||||||
setlocale(LC_NUMERIC, "C");
|
setlocale(LC_NUMERIC, "C");
|
||||||
|
@ -546,7 +546,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 = mstrcpy("");
|
char *extension = strdup("");
|
||||||
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) {
|
||||||
|
|
|
@ -3,28 +3,6 @@
|
||||||
#include "compiler.h"
|
#include "compiler.h"
|
||||||
#include "string_utils.h"
|
#include "string_utils.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
/**
|
|
||||||
* Allocate the space and copy a string.
|
|
||||||
*/
|
|
||||||
char *mstrcpy(const char *src) {
|
|
||||||
auto str = ccalloc(strlen(src) + 1, char);
|
|
||||||
|
|
||||||
strcpy(str, src);
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Allocate the space and copy a string.
|
|
||||||
*/
|
|
||||||
char *mstrncpy(const char *src, unsigned len) {
|
|
||||||
auto str = ccalloc(len + 1, char);
|
|
||||||
|
|
||||||
strncpy(str, src, len);
|
|
||||||
str[len] = '\0';
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allocate the space and join two strings.
|
* Allocate the space and join two strings.
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
|
|
||||||
#define mstrncmp(s1, s2) strncmp((s1), (s2), strlen(s1))
|
#define mstrncmp(s1, s2) strncmp((s1), (s2), strlen(s1))
|
||||||
|
|
||||||
char *mstrcpy(const char *src);
|
|
||||||
char *mstrncpy(const char *src, unsigned len);
|
|
||||||
char *mstrjoin(const char *src1, const char *src2);
|
char *mstrjoin(const char *src1, const char *src2);
|
||||||
char *
|
char *
|
||||||
mstrjoin3(const char *src1, const char *src2, const char *src3);
|
mstrjoin3(const char *src1, const char *src2, const char *src3);
|
||||||
|
|
|
@ -194,7 +194,7 @@ int win_get_name(session_t *ps, win *w) {
|
||||||
if (!w->name || strcmp(w->name, strlst[0]) != 0) {
|
if (!w->name || strcmp(w->name, strlst[0]) != 0) {
|
||||||
ret = 1;
|
ret = 1;
|
||||||
free(w->name);
|
free(w->name);
|
||||||
w->name = mstrcpy(strlst[0]);
|
w->name = strdup(strlst[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
XFreeStringList(strlst);
|
XFreeStringList(strlst);
|
||||||
|
@ -217,7 +217,7 @@ int win_get_role(session_t *ps, win *w) {
|
||||||
if (!w->role || strcmp(w->role, strlst[0]) != 0) {
|
if (!w->role || strcmp(w->role, strlst[0]) != 0) {
|
||||||
ret = 1;
|
ret = 1;
|
||||||
free(w->role);
|
free(w->role);
|
||||||
w->role = mstrcpy(strlst[0]);
|
w->role = strdup(strlst[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
XFreeStringList(strlst);
|
XFreeStringList(strlst);
|
||||||
|
@ -1042,10 +1042,10 @@ bool win_get_class(session_t *ps, win *w) {
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Copy the strings if successful
|
// Copy the strings if successful
|
||||||
w->class_instance = mstrcpy(strlst[0]);
|
w->class_instance = strdup(strlst[0]);
|
||||||
|
|
||||||
if (nstr > 1)
|
if (nstr > 1)
|
||||||
w->class_general = mstrcpy(strlst[1]);
|
w->class_general = strdup(strlst[1]);
|
||||||
|
|
||||||
XFreeStringList(strlst);
|
XFreeStringList(strlst);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue