From c4e54771f84f3acd02c6da80a6f62603eb3e8505 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Mon, 19 May 2014 13:10:21 -0600 Subject: [PATCH] fix two latent type errors I'm checking this in as obvious. I was looking at instances of "alloc.*sizeof" and noticed a couple where the types in question are incorrect. In gdbtypes, the code allocates sizeof(int) to represent a struct rank. In mi-cmds, the code uses "struct mi_cmd **" -- one "*" too many. In both cases the problems are latent because in practice the sizes are the same as the sizes of the correct types. Still, it's better to be correct. I think gdb would be improved by a wholesale change from explicit sizeofs to using the libiberty.h allocation macros. In most cases they are both shorter and have better type safety. However, the resulting patch is rather large. Built and regtested on x86-64 Fedora 20. 2014-05-19 Tom Tromey * gdbtypes.c (rank_function): Use XNEWVEC. * mi/mi-cmds.c (build_table): Use XCNEWVEC. --- gdb/ChangeLog | 5 +++++ gdb/gdbtypes.c | 2 +- gdb/mi/mi-cmds.c | 4 +--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index ee3d848b8d0..c9bf846de12 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2014-05-19 Tom Tromey + + * gdbtypes.c (rank_function): Use XNEWVEC. + * mi/mi-cmds.c (build_table): Use XCNEWVEC. + 2014-05-19 Doug Evans * dwarf2read.c (struct dwarf2_per_objfile): Delete unused members diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 8e6631af175..d58193e82f4 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -2582,7 +2582,7 @@ rank_function (struct type **parms, int nparms, bv = xmalloc (sizeof (struct badness_vector)); bv->length = nargs + 1; /* add 1 for the length-match rank. */ - bv->rank = xmalloc ((nargs + 1) * sizeof (int)); + bv->rank = XNEWVEC (struct rank, nargs + 1); /* First compare the lengths of the supplied lists. If there is a mismatch, set it to a high value. */ diff --git a/gdb/mi/mi-cmds.c b/gdb/mi/mi-cmds.c index 87a536faf11..68f97f66d54 100644 --- a/gdb/mi/mi-cmds.c +++ b/gdb/mi/mi-cmds.c @@ -247,10 +247,8 @@ build_table (struct mi_cmd *commands) int nr_rehash = 0; int nr_entries = 0; struct mi_cmd *command; - int sizeof_table = sizeof (struct mi_cmd **) * MI_TABLE_SIZE; - mi_table = xmalloc (sizeof_table); - memset (mi_table, 0, sizeof_table); + mi_table = XCNEWVEC (struct mi_cmd *, MI_TABLE_SIZE); for (command = commands; command->name != 0; command++) { struct mi_cmd **entry = lookup_table (command->name); -- 2.30.2