This is the mail archive of the
gdb@sources.redhat.com
mailing list for the GDB project.
Re: [RFC] xnsprintf()
- From: Daniel Jacobowitz <drow at false dot org>
- To: Mark Kettenis <kettenis at gnu dot org>
- Cc: gdb at sources dot redhat dot com
- Date: Sun, 13 Mar 2005 10:41:55 -0500
- Subject: Re: [RFC] xnsprintf()
- References: <200503131448.j2DEmqZ0029001@elgar.sibelius.xs4all.nl>
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