mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
syntax: xfs: Rewrite split_strdup function to avoid use of strncpy.
Found by 'make syntax-check'.
This commit is contained in:
14
daemon/xfs.c
14
daemon/xfs.c
@@ -42,19 +42,21 @@ optgroup_xfs_available (void)
|
||||
return prog_exists (str_mkfs_xfs);
|
||||
}
|
||||
|
||||
/* Return everything up to the first comma or space in the input
|
||||
* string, strdup'ing the return value.
|
||||
*/
|
||||
static char *
|
||||
split_strdup (char *string)
|
||||
{
|
||||
char *end = string;
|
||||
while (*end != ' ' && *end != ',' && *end != '\0') end++;
|
||||
size_t len = end - string;
|
||||
char *ret = malloc (len + 1);
|
||||
size_t len;
|
||||
char *ret;
|
||||
|
||||
len = strcspn (string, " ,");
|
||||
ret = strndup (string, len);
|
||||
if (!ret) {
|
||||
reply_with_perror ("malloc");
|
||||
return NULL;
|
||||
}
|
||||
strncpy (ret, string, len);
|
||||
ret[len] = '\0';
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user