[PATCH 17/25] Convert KdDoSwitchCmd to use asprintf instead of malloc/strcat/etc.

Alan Coopersmith alan.coopersmith at oracle.com
Sun Dec 11 10:16:30 PST 2011


Also fix the reason argument to be const char * to clear several gcc
warnings of:
kdrive.c:151:2: warning: passing argument 1 of 'KdDoSwitchCmd' discards qualifiers from pointer target type
kdrive.c:116:1: note: expected 'char *' but argument is of type 'const char *'

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 hw/kdrive/src/kdrive.c |   13 ++++---------
 1 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/hw/kdrive/src/kdrive.c b/hw/kdrive/src/kdrive.c
index 8dd039e..2c64940 100644
--- a/hw/kdrive/src/kdrive.c
+++ b/hw/kdrive/src/kdrive.c
@@ -113,19 +113,14 @@ KdDisableScreen (ScreenPtr pScreen)
 }
 
 static void
-KdDoSwitchCmd (char *reason)
+KdDoSwitchCmd (const char *reason)
 {
     if (kdSwitchCmd)
     {
-	char    *command = malloc(strlen (kdSwitchCmd) +
-				   1 +
-				   strlen (reason) +
-				   1);
-	if (!command)
+	char    *command;
+
+	if (asprintf(&command, "%s %s", kdSwitchCmd, reason) == -1)
 	    return;
-	strcpy (command, kdSwitchCmd);
-	strcat (command, " ");
-	strcat (command, reason);
 	system (command);
 	free(command);
     }
-- 
1.7.3.2



More information about the xorg-devel mailing list