From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18514 invoked by alias); 14 Feb 2002 15:31:40 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 18333 invoked from network); 14 Feb 2002 15:31:35 -0000 Received: from unknown (HELO localhost.redhat.com) (24.112.135.44) by sources.redhat.com with SMTP; 14 Feb 2002 15:31:35 -0000 Received: from cygnus.com (localhost [127.0.0.1]) by localhost.redhat.com (Postfix) with ESMTP id D703C3CC5; Thu, 14 Feb 2002 10:31:33 -0500 (EST) Message-ID: <3C6BD855.8030003@cygnus.com> Date: Thu, 14 Feb 2002 07:31:00 -0000 From: Andrew Cagney User-Agent: Mozilla/5.0 (X11; U; NetBSD macppc; en-US; rv:0.9.8) Gecko/20020210 X-Accept-Language: en-us MIME-Version: 1.0 To: Pierre Muller Cc: gdb-patches@sources.redhat.com Subject: Re: [RFA] win32-nat printf and sprintf removal References: <4.2.0.58.20020208182442.00ad05e0@ics.u-strasbg.fr> <4.2.0.58.20020208182442.00ad05e0@ics.u-strasbg.fr> <4.2.0.58.20020214121240.01a80208@ics.u-strasbg.fr> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2002-02/txt/msg00406.txt.bz2 >>@@ -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