summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/irmd/utils.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/irmd/utils.c b/src/irmd/utils.c
index 976dcfa2..fade2bee 100644
--- a/src/irmd/utils.c
+++ b/src/irmd/utils.c
@@ -39,9 +39,9 @@ void argvfree(char ** argv)
char ** argvdup(char ** argv)
{
- int argc = 0;
+ int argc = 0;
char ** argv_dup = argv;
- int i;
+ int i;
if (argv == NULL)
return NULL;
@@ -49,16 +49,18 @@ char ** argvdup(char ** argv)
while (*(argv_dup++) != NULL)
argc++;
- if (argc != 0) {
- argv_dup = malloc((argc + 1) * sizeof(*argv_dup));
- for (i = 0; i < argc; ++i) {
- argv_dup[i] = strdup(argv[i]);
- if (argv_dup[i] == NULL) {
- argvfree(argv_dup);
- return NULL;
- }
+ argv_dup = malloc((argc + 1) * sizeof(*argv_dup));
+ if (argv_dup == NULL)
+ return NULL;
+
+ for (i = 0; i < argc; ++i) {
+ argv_dup[i] = strdup(argv[i]);
+ if (argv_dup[i] == NULL) {
+ argvfree(argv_dup);
+ return NULL;
}
}
+
argv_dup[argc] = NULL;
return argv_dup;
}