From: Andrew Cagney <ac131313@cygnus.com>
To: Pierre Muller <muller@cerbere.u-strasbg.fr>
Cc: gdb-patches@sources.redhat.com
Subject: Re: [RFA] win32-nat printf and sprintf removal
Date: Thu, 14 Feb 2002 07:31:00 -0000 [thread overview]
Message-ID: <3C6BD855.8030003@cygnus.com> (raw)
In-Reply-To: <4.2.0.58.20020214121240.01a80208@ics.u-strasbg.fr>
>>@@ -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?
Different coding styles. People use static buffers (making the code
non-reentrant) and sprintf() (making the code prone to buffer overruns)
for a number of reasons. One is that the programmer does know the
lenght of the buffer and does know it won't be called re-entrantly so,
rather than contend with cleanups, they use a static buffer.
Suggest adding a comment just above each sprintf() call indicating that
buf is static (at least that way the next person won't be puzzled by this).
Andrew
next prev parent reply other threads:[~2002-02-14 15:31 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-02-08 9:29 Pierre Muller
2002-02-08 11:00 ` Andrew Cagney
2002-02-08 11:34 ` muller
2002-02-08 15:04 ` Christopher Faylor
2002-02-08 15:17 ` Martin M. Hunt
2002-02-08 15:48 ` Martin M. Hunt
2002-02-14 3:17 ` Pierre Muller
2002-02-14 3:36 ` Pierre Muller
2002-02-14 7:31 ` Andrew Cagney [this message]
2002-02-14 8:13 ` Christopher Faylor
2002-02-14 8:44 ` Pierre Muller
2002-02-14 8:49 ` Christopher Faylor
2002-02-14 7:59 ` Christopher Faylor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3C6BD855.8030003@cygnus.com \
--to=ac131313@cygnus.com \
--cc=gdb-patches@sources.redhat.com \
--cc=muller@cerbere.u-strasbg.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox