readline: use g_strndup instead of open-coding it
authorMichael Tokarev <mjt@tls.msk.ru>
Mon, 5 May 2014 09:23:50 +0000 (13:23 +0400)
committerMichael Tokarev <mjt@tls.msk.ru>
Wed, 7 May 2014 17:00:43 +0000 (21:00 +0400)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Reviewed-by: Andreas Färber <afaerber@suse.de>
util/readline.c

index 8441be4..a3fd2cb 100644 (file)
@@ -279,9 +279,7 @@ static void readline_completion(ReadLineState *rs)
 
     rs->nb_completions = 0;
 
-    cmdline = g_malloc(rs->cmd_buf_index + 1);
-    memcpy(cmdline, rs->cmd_buf, rs->cmd_buf_index);
-    cmdline[rs->cmd_buf_index] = '\0';
+    cmdline = g_strndup(rs->cmd_buf, rs->cmd_buf_index);
     rs->completion_finder(rs->opaque, cmdline);
     g_free(cmdline);