diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2013-06-12 22:42:53 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2013-06-12 22:42:53 +0000 |
commit | 263f056b32fc1c2240f42baf1077de2de0379ad3 (patch) | |
tree | 9f85e9ddaa64ad42722a2d3ef28c60182e87c04d /lib/libfuse/fuse_opt.c | |
parent | 6f81aee6d70b6385520cab0030f2bfec157a2ca0 (diff) |
correct realloc usage
Diffstat (limited to 'lib/libfuse/fuse_opt.c')
-rw-r--r-- | lib/libfuse/fuse_opt.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/lib/libfuse/fuse_opt.c b/lib/libfuse/fuse_opt.c index fbc1a0de2ed..352a094c704 100644 --- a/lib/libfuse/fuse_opt.c +++ b/lib/libfuse/fuse_opt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fuse_opt.c,v 1.2 2013/06/12 22:38:08 tedu Exp $ */ +/* $OpenBSD: fuse_opt.c,v 1.3 2013/06/12 22:42:52 tedu Exp $ */ /* * Copyright (c) 2013 Sylvestre Gallon <ccna.syl@gmail.com> * @@ -47,13 +47,13 @@ fuse_opt_add_arg(struct fuse_args *args, const char *name) args->argc++; args->argv = av; args->allocated = 1; - } else { - args->argc++; - args->argv = realloc(args->argv, args->argc * sizeof(*av)); - if (args->argv == NULL) + av = realloc(args->argv, (args->argc + 1) * sizeof(*av)); + if (av == NULL) return (-1); + args->argv = av; + args->argc++; args->argv[args->argc - 1] = strdup(name); if (args->argv[args->argc - 1] == NULL) return (-1); @@ -117,17 +117,19 @@ fuse_opt_parse(struct fuse_args *args, void *data, struct fuse_opt *opt, int fuse_opt_insert_arg(struct fuse_args *args, int p, const char *arg) { + char **av; int i; if (p > args->argc + 1) return -1; if (args->allocated) { - args->argc++; - args->argv = realloc(args->argv, (args->argc) * sizeof(char *)); - if (args->argv == NULL) + av = realloc(args->argv, (args->argc + 1) * sizeof(char *)); + if (av == NULL) return (-1); + args->argv = av; + args->argc++; for (i = args->argc - 1 ; i > p ; i++) args->argv[i] = args->argv[i - 1]; |