Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* [RFC] xnsprintf()
@ 2005-03-13 14:49 Mark Kettenis
  2005-03-13 15:41 ` Daniel Jacobowitz
  0 siblings, 1 reply; 5+ messages in thread
From: Mark Kettenis @ 2005-03-13 14:49 UTC (permalink / raw)
  To: gdb

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFC] xnsprintf()
  2005-03-13 14:49 [RFC] xnsprintf() Mark Kettenis
@ 2005-03-13 15:41 ` Daniel Jacobowitz
  2005-03-16  0:27   ` Kevin Buettner
  2005-04-08 23:33   ` Andrew Cagney
  0 siblings, 2 replies; 5+ messages in thread
From: Daniel Jacobowitz @ 2005-03-13 15:41 UTC (permalink / raw)
  To: Mark Kettenis; +Cc: gdb

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFC] xnsprintf()
  2005-03-13 15:41 ` Daniel Jacobowitz
@ 2005-03-16  0:27   ` Kevin Buettner
  2005-04-08 23:33   ` Andrew Cagney
  1 sibling, 0 replies; 5+ messages in thread
From: Kevin Buettner @ 2005-03-16  0:27 UTC (permalink / raw)
  To: gdb; +Cc: Mark Kettenis

On Sun, 13 Mar 2005 10:41:55 -0500
Daniel Jacobowitz <drow@false.org> wrote:

> On Sun, Mar 13, 2005 at 03:48:52PM +0100, Mark Kettenis wrote:
> > 
> > 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 agree.

Kevin


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFC] xnsprintf()
  2005-03-13 15:41 ` Daniel Jacobowitz
  2005-03-16  0:27   ` Kevin Buettner
@ 2005-04-08 23:33   ` Andrew Cagney
  2005-04-08 23:39     ` Daniel Jacobowitz
  1 sibling, 1 reply; 5+ messages in thread
From: Andrew Cagney @ 2005-04-08 23:33 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: Mark Kettenis, gdb

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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFC] xnsprintf()
  2005-04-08 23:33   ` Andrew Cagney
@ 2005-04-08 23:39     ` Daniel Jacobowitz
  0 siblings, 0 replies; 5+ messages in thread
From: Daniel Jacobowitz @ 2005-04-08 23:39 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: Mark Kettenis, gdb

On Fri, Apr 08, 2005 at 07:31:21PM -0400, Andrew Cagney wrote:
> 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.

Mark has a valid reason - that OpenBSD has begun to warn about it - and
even if I think it's a bit objectionable for an OS to issue such a
warning, we don't get to decide that.

He was also offering a constructive idea for a new interface instead of
objecting to anything.  The question I answered here is not the same
as the opinion I offered in your quoted message.

Anyway, did you have anything useful to contribute, or did you just pop
out of the woodwork to be sarcastic at me?  I don't appreciate it.

-- 
Daniel Jacobowitz
CodeSourcery, LLC


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-04-08 23:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-13 14:49 [RFC] xnsprintf() Mark Kettenis
2005-03-13 15:41 ` Daniel Jacobowitz
2005-03-16  0:27   ` Kevin Buettner
2005-04-08 23:33   ` Andrew Cagney
2005-04-08 23:39     ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox