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

Christopher Faylor
2002-02-14T15:59:35Z

On Thu, Feb 14, 2002 at 12:17:17PM +0100, Pierre Muller wrote:
> >@@ -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?

No.

>> >@@ -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?

No. Please don't mess with the sprintfs in win32-nat.c.

cgf