From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16536 invoked by alias); 13 Mar 2005 15:41:58 -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 16519 invoked from network); 13 Mar 2005 15:41:55 -0000 Received: from unknown (HELO nevyn.them.org) (66.93.172.17) by sourceware.org with SMTP; 13 Mar 2005 15:41:55 -0000 Received: from drow by nevyn.them.org with local (Exim 4.44 #1 (Debian)) id 1DAVE3-0004oS-Hi; Sun, 13 Mar 2005 10:41:55 -0500 Date: Sun, 13 Mar 2005 15:41:00 -0000 From: Daniel Jacobowitz To: Mark Kettenis Cc: gdb@sources.redhat.com Subject: Re: [RFC] xnsprintf() Message-ID: <20050313154155.GB18342@nevyn.them.org> Mail-Followup-To: Mark Kettenis , gdb@sources.redhat.com References: <200503131448.j2DEmqZ0029001@elgar.sibelius.xs4all.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200503131448.j2DEmqZ0029001@elgar.sibelius.xs4all.nl> User-Agent: Mutt/1.5.6+20040907i X-SW-Source: 2005-03/txt/msg00146.txt.bz2 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. -- Daniel Jacobowitz CodeSourcery, LLC