cmd: Fix potential NULL pointer dereference
PATCH 1/1 cmd: Fix potential NULL pointer dereference
---
Note, that almost all code in the file violates CODING STYLE. The changed lines are written wrt CODING STYLE (like commits 7d7d975c and c32d766a).
---
cmd.c | 11 +++-------- 1 files changed, 3 insertions(+), 8 deletions(-)
cmd.c +3 -8
@@ -49,7 +49,7 @@ voidadd_command ( const cmdinfo_t *ci) { - cmdtab =realloc ((void *)cmdtab, ++ncmds *sizeof (*cmdtab)); + cmdtab =g_realloc ((void *)cmdtab, ++ncmds *sizeof (*cmdtab)); cmdtab[ncmds -1 ] = *ci;qsort (cmdtab, ncmds,sizeof (*cmdtab), compare); }
@@ -125,12 +125,7 @@ find_command(void add_user_command (char *optarg) { - ncmdline++; - cmdline =realloc (cmdline,sizeof (char *) * (ncmdline)); -if (!cmdline) { -perror ("realloc" ); -exit (1 ); - } + cmdline =g_realloc (cmdline, ++ncmdline *sizeof (char *)); cmdline[ncmdline-1 ] = optarg; }
@@ -194,7 +189,7 @@ command_loop(void)doneline (input, v); }if (cmdline) { -free (cmdline); +g_free (cmdline);return ; }
Signature · 1 line
1.7.0.4
Quoted 15 lines · Pavel Borzenkov
Signed-off-by Pavel Borzenkov <[email protected]>---
Note, that almost all code in the file violates CODING STYLE. The changed lines are written wrt CODING STYLE (like commits7d7d975candc32d766a).---
cmd.c | 11 +++-------- 1 files changed, 3 insertions(+), 8 deletions(-)cmd.c +0
-0
cmd.c void · line 55
Quoted 8 lines
cmd.c +1
-1@@ -49,7 +49,7 @@ voidadd_command ( const cmdinfo_t *ci) { - cmdtab =realloc ((void *)cmdtab, ++ncmds *sizeof (*cmdtab)); + cmdtab =g_realloc ((void *)cmdtab, ++ncmds *sizeof (*cmdtab)); cmdtab[ncmds -1 ] = *ci;qsort (cmdtab, ncmds,sizeof (*cmdtab), compare); }
Inconsistent indentation.
Either stick to the original indentation, or reindent the whole function.
[More of the same...]
Quoted 28 lines · Markus Armbruster
Quoted 15 lines · Pavel Borzenkov
Signed-off-by Pavel Borzenkov <[email protected]>---
Note, that almost all code in the file violates CODING STYLE. The changed lines are written wrt CODING STYLE (like commits7d7d975candc32d766a).---
cmd.c | 11 +++--------
1 files changed, 3 insertions(+), 8 deletions(-)cmd.c +0
-0@@ -49,7 +49,7 @@ voidQuoted 8 lines
add_command(
constcmdinfo_t*ci)
{
- cmdtab =realloc((void *)cmdtab, ++ncmds * sizeof(*cmdtab));
+ cmdtab =g_realloc((void *)cmdtab, ++ncmds * sizeof(*cmdtab)); cmdtab[ncmds - 1] = *ci;
qsort(cmdtab, ncmds, sizeof(*cmdtab), compare);
}Inconsistent indentation.
Quoted 2 lines
Either stick to the original indentation, or reindent the whole function.
I'll send second version with coding style fixes made in a separate commit.
Signature · 1 line
Pavel
Quoted 3 lines
[More of the same...]