1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

commands: use dm_strncpy

Easier code using dm_strncpy() an dm_snprintf().
This commit is contained in:
Zdenek Kabelac 2017-02-17 09:59:29 +01:00
parent 80b717af0c
commit 582a272b3f

View File

@ -330,13 +330,13 @@ static char *split_line(char *buf, int *argc, char **argv, char sep)
static int val_str_to_num(char *str) static int val_str_to_num(char *str)
{ {
char name[32] = { 0 }; char name[32];
char *new; char *new;
int i; int i;
/* compare the name before any suffix like _new or _<lvtype> */ /* compare the name before any suffix like _new or _<lvtype> */
strncpy(name, str, 31); dm_strncpy(name, str, sizeof(name));
if ((new = strstr(name, "_"))) if ((new = strstr(name, "_")))
*new = '\0'; *new = '\0';
@ -757,12 +757,8 @@ static void append_oo_definition_line(struct command *cmd, const char *new_line)
cmd->cmd_flags |= CMD_FLAG_PARSE_ERROR; cmd->cmd_flags |= CMD_FLAG_PARSE_ERROR;
return; return;
} }
memset(line, 0, len);
strcat(line, old_line);
strcat(line, " ");
strcat(line, new_line);
(void) dm_snprintf(line, len, "%s %s", old_line, new_line);
dm_free(oo->line); dm_free(oo->line);
oo->line = line; oo->line = line;
} }
@ -778,8 +774,7 @@ static char *get_oo_line(const char *str)
char str2[OO_NAME_LEN]; char str2[OO_NAME_LEN];
int i; int i;
memset(str2, 0, sizeof(str2)); dm_strncpy(str2, str, sizeof(str2));
strncpy(str2, str, OO_NAME_LEN-1);
if ((end = strstr(str2, ":"))) if ((end = strstr(str2, ":")))
*end = '\0'; *end = '\0';
if ((end = strstr(str2, ","))) if ((end = strstr(str2, ",")))