This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[patch] malloc() -> xmalloc()
- To: GDB Patches <gdb-patches at sourceware dot cygnus dot com>
- Subject: [patch] malloc() -> xmalloc()
- From: Andrew Cagney <ac131313 at cygnus dot com>
- Date: Mon, 19 Mar 2001 20:36:20 -0500
FYI,
I've checked in the attatched.
Andrew
2001-03-19 Andrew Cagney <ac131313@redhat.com>
* defs.h (malloc): Move declaration from here.
* utils.c (malloc): To here.
* config/pa/xm-hppah.h (malloc): Delete declaration.
* gnu-nat.c (make_proc): Use xmalloc instead of malloc.
* hp-psymtab-read.c (hpread_call_pxdb): Ditto.
(hpread_quick_traverse): Ditto.
* infttrace.c (create_thread_info): Ditto.
(kill_inferior): Ditto.
* gnu-nat.c (make_inf): Ditto, and don't check return value.
* procfs.c (proc_update_threads): Ditto.
* valprint.c (print_decimal_chars): Ditto.
* gdbtypes.c (cfront_mangle_name): Use xasprintf instead of
malloc and sprintf.
* remote-rdp.c (rdp_set_command_line): Ditto.
Index: defs.h
===================================================================
RCS file: /cvs/src/src/gdb/defs.h,v
retrieving revision 1.45
diff -p -r1.45 defs.h
*** defs.h 2001/03/20 00:54:42 1.45
--- defs.h 2001/03/20 01:33:23
*************** extern int fclose (FILE *);
*** 945,958 ****
extern double atof (const char *); /* X3.159-1989 4.10.1.1 */
#endif
- #ifndef MALLOC_INCOMPATIBLE
-
- #ifdef NEED_DECLARATION_MALLOC
- extern PTR malloc ();
- #endif
-
- #endif /* MALLOC_INCOMPATIBLE */
-
/* Various possibilities for alloca. */
#ifndef alloca
#ifdef __GNUC__
--- 945,950 ----
Index: gdbtypes.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtypes.c,v
retrieving revision 1.18
diff -p -r1.18 gdbtypes.c
*** gdbtypes.c 2001/03/07 02:57:08 1.18
--- gdbtypes.c 2001/03/20 01:33:24
*************** cfront_mangle_name (struct type *type, i
*** 1350,1357 ****
}
ADD_EXTRA ('\0')
printf ("add_mangled_type: %s\n", extras.str); /* FIXME */
! arm_mangled_name = malloc (strlen (mangled_name) + extras.len);
! sprintf (arm_mangled_name, "%s%s", mangled_name, extras.str);
xfree (mangled_name);
mangled_name = arm_mangled_name;
}
--- 1350,1356 ----
}
ADD_EXTRA ('\0')
printf ("add_mangled_type: %s\n", extras.str); /* FIXME */
! xasprintf (&arm_mangled_name, "%s%s", mangled_name, extras.str);
xfree (mangled_name);
mangled_name = arm_mangled_name;
}
Index: gnu-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/gnu-nat.c,v
retrieving revision 1.12
diff -p -r1.12 gnu-nat.c
*** gnu-nat.c 2001/03/15 16:55:14 1.12
--- gnu-nat.c 2001/03/20 01:33:24
*************** make_proc (struct inf *inf, mach_port_t
*** 539,545 ****
{
error_t err;
mach_port_t prev_port = MACH_PORT_NULL;
! struct proc *proc = malloc (sizeof (struct proc));
proc->port = port;
proc->tid = tid;
--- 539,545 ----
{
error_t err;
mach_port_t prev_port = MACH_PORT_NULL;
! struct proc *proc = xmalloc (sizeof (struct proc));
proc->port = port;
proc->tid = tid;
*************** _proc_free (struct proc *proc)
*** 636,645 ****
struct inf *
make_inf (void)
{
! struct inf *inf = malloc (sizeof (struct inf));
!
! if (!inf)
! return 0;
inf->task = 0;
inf->threads = 0;
--- 636,642 ----
struct inf *
make_inf (void)
{
! struct inf *inf = xmalloc (sizeof (struct inf));
inf->task = 0;
inf->threads = 0;
Index: hp-psymtab-read.c
===================================================================
RCS file: /cvs/src/src/gdb/hp-psymtab-read.c,v
retrieving revision 1.9
diff -p -r1.9 hp-psymtab-read.c
*** hp-psymtab-read.c 2001/03/06 08:21:08 1.9
--- hp-psymtab-read.c 2001/03/20 01:33:26
*************** hpread_call_pxdb (char *file_name)
*** 118,124 ****
if (file_exists (PXDB_SVR4))
{
! p = malloc (strlen (PXDB_SVR4) + strlen (file_name) + 2);
strcpy (p, PXDB_SVR4);
strcat (p, " ");
strcat (p, file_name);
--- 118,124 ----
if (file_exists (PXDB_SVR4))
{
! p = xmalloc (strlen (PXDB_SVR4) + strlen (file_name) + 2);
strcpy (p, PXDB_SVR4);
strcat (p, " ");
strcat (p, file_name);
*************** hpread_quick_traverse (struct objfile *o
*** 946,952 ****
static_syms);
/* Set up to only enter each class referenced in this module once. */
! class_entered = malloc (B_BYTES (pxdb_header_p->cd_entries));
B_CLRALL (class_entered, pxdb_header_p->cd_entries);
/* Scan the procedure descriptors for procedures in the current
--- 946,952 ----
static_syms);
/* Set up to only enter each class referenced in this module once. */
! class_entered = xmalloc (B_BYTES (pxdb_header_p->cd_entries));
B_CLRALL (class_entered, pxdb_header_p->cd_entries);
/* Scan the procedure descriptors for procedures in the current
*************** hpread_quick_traverse (struct objfile *o
*** 1174,1180 ****
static_syms);
/* Set up to only enter each class referenced in this module once. */
! class_entered = malloc (B_BYTES (pxdb_header_p->cd_entries));
B_CLRALL (class_entered, pxdb_header_p->cd_entries);
/* Scan the procedure descriptors for procedures in the current
--- 1174,1180 ----
static_syms);
/* Set up to only enter each class referenced in this module once. */
! class_entered = xmalloc (B_BYTES (pxdb_header_p->cd_entries));
B_CLRALL (class_entered, pxdb_header_p->cd_entries);
/* Scan the procedure descriptors for procedures in the current
Index: infttrace.c
===================================================================
RCS file: /cvs/src/src/gdb/infttrace.c,v
retrieving revision 1.10
diff -p -r1.10 infttrace.c
*** infttrace.c 2001/03/15 16:55:14 1.10
--- infttrace.c 2001/03/20 01:33:27
*************** create_thread_info (int pid, lwpid_t tid
*** 602,608 ****
thread_info *p;
int thread_count_of_pid;
! new_p = malloc (sizeof (thread_info));
new_p->pid = pid;
new_p->tid = tid;
new_p->have_signal = 0;
--- 602,608 ----
thread_info *p;
int thread_count_of_pid;
! new_p = xmalloc (sizeof (thread_info));
new_p->pid = pid;
new_p->tid = tid;
new_p->have_signal = 0;
*************** kill_inferior (void)
*** 3830,3837 ****
zaps the target vector.
*/
! paranoia = (thread_info **) malloc (thread_head.count *
! sizeof (thread_info *));
para_count = 0;
t = thread_head.head;
--- 3830,3837 ----
zaps the target vector.
*/
! paranoia = (thread_info **) xmalloc (thread_head.count *
! sizeof (thread_info *));
para_count = 0;
t = thread_head.head;
Index: procfs.c
===================================================================
RCS file: /cvs/src/src/gdb/procfs.c,v
retrieving revision 1.24
diff -p -r1.24 procfs.c
*** procfs.c 2001/03/15 16:55:14 1.24
--- procfs.c 2001/03/20 01:33:29
*************** proc_update_threads (procinfo *pi)
*** 2876,2884 ****
if ((nlwp = proc_get_nthreads (pi)) <= 1)
return 1; /* Process is not multi-threaded; nothing to do. */
! if ((prstatus = (gdb_prstatus_t *)
! malloc (sizeof (gdb_prstatus_t) * (nlwp + 1))) == 0)
! perror_with_name ("procfs: malloc failed in update_threads");
old_chain = make_cleanup (xfree, prstatus);
if (ioctl (pi->ctl_fd, PIOCLSTATUS, prstatus) < 0)
--- 2876,2882 ----
if ((nlwp = proc_get_nthreads (pi)) <= 1)
return 1; /* Process is not multi-threaded; nothing to do. */
! prstatus = xmalloc (sizeof (gdb_prstatus_t) * (nlwp + 1));
old_chain = make_cleanup (xfree, prstatus);
if (ioctl (pi->ctl_fd, PIOCLSTATUS, prstatus) < 0)
*************** proc_update_threads (procinfo *pi)
*** 2984,2991 ****
if (nthreads < 2)
return 0; /* nothing to do for 1 or fewer threads */
! if ((threads = malloc (nthreads * sizeof (tid_t))) == NULL)
! proc_error (pi, "update_threads, malloc", __LINE__);
if (ioctl (pi->ctl_fd, PIOCTLIST, threads) < 0)
proc_error (pi, "procfs: update_threads (PIOCTLIST)", __LINE__);
--- 2982,2988 ----
if (nthreads < 2)
return 0; /* nothing to do for 1 or fewer threads */
! threads = xmalloc (nthreads * sizeof (tid_t));
if (ioctl (pi->ctl_fd, PIOCTLIST, threads) < 0)
proc_error (pi, "procfs: update_threads (PIOCTLIST)", __LINE__);
Index: remote-rdp.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-rdp.c,v
retrieving revision 1.13
diff -p -r1.13 remote-rdp.c
*** remote-rdp.c 2001/03/06 08:21:12 1.13
--- remote-rdp.c 2001/03/20 01:33:30
*************** rdp_set_command_line (char *command, cha
*** 699,711 ****
if (commandline != NULL)
xfree (commandline);
! commandline = malloc (strlen (command) + strlen (args) + 2);
! if (commandline != NULL)
! {
! strcpy (commandline, command);
! strcat (commandline, " ");
! strcat (commandline, args);
! }
}
static void
--- 699,705 ----
if (commandline != NULL)
xfree (commandline);
! xasprintf (&commandline, %s %s", command, args);
}
static void
Index: utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.37
diff -p -r1.37 utils.c
*** utils.c 2001/03/20 00:54:42 1.37
--- utils.c 2001/03/20 01:33:30
***************
*** 57,62 ****
--- 57,65 ----
#include <readline/readline.h>
#ifndef MALLOC_INCOMPATIBLE
+ #ifdef NEED_DECLARATION_MALLOC
+ extern PTR malloc ();
+ #endif
#ifdef NEED_DECLARATION_REALLOC
extern PTR realloc ();
#endif
Index: valprint.c
===================================================================
RCS file: /cvs/src/src/gdb/valprint.c,v
retrieving revision 1.13
diff -p -r1.13 valprint.c
*** valprint.c 2001/03/07 16:09:03 1.13
--- valprint.c 2001/03/20 01:33:42
*************** print_decimal_chars (struct ui_file *str
*** 838,846 ****
* as the base 16 number, which is 2 digits per byte.
*/
decimal_len = len * 2 * 2;
! digits = (unsigned char *) malloc (decimal_len);
! if (digits == NULL)
! error ("Can't allocate memory for conversion to decimal.");
for (i = 0; i < decimal_len; i++)
{
--- 838,844 ----
* as the base 16 number, which is 2 digits per byte.
*/
decimal_len = len * 2 * 2;
! digits = xmalloc (decimal_len);
for (i = 0; i < decimal_len; i++)
{