void BStrListRec(SFile * F,FHand Targ,FHand ** Pos,unsigned int * Count)
{
if ((*Count)==0) return;
// Read the data required...
FBTPacket T;
F->Read(Targ,&T,BLOCK_32);
// Now proccess it all...
if (T.Left!=0xFFFFFFFF) {Log.Add(LOG_MIS,"Going left");BStrListRec(F,T.Left,Pos,Count); Log.Add(LOG_MIS,"Gone left");}
if (T.Ownership==-1)
{
Log.Add(LOG_MIS,"Adding to list");
(**Pos) = T.Target;
(*Pos)++;
(*Count)--;
}
if (T.Right!=0xFFFFFFFF) {Log.Add(LOG_MIS,"Going right");BStrListRec(F,T.Right,Pos,Count); Log.Add(LOG_MIS,"Gone right");}
Log.Add(LOG_MIS,"Going up");
}
FHand * BStrList(SFile * Targ,FHand First,unsigned int Count)
{
if (First==0xFFFFFFFF) return 0;
FHand * Data = (FHand*)malloc(Count*sizeof(FHand));
if (Data==0) return 0;
memset(Data,0xFFFFFFFF,Count*sizeof(FHand));
FHand * Pos = Data;
Log.Add(LOG_MIS,"Starting recursion");
BStrListRec(Targ,First,&Pos,&Count);
Log.Add(LOG_MIS,"Done recursion");
return Data;
}
As you can probably figgure out, it''s going through a binary tree, the next thing will make you think you know the error-
>Small stack size it crashes ''instantly''.
>Large stack size it takes a while.
ie stack overflow, due to never returning, but if you look at the log file-
For 1 entry in the tree-
Mis: Tue Jan 16 18:00:01 2001; Starting recursion
Mis: Tue Jan 16 18:00:01 2001; Adding to list
Mis: Tue Jan 16 18:00:01 2001; Going up
For multiple entrys in the tree-
Mis: Tue Jan 16 18:48:48 2001; Starting recursion
Mis: Tue Jan 16 18:48:48 2001; Going left
Mis: Tue Jan 16 18:48:48 2001; Adding to list
Mis: Tue Jan 16 18:48:48 2001; Going right
Mis: Tue Jan 16 18:48:48 2001; Adding to list
Mis: Tue Jan 16 18:48:48 2001; Going right
Mis: Tue Jan 16 18:48:48 2001; Adding to list
Mis: Tue Jan 16 18:48:48 2001; Going up
In other words, it''s not going on forever, though thats what the signs show. So what now? Problem with compiler - checked it, same ''error'' on both windows and linux. (Note it dosn''t say ''stackoverflow'' on windows, as it''s being tested as a console app.)
If anyone has the faintest idea, I would really appreciate some help... Thanks in advance.
-Lethe
Crazy bug... with big teeth... and a nose...
Ok - this one will probably give you nightmares, but I''ll scare you all anyway
Few notes about code - uses a set of speciall libarys, it''s fairly obvious whats happenning, but FHand''s that equall 0xFFFFFFFF are null.Allso, the count thing shouldn''t need to be, and neither should the loggin - it''s just there as debbugging. Oh, and a try catch(...) has no effect.
Code-
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement