From f7ceadf6dcde43e4539a81ff6d0ce65c0bb52dcd Mon Sep 17 00:00:00 2001 From: Nam Nguyen Date: Mon, 9 Sep 2019 05:52:31 +0000 Subject: [PATCH] pack the TMegaPkt struct. define TMEGAPKT_SIZE. memcpy((char *)&packeta[1] - packeta->dwSpaceLeft, packet, dwSize); Source/msg.cpp does this calculation, which will be wrong if any padding is added. To get this to work correctly, pack the structures, as suggested by @AJenbo. Also, define TMEGAPKT_SIZE because pNext can be 4 or 8 bytes. --- Source/msg.cpp | 2 +- structs.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Source/msg.cpp b/Source/msg.cpp index a6f68f9d6..662f3855c 100644 --- a/Source/msg.cpp +++ b/Source/msg.cpp @@ -55,7 +55,7 @@ TMegaPkt *msg_get_next_packet() { TMegaPkt *result; - sgpCurrPkt = (TMegaPkt *)DiabloAllocPtr(32008); + sgpCurrPkt = (TMegaPkt *)DiabloAllocPtr(TMEGAPKT_SIZE); sgpCurrPkt->pNext = NULL; sgpCurrPkt->dwSpaceLeft = 32000; diff --git a/structs.h b/structs.h index 622e2085f..0191eb723 100644 --- a/structs.h +++ b/structs.h @@ -955,11 +955,14 @@ typedef struct DJunk { } DJunk; #pragma pack(pop) +#pragma pack(push, 1) typedef struct TMegaPkt { struct TMegaPkt *pNext; DWORD dwSpaceLeft; BYTE data[32000]; } TMegaPkt; +#pragma pack(pop) +#define TMEGAPKT_SIZE sizeof(TMegaPkt) typedef struct TBuffer { DWORD dwNextWriteOffset;