I have the following struct
struct NETWORK_ENDPOINT {
unsigned char Type;
unsigned char Protocol;
unsigned char IPv4[IPV4SIZE + 1];
unsigned int PortNumber;
unsigned char SocketIndex;
unsigned char RESERVED;
unsigned char *InboundData;
unsigned int InboundDataSize;
unsigned char *OutboundData;
unsigned int OutboundDataSize;
};
In the code I'm allocating with :
struct NETWORK_ENDPOINT *Endpoint = malloc(sizeof(struct NETWORK_ENDPOINT));
Then later in the code I'm allocating the OutboundData with.
Endpoint->OutboundData = malloc(20); // malloc() size may vary,
// but in the problem situation it is 20
Then I do :
memcpy(Endpoint->OutboundData, Data, 20);
Then the problem : From the debugger I can see that Endpoint
is given address @0x1fd6, and the OutboundData
is given address @0x1fca, so only 12 between. Shouldn't is be atleast 20 ?
The memcpy()
function then will fill out in OutboundData
( can see in memory that data is correctly placed ), but once it passes 12 bytes, it will begin overwriting the start of the struct Endpoint
, corrupting the Type
and Protocol
and half the IP
, thereby making it useless afterwards.
anyone got any idea what I'm going wrong here ? Been working on this for days now, but whatever I try it does not fix this issue...
Have tried to increase the HEAP size, but it seems to stay at 12 bytes between the two memory locations no matter what I do..