windows triggered breakpoint due to corruption of heap
laxman (1)
Nov 4, 2009 at 9:33am UTC
Hi,
I was implementing queue in some pre-written program.
There I get this heap corruption error. I predict the error might be
of array index overflow..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
// global declaration
#define MAX_LIST 20
int front=0, rear=0;
typedef struct byteslog
{
ULONG serverCode;
long totalBytes;
}byteslog;
byteslog ser[MAX_LIST];
void
pushToQ(ULONG code, long sentbytes, long recvbytes)
{
if (rear >= MAX_LIST)
{
//debug("Queue overflow");
return ;
}
for (int i=0; i<MAX_LIST; i++)
{
// if server is already added just update bytes
if (ser[i].serverCode == code)
{
ser[i].totalBytes=(sentbytes+recvbytes)/512;
return ;
}
}
// add server and update bytes
ser[rear].serverCode=code;
ser[rear].totalBytes=(sentbytes+recvbytes)/512;
rear++;
}
Any corrections ??
toro (2)
Nov 6, 2009 at 9:24am UTC
If (rear >= MAX_LIST) and there is no element with that code in the list, the last lines are executed.
Possible solution: put the second part of the code in a else {...}.
Last edited on Nov 6, 2009 at 9:25am UTC
Zhuge (2205)
Nov 7, 2009 at 2:02am UTC
The if statement returns from the function, so that isn't it. I don't see anything that could result in array index problems, but...
EDIT: Also, it seems like maybe a map would be better for what you seem to be doing here; let the key be the code.
Last edited on Nov 7, 2009 at 2:03am UTC
toro (2)
Nov 13, 2009 at 4:00pm UTC
@Zhuge: You are correct.
@laxman: Maybe the function is called from different threads?
Topic archived. No new replies allowed.