Re: [RFA] win32-nat printf and sprintf removal

Pierre Muller
2002-02-14T11:17:58Z

At 00:04 09/02/2002 , Christopher Faylor a Ã©crit:
>On Fri, Feb 08, 2002 at 06:29:11PM +0100, Pierre Muller wrote:
> >
> >I replaced printf by printf_unfiltered (or printf_filtered
> >when there where other printf_filtered in the same function)
> >and sprintf by xasprintf in win32-nat.c source.
>
>Since I wasn't aware of xasprintf, I checked it out. It takes
>a different first argument than sprintf. xasprintf takes a char **.
>sprintf takes a char *.
>
>Didn't you notice an increased number of warnings with this patch?
>I don't think you changed these calls correctly.

You are right, I didn't check correctly :(

>@@ -1763,9 +1763,9 @@ cygwin_pid_to_str (ptid_t ptid)
> > int pid = PIDGET (ptid);
> >
> > if ((DWORD) pid == current_event.dwProcessId)
> >- sprintf (buf, "process %d", pid);
> >+ xaprintf (buf, "process %d", pid);
> > else
> >- sprintf (buf, "thread %ld.0x%x", current_event.dwProcessId, pid);
> >+ xasprintf (buf, "thread %ld.0x%x", current_event.dwProcessId, pid);
> > return buf;

As this is a static buffer, xasprintf can't be used here....
Andrew, why are the target_pid_to_str functions supposed to return static buffers?
Isn't that a big waste of memory?

> >@@ -2009,7 +2009,7 @@ _initialize_check_for_gdb_ini (void)
> > {
> > int len = strlen (oldini);
> > char *newini = alloca (len + 1);
> >- sprintf (newini, "%.*s.gdbinit",
> >+ xasprintf (newini, "%.*s.gdbinit",
> > (int) (len - (sizeof ("gdb.ini") - 1)), oldini);
> > warning ("obsolete '%s' found. Rename to '%s'.", oldini, newini);
> > }

I corrected this one to this patch,
which doesn't give any warning.
But the memory allocated for oldini is still lost....
Can I check this in?

Index: win32-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/win32-nat.c,v
retrieving revision 1.50
diff -u -p -r1.50 win32-nat.c
--- win32-nat.c 2002/02/08 23:12:16 1.50
+++ win32-nat.c 2002/02/14 11:16:15
@@ -2008,10 +2008,11 @@ _initialize_check_for_gdb_ini (void)
if (access (oldini, 0) == 0)
{
int len = strlen (oldini);
- char *newini = alloca (len + 1);
- sprintf (newini, "%.*s.gdbinit",
+ char *newini;
+ xasprintf (&newini, "%.*s.gdbinit",
(int) (len - (sizeof ("gdb.ini") - 1)), oldini);
warning ("obsolete '%s' found. Rename to '%s'.", oldini, newini);
+ xfree (newini);
}
}
}

Pierre Muller
Institut Charles Sadron
6,rue Boussingault
F 67083 STRASBOURG CEDEX (France)
mailto:muller@ics.u-strasbg.fr
Phone : (33)-3-88-41-40-07 Fax : (33)-3-88-41-40-99