🐞 fix(module manager): fix strncpy cppcheck warning

This commit is contained in:
yangwei
2024-09-14 17:41:07 +08:00
parent 7305c64a8c
commit 340c8a1054

View File

@@ -213,7 +213,7 @@ struct stellar_module *stellar_module_manager_get_module(struct stellar_module_m
struct stellar_module *stellar_module_new(const char *name) struct stellar_module *stellar_module_new(const char *name)
{ {
struct stellar_module *mod = CALLOC(struct stellar_module, 1); struct stellar_module *mod = CALLOC(struct stellar_module, 1);
strncpy(mod->name, name, NAME_MAX); memcpy(mod->name, name, MIN(NAME_MAX, strlen(name)));
return mod; return mod;
} }
@@ -246,6 +246,6 @@ const char *stellar_module_get_name(struct stellar_module* mod)
void stellar_module_set_name(struct stellar_module* mod, const char *name) void stellar_module_set_name(struct stellar_module* mod, const char *name)
{ {
if(mod==NULL)return; if(mod==NULL)return;
strncpy(mod->name, name, NAME_MAX); memcpy(mod->name, name, MIN(NAME_MAX, strlen(name)));
return; return;
} }