summaryrefslogtreecommitdiffstats
path: root/daemon/xfs.c
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-09-15 13:19:12 +0100
committerRichard W.M. Jones <rjones@redhat.com>2012-09-15 13:19:12 +0100
commitd26f40236196eb2cdf81fa62cbfa28ca89623b28 (patch)
tree595ae18daeec0b1c495a643063029233a7b36f2d /daemon/xfs.c
parentb0cefb417d01c6dcb87cc6bafe9c19b98c690c9d (diff)
downloadlibguestfs-d26f40236196eb2cdf81fa62cbfa28ca89623b28.tar.gz
libguestfs-d26f40236196eb2cdf81fa62cbfa28ca89623b28.tar.xz
libguestfs-d26f40236196eb2cdf81fa62cbfa28ca89623b28.zip
syntax: xfs: Rewrite split_strdup function to avoid use of strncpy.
Found by 'make syntax-check'.
Diffstat (limited to 'daemon/xfs.c')
-rw-r--r--daemon/xfs.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/daemon/xfs.c b/daemon/xfs.c
index 13ccb11d..e92df62d 100644
--- a/daemon/xfs.c
+++ b/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;
}