This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [PATCH] Optimize sprintf into strcpy if possible


On Fri, Apr 06, 2001 at 01:08:43PM -0700, Matt Kraai wrote:
> On Fri, Apr 06, 2001 at 08:49:28PM +0200, Jakub Jelinek wrote:
> > +  /* Test at least one instance of the __builtin_ style.  We do this
> > +     to ensure that it works and that the prototype is correct.  */
> > +  __builtin_sprintf (--d2, "z");
> > +  if (memcmp (dst, "oobarz", 7 != 0) || d2 != dst + 6)
> > +    abort ();
> 
> This test isn't correct.  It puts the "z" past the end of the
> string, and the memcmp has an incorrect count.

Well, sure, the test is not what I meant, but since it is the same as
if (memcmp (dst, "oobarz", 1) != 0 || d2 != dst + 6)
it has not triggered the abort().

The test should obviously look like:
  if (memcmp (dst, "oobar\0z", 8) != 0 || d2 != dst + 6)
    abort();

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]