Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Replace strndup(3) usage with malloc + strncpy

strndup(3) wasn't standardized until POSIX.1-2008, and (more concretely)
isn't available in OS X 10.5 Leopard.

Reported by Samuel Bronson.
  • Loading branch information...
commit a3079e26a34ee79ed3dce05dcdbe6f0bfdc4cd59 1 parent 756724a
@jonas jonas authored
Showing with 8 additions and 4 deletions.
  1. +8 −4 io.c
View
12 io.c
@@ -151,15 +151,19 @@ argv_remove_quotes(const char *argv[])
char quoted = 0;
const char *arg = argv[argc];
int arglen = get_arg_valuelen(arg, &quoted);
+ int unquotedlen = arglen - 1 - (arg[arglen - 1] == quoted);
+ char *unquoted;
if (!quoted)
continue;
- arg = strndup(arg + 1, arglen - 1 - (arg[arglen - 1] == quoted));
- if (!arg)
+ unquoted = malloc(unquotedlen + 1);
+ if (!unquoted)
return FALSE;
- free((void *) argv[argc]);
- argv[argc] = arg;
+ strncpy(unquoted, arg + 1, unquotedlen);
+ unquoted[unquotedlen] = 0;
+ free((void *) arg);
+ argv[argc] = unquoted;
}
return TRUE;
Please sign in to comment.
Something went wrong with that request. Please try again.