[PATCH 4/5] Convert DetermineClientCmd to use strdup instead of malloc+strncpy

Alan Coopersmith alan.coopersmith at oracle.com
Fri Oct 28 21:41:52 PDT 2011


*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 at oracle.com>
---
 os/client.c |    8 +-------
 1 files changed, 1 insertions(+), 7 deletions(-)

diff --git a/os/client.c b/os/client.c
index b534977..4aec097 100644
--- a/os/client.c
+++ b/os/client.c
@@ -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. */
-- 
1.7.3.2



More information about the xorg-devel mailing list