From ff64ad6c74a3e14ca34bacb8866bdbd2262bddff Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Mon, 12 Dec 2011 16:49:34 -0800 Subject: [PATCH] Convert KdDoSwitchCmd to use asprintf instead of malloc/strcat/etc. 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 Reviewed-by: Jamey Sharp Reviewed-by: Peter Hutterer --- hw/kdrive/src/kdrive.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/hw/kdrive/src/kdrive.c b/hw/kdrive/src/kdrive.c index 8dd039e1d..2c649409e 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); }