This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
FYI: some minor `sizeof'-related fixes
- From: Tom Tromey <tromey at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Fri, 29 Apr 2011 12:41:12 -0600
- Subject: FYI: some minor `sizeof'-related fixes
I am checking this in on the trunk.
A static analysis tool noticed a few incorrect uses of `sizeof':
* For the breakpoint.c change, xcalloc takes the size of the element
type as an argument. In this case the fix is just pedantic, since
char* and char** have the same size on ordinary machines.
* mi-parse.c was over-allocating some arrays by using sizeof(char*).
The correct use is sizeof(char), but since that is 1 by definition, I
removed it entirely.
Tom
2011-04-29 Tom Tromey <tromey@redhat.com>
* mi/mi-parse.c (mi_parse): Remove incorrect sizeof.
(mi_parse): Likewise.
* breakpoint.c (break_range_command): Use sizeof char*, not
char**.
(create_breakpoint): Likewise.
(parse_breakpoint_sals): Likewise.
Index: breakpoint.c
===================================================================
RCS file: /cvs/src/src/gdb/breakpoint.c,v
retrieving revision 1.570
diff -u -r1.570 breakpoint.c
--- breakpoint.c 27 Apr 2011 12:44:26 -0000 1.570
+++ breakpoint.c 29 Apr 2011 18:38:19 -0000
@@ -7698,7 +7698,7 @@
}
/* For any SAL that didn't have a canonical string, fill one in. */
if (sals->nelts > 0 && canonical->canonical == NULL)
- canonical->canonical = xcalloc (sals->nelts, sizeof (char **));
+ canonical->canonical = xcalloc (sals->nelts, sizeof (char *));
if (addr_start != (*address))
{
int i;
@@ -7917,7 +7917,7 @@
sals = decode_static_tracepoint_spec (&arg);
copy_arg = savestring (addr_start, arg - addr_start);
- canonical.canonical = xcalloc (sals.nelts, sizeof (char **));
+ canonical.canonical = xcalloc (sals.nelts, sizeof (char *));
for (i = 0; i < sals.nelts; i++)
canonical.canonical[i] = xstrdup (copy_arg);
goto done;
@@ -8573,7 +8573,7 @@
/* canonical_end can be NULL if it was of the form "*0xdeadbeef". */
if (canonical_end.canonical == NULL)
- canonical_end.canonical = xcalloc (1, sizeof (char **));
+ canonical_end.canonical = xcalloc (1, sizeof (char *));
/* Add the string if not present. */
if (arg_start != arg && canonical_end.canonical[0] == NULL)
canonical_end.canonical[0] = savestring (arg_start, arg - arg_start);
Index: mi/mi-parse.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-parse.c,v
retrieving revision 1.25
diff -u -r1.25 mi-parse.c
--- mi/mi-parse.c 1 Jan 2011 15:33:25 -0000 1.25
+++ mi/mi-parse.c 29 Apr 2011 18:38:19 -0000
@@ -253,7 +253,7 @@
/* Find/skip any token and then extract it. */
for (chp = cmd; *chp >= '0' && *chp <= '9'; chp++)
;
- *token = xmalloc ((chp - cmd + 1) * sizeof (char *));
+ *token = xmalloc (chp - cmd + 1);
memcpy (*token, cmd, (chp - cmd));
(*token)[chp - cmd] = '\0';
@@ -276,7 +276,7 @@
for (; *chp && !isspace (*chp); chp++)
;
- parse->command = xmalloc ((chp - tmp + 1) * sizeof (char *));
+ parse->command = xmalloc (chp - tmp + 1);
memcpy (parse->command, tmp, chp - tmp);
parse->command[chp - tmp] = '\0';
}