From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17221 invoked by alias); 8 Apr 2005 23:33:07 -0000 Mailing-List: contact gdb-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sources.redhat.com Received: (qmail 17203 invoked from network); 8 Apr 2005 23:33:03 -0000 Received: from unknown (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org with SMTP; 8 Apr 2005 23:33:03 -0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.12.11/8.12.11) with ESMTP id j38NX3hL030454 for ; Fri, 8 Apr 2005 19:33:03 -0400 Received: from pobox.corp.redhat.com (pobox.corp.redhat.com [172.16.52.156]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id j38NWvO19162; Fri, 8 Apr 2005 19:32:57 -0400 Received: from [172.16.50.7] (vpn50-7.rdu.redhat.com [172.16.50.7]) by pobox.corp.redhat.com (8.12.8/8.12.8) with ESMTP id j38NWveP003234; Fri, 8 Apr 2005 19:32:57 -0400 Message-ID: <42571449.9030800@gnu.org> Date: Fri, 08 Apr 2005 23:33:00 -0000 From: Andrew Cagney User-Agent: Mozilla Thunderbird 1.0-5 (X11/20050308) MIME-Version: 1.0 To: Daniel Jacobowitz CC: Mark Kettenis , gdb@sources.redhat.com Subject: Re: [RFC] xnsprintf() References: <200503131448.j2DEmqZ0029001@elgar.sibelius.xs4all.nl> <20050313154155.GB18342@nevyn.them.org> In-Reply-To: <20050313154155.GB18342@nevyn.them.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2005-04/txt/msg00046.txt.bz2 Daniel Jacobowitz wrote: > On Sun, Mar 13, 2005 at 03:48:52PM +0100, Mark Kettenis wrote: > >>The bootdisk of my workstation crashed, so I found myself replacing my >>aging FreeBSD environment with a fresh OpenBSD snapshot. The OpenBSD >>toolchain complains about using dangerous functions like snprintf: >> >> libgdb.a(remote.o)(.text+0xb3b): In function `set_thread': >> ../../src/gdb/remote.c:1066: warning: sprintf() is often misused, >> please use snprintf() >> >>Of course it is right, so I've started converting sprintf() into >>snprintf(). While doing so, I find myself writing the following bit >>of code over and over again: >> >> int size; >> size = snprintf (buf, sizeof buf, ...); >> gdb_assert (size < sizeof buf); >> >>So right now I'm wondering whether we should have a function, say >>xsnprintf(), that checks whether the string fits in the buffer, and >>throws an internal-error if it doesn't. >> >>Opinions? > > > Sure. Seems like a good fit with xasprintf and xstrprintf. I like this positive change. http://sources.redhat.com/ml/gdb-patches/2003-04/msg00404.html I disagree. Why on earth wouldn't we use sprintf? Just because it can be used incorrectly is no excuse.