Problems with a for loop

Status
Not open for further replies.

pugboy3

BSOD
Messages
4
I am writting a rather complicated little node based tree and trying to iterate over the full and untouched set of n before the dijkstra implementation - seen here in pseudo code form : http://en.wikipedia.org/wiki/Dijkstra's_algorithm#Algorithm can complete full running.

Anyway - the current code I have is as follows:

for (loop=0; loop<NLOOP; loop++)
{
for (pass=0; pass<NPASS; pass++)
{
for (subpass=0; subpass<SUBP; subpass++)
{
for (i=0; i<MAXP; i++)
{
int rno = rand();
if (rno & 8)
{
if (pointers)
{
if (!(rno & realloc_mask))
{
r = rsize();
curmax -= size;
curmax += r;
pointers = realloc(pointers, rsize());
size = r;
if (absmax < curmax) absmax = curmax;
}
else
{
curmax -= size;
free(pointers);
pointers = 0;
}
}
else
{
r = rsize();
curmax += r;
pointers = malloc(r);
size = r;
if (absmax < curmax) absmax = curmax;
}
}
}
}
}

There is something odd about the curmax variable on the 76th and 95 iteration where it infact equals !=0.

Any ideas - im desperate.

Rolf
 
Good day to you Sir,

I observe that your code is indeed somewhat flawed in numerous occurring places. Please check your indentation, and recompile. This fixes numerous bugs and errors for me even including that somewhat elusive error of the most awful buffer overrun.

Also allocating memory in C is a sure fire Savoy Grill recipe for disaster. One must consider not just the implications of the memory allocation, but remember this: You must free not just the memory, but the whole object.

I hope my assistance is valued,

A Former Prime Minister.
 
christ - ofcourse the whole object hence the invalid memory seeks to 0x45baaaaaa

Dam.

Thatcher - thanks so much, you are a downright legend.

One other problem I am experiancing is that the line:

for (subpass=0; subpass<SUBP; subpass++)

seems to never get executed. Somebody told me to attempt a pin dial drop on it - but this got washed under the execution path of the seventeen void statements above it.

Confused :S
 
Status
Not open for further replies.
Back
Top Bottom