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: Weird optimization bug...?

Yeah, that would make sense.  And buffer overruns can sometimes appear
only in release mode (not 0 initializing something or the like).... 
However, if that was the case, inserting a random function into the code
certain shouldn't fix the problem :P.

Here's a snippet of code for all to see, I'll just explain some of the
dependent stuff:

//not compilable unless you have all the other classes... which is a lot

template<typename T1,typename T2> void
vbox_blur(T1 pen,int w, int h, int length,T2 outpen)
	int x,y;
   	typename T1::iterator_y iter, end;
	printf("V Blur (%d,%d) - %d size\n",w,h,length); //debug crap
	const int div = (length*2+1);

		printf("\nx line %d\n",x); //debugging crud
		const typename T1::value_type val=pen.get_value();
		typename T1::accumulator_type tot(val*(length+1));

		for (y=0;y<length && iter!=end;y++,++iter) tot+=*iter;

		for (y=0;y<h && iter!=end;y++,++iter,outpen.inc_y())
			//calling either of these functions here fixes the crash... WTF!!!!!!
			/*if (y>length) tot-=iter[-length-1];
			else tot-=val;

			if (y+length<h) tot+=iter[length];
			else tot+=end[-1];*/
			tot -= (y>length) ? iter[-length-1] : val;
			tot += (y+length<h) ? iter[length] : end[-1];

The pen is basically just a random-access iterator for a 2 dimensional
array (the inc_x and inc_y functions behave exactly as you'd expect). 
The value type it's looking at is basically a vector (actually a color)
with overloaded functions +=, -=, / (among others).  Iterator_y is
basically just a specialized iterator to increment using a stride rather
than 1.

In any case, I'm pretty sure this was not a buffer overrun (at least of
the fault of the pen/iterators), because it worked just fine in previous
versions of gcc, and it's pretty simple and has been tested (I'm going
to disect the pen class in a bit).  Plus that certainly doesn't explain
why forcing a function call will make it not crash.

I would submit a bug, except this certainly isn't very straight forward,
and I can't submit that big of a chunk of my project for testing.... 
Any suggestions?


On Thu, 2004-06-03 at 04:26, Eljay Love-Jensen wrote:
> Hi Adruab,
> A bug like that is usually indicative of a buffer overrun.
> int rgb[3];
> rgb[4] = 7;
> Or of cavalier casting.
> short hue;
> int* p = (int*)&hue;
> *p = 0;
> Without seeing the code (or some sample code that replicates the bug), it 
> would be difficult to guess less likely scenarios.
> HTH,
> --Eljay

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