This is the mail archive of the 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]
Other format: [Raw text]

Re: Patch to provide a default for ASM_OUTPUT_INTERNAL_LABEL

 > From: Richard Henderson <>
 > On Thu, Aug 22, 2002 at 01:36:09PM -0400, Kaveh R. Ghazi wrote:
 > > +  do {								\
 > > +    const char *const prefix_ = (PREFIX);			\
 > > +    char *const buf_ = alloca (40 + strlen (prefix_));		\
 > > +    ASM_GENERATE_INTERNAL_LABEL (buf_, prefix_, (LABELNO));	\
 > I don't see that using alloca here is effective at all.

Why not?  I've seen buffers used in dwarf2out.c hardcoded at 20 bytes.
So 40 + strlen (PREFIX) should be plenty, no?

 > I'd be in favour of the final GENERATE target hook taking a
 > length parameter for the buffer, and doing something like
 > 	if (snprintf (buf, size, format, args) == -1)
 > 	  abort ();
 > Or perhaps _define_ the input buffer to have some specific
 > length (e.g. MAX_INTERNAL_LABEL_LEN=64) and fix up all uses.
 > r~

I think snprintf is supposed to return the length of what would have
been output even when you would have exceeded the max, not -1.  Not
all platforms do this correctly though, on irix6.5 it returns the
truncated printed length.  So you'll never know that you would have
exceeded the supplied length by checking the return type.

Hmm, I think I can get around this by checking for a max length two
less than the real buffer length like so:

	char buf[MAX+2];
	if (snprintf (buf, MAX+2, format, args) > MAX)
	  abort ();

I'll do something like this when I convert the GENERATE stuff into a

Kaveh R. Ghazi

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