From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6169 invoked by alias); 13 Mar 2005 14:49:03 -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 6115 invoked from network); 13 Mar 2005 14:48:54 -0000 Received: from unknown (HELO sibelius.xs4all.nl) (82.92.89.47) by sourceware.org with SMTP; 13 Mar 2005 14:48:54 -0000 Received: from elgar.sibelius.xs4all.nl (root@elgar.sibelius.xs4all.nl [192.168.0.2]) by sibelius.xs4all.nl (8.13.0/8.13.0) with ESMTP id j2DEmrvW013095 for ; Sun, 13 Mar 2005 15:48:53 +0100 (CET) Received: from elgar.sibelius.xs4all.nl (kettenis@localhost.sibelius.xs4all.nl [127.0.0.1]) by elgar.sibelius.xs4all.nl (8.13.3/8.13.3) with ESMTP id j2DEmrL4008590 for ; Sun, 13 Mar 2005 15:48:53 +0100 (CET) Received: (from kettenis@localhost) by elgar.sibelius.xs4all.nl (8.13.3/8.13.3/Submit) id j2DEmqZ0029001; Sun, 13 Mar 2005 15:48:52 +0100 (CET) Date: Sun, 13 Mar 2005 14:49:00 -0000 Message-Id: <200503131448.j2DEmqZ0029001@elgar.sibelius.xs4all.nl> From: Mark Kettenis To: gdb@sources.redhat.com Subject: [RFC] xnsprintf() X-SW-Source: 2005-03/txt/msg00144.txt.bz2 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? Mark