diff mbox

[04/11] readline: Fix unchecked strdup() by converting to g_strdup()

Message ID 1358346998-26328-5-git-send-email-armbru@redhat.com
State New
Headers show

Commit Message

Markus Armbruster Jan. 16, 2013, 2:36 p.m. UTC
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 readline.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Eric Blake Jan. 16, 2013, 3:51 p.m. UTC | #1
On 01/16/2013 07:36 AM, Markus Armbruster wrote:
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  readline.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/readline.c b/readline.c
> index a0c9638..d6e04d4 100644
> --- a/readline.c
> +++ b/readline.c
> @@ -247,14 +247,14 @@ static void readline_hist_add(ReadLineState *rs, const char *cmdline)
>      }
>      if (idx == READLINE_MAX_CMDS) {
>  	/* Need to get one free slot */
> -	free(rs->history[0]);
> +        g_free(rs->history[0]);
>  	memmove(rs->history, &rs->history[1],
>  	        (READLINE_MAX_CMDS - 1) * sizeof(char *));
>  	rs->history[READLINE_MAX_CMDS - 1] = NULL;
>  	idx = READLINE_MAX_CMDS - 1;
>      }
>      if (new_entry == NULL)
> -	new_entry = strdup(cmdline);
> +        new_entry = g_strdup(cmdline);

As long as you are converting tabs to spaces, you should also be adding {}.
Markus Armbruster Jan. 16, 2013, 4:03 p.m. UTC | #2
Eric Blake <eblake@redhat.com> writes:

> On 01/16/2013 07:36 AM, Markus Armbruster wrote:
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>>  readline.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>> 
>> diff --git a/readline.c b/readline.c
>> index a0c9638..d6e04d4 100644
>> --- a/readline.c
>> +++ b/readline.c
>> @@ -247,14 +247,14 @@ static void readline_hist_add(ReadLineState *rs, const char *cmdline)
>>      }
>>      if (idx == READLINE_MAX_CMDS) {
>>  	/* Need to get one free slot */
>> -	free(rs->history[0]);
>> +        g_free(rs->history[0]);
>>  	memmove(rs->history, &rs->history[1],
>>  	        (READLINE_MAX_CMDS - 1) * sizeof(char *));
>>  	rs->history[READLINE_MAX_CMDS - 1] = NULL;
>>  	idx = READLINE_MAX_CMDS - 1;
>>      }
>>      if (new_entry == NULL)
>> -	new_entry = strdup(cmdline);
>> +        new_entry = g_strdup(cmdline);
>
> As long as you are converting tabs to spaces, you should also be adding {}.

I style-fix exactly the lines I touch anyway.  For what it's worth,
checkpatch is happy.
diff mbox

Patch

diff --git a/readline.c b/readline.c
index a0c9638..d6e04d4 100644
--- a/readline.c
+++ b/readline.c
@@ -247,14 +247,14 @@  static void readline_hist_add(ReadLineState *rs, const char *cmdline)
     }
     if (idx == READLINE_MAX_CMDS) {
 	/* Need to get one free slot */
-	free(rs->history[0]);
+        g_free(rs->history[0]);
 	memmove(rs->history, &rs->history[1],
 	        (READLINE_MAX_CMDS - 1) * sizeof(char *));
 	rs->history[READLINE_MAX_CMDS - 1] = NULL;
 	idx = READLINE_MAX_CMDS - 1;
     }
     if (new_entry == NULL)
-	new_entry = strdup(cmdline);
+        new_entry = g_strdup(cmdline);
     rs->history[idx] = new_entry;
     rs->hist_entry = -1;
 }