please fix the HEAP CORRUPTION DETECTED error

I run a growtopia private server and have been recently getting server crashes
due to HEAP CORRUPTION DETECTED error when joining certain worlds.

The code is here on pastebin: https://pastebin.com/QqwqjusB
can someone please fix the issue and reupload to a new paste?

it would be incredibly helpful as my main coder is in the hospital and I don't understand c++ good at all....
If the array only has a size of 69 bytes, then surely lines like
1
2
3
4
5
        memcpy(data + 66, &loled, 4);
        memcpy(data + 68, &state, 4);

        memcpy(data + 67, &yeetus, 5);
        memcpy(data + 68, &state, 4);

are all going out of bounds.

Also, you should delete[] a new[]'d array, not just delete.
i.e. delete[] data;

Btw, I assume some sort of clean up is needed to free the data presumably created by the enet_packet_create call.

That code looks as if a troll made it.
Last edited on
> memcpy(data + 67, &yeetus, 5);
> memcpy(data + 68, &state, 4);
You have some very strange offsets and lengths.

First, let's assume that int's are 4 bytes on your machine, and that the endians of the peer machines is the same (see https://en.wikipedia.org/wiki/Endianness )

So,
1 - yeetus is only 4 bytes, but you copy 5
2 - you lose most of yeetus when you overwrite it with state

EDIT:
It's 4 (FOUR) not 5 - meh, thanks ne555
Last edited on
> Also, you should delete[] a new[]'d array,
or, as the size is known at compile time, don't use dynamic memory allocation
BYTE data[69];

> yeetus is only 5 bytes, but you copy 5
¿? ¿why that would be a problem?
It looks like data is the data portion of a packet of some sort. Do you know the format of that packet? Without knowing what the format is supposed to be, it's hard to know how to fix the problems.
Topic archived. No new replies allowed.