This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[rfa] kod-cisco.c init sync_ids, exploit xrealloc()
- To: GDB Patches <gdb-patches at sourceware dot cygnus dot com>
- Subject: [rfa] kod-cisco.c init sync_ids, exploit xrealloc()
- From: Andrew Cagney <ac131313 at cygnus dot com>
- Date: Mon, 27 Nov 2000 18:33:22 +1100
Hello,
The attatched simplifies the setting of ``sync_ids'' by exploiting
xrealloc()'s semantics (If NULL, act like xmalloc()). It also
eliminates a -Wuninitialized warning.
Ok?
Andrew
* kod-cisco.c (cisco_kod_request): Simplify allocation of
``sync_ids'' eliminating uninitialized variable.
Index: kod-cisco.c
===================================================================
RCS file: /cvs/src/src/gdb/kod-cisco.c,v
retrieving revision 1.2
diff -p -r1.2 kod-cisco.c
*** kod-cisco.c 2000/07/30 01:48:26 1.2
--- kod-cisco.c 2000/11/27 06:54:08
*************** cisco_kod_request (char *arg, int from_t
*** 112,118 ****
int done = 0, i;
int fail = 0;
! char **sync_ids;
int sync_len = 0;
int sync_next = 0;
char *prev_id = NULL;
--- 112,118 ----
int done = 0, i;
int fail = 0;
! char **sync_ids = NULL;
int sync_len = 0;
int sync_next = 0;
char *prev_id = NULL;
*************** cisco_kod_request (char *arg, int from_t
*** 216,227 ****
buffer[off + 8] = '\0';
off += 9;
- if (sync_len == 0)
- sync_ids = (char **) xmalloc (count * sizeof (char *));
- else
- sync_ids = (char **) xrealloc (sync_ids,
- (sync_len + count) * sizeof (char *));
sync_len += count;
for (i = 0; i < count; ++i)
{
--- 216,223 ----
buffer[off + 8] = '\0';
off += 9;
sync_len += count;
+ sync_ids = (char **) xrealloc (sync_ids, sync_len * sizeof (char *));
for (i = 0; i < count; ++i)
{