This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [rfa] kod-cisco.c init sync_ids, exploit xrealloc()


Andrew Cagney wrote:
> 
> 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?

Sure.  Thanks.


>         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)
>         {

-- 
Fernando Nasser
Red Hat Canada Ltd.                     E-Mail:  fnasser@redhat.com
2323 Yonge Street, Suite #300
Toronto, Ontario   M4P 2C9

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]