Convert DetermineClientCmd to use strdup instead of malloc+strncpy

*cmdname is initialized to NULL earlier in the function, so it's
okay to overwrite it with NULL if strdup fails, don't need that
extra check.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Jeremy Huddleston <jeremyhu@apple.com>
This commit is contained in:
Alan Coopersmith 2011-10-28 21:29:50 -07:00
parent 03ddca6f71
commit 780133f9ae

View File

@ -149,13 +149,7 @@ void DetermineClientCmd(pid_t pid, const char **cmdname, const char **cmdargs)
cmdsize = strlen(path) + 1;
if (cmdname)
{
char *name = malloc(cmdsize);
if (name)
{
strncpy(name, path, cmdsize);
name[cmdsize - 1] = '\0';
*cmdname = name;
}
*cmdname = strdup(path);
}
/* Construct the arguments for client process. */