Skip to content

Commit

Permalink
fix warnings of possible overflow after multiplication
Browse files Browse the repository at this point in the history
  • Loading branch information
pionere committed Aug 27, 2024
1 parent d513dd5 commit b2309f5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 46 deletions.
2 changes: 1 addition & 1 deletion tools/patcher/DiabloUI/patcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2009,7 +2009,7 @@ static BYTE* ReEncodeCL2(BYTE* cl2Buf, size_t *dwLen, int numGroups, int frameCo
const BYTE* frameBuf = CelGetFrameStart(cl2Buf, ii);

for (int n = 1; n <= ni; n++) {
memset(&gpBuffer[0], TRANS_COLOR, BUFFER_WIDTH * height);
memset(&gpBuffer[0], TRANS_COLOR, (size_t)BUFFER_WIDTH * height);

Cl2Draw(0, height - 1, frameBuf, n, width);
BYTE* frameSrc = &gpBuffer[0 + (height - 1) * BUFFER_WIDTH];
Expand Down
45 changes: 16 additions & 29 deletions tools/patcher/drlp_l2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,9 @@ DEVILUTION_BEGIN_NAMESPACE

BYTE* DRLP_L2_PatchDoors(BYTE* celBuf, size_t* celLen)
{
typedef struct {
int frameIndex;
int frameWidth;
int frameHeight;
} CelFrame;
const CelFrame frames[] = {
{ 0, 64, 128 },
{ 1, 64, 128 },
};
const int frames[] = { 0, 1 };
constexpr int FRAME_WIDTH = 64;
constexpr int FRAME_HEIGHT = 128;

constexpr BYTE TRANS_COLOR = 128;
constexpr BYTE SUB_HEADER_SIZE = 10;
Expand All @@ -40,11 +34,11 @@ BYTE* DRLP_L2_PatchDoors(BYTE* celBuf, size_t* celLen)

BYTE* dstDataCursor = resCelBuf + 4 * (srcCelEntries + 2);
for (int i = 0; i < srcCelEntries; i++) {
const CelFrame &frame = frames[idx];
if (i == frame.frameIndex) {
const int frameIndex = frames[idx];
if (i == frameIndex) {
// draw the frame to the back-buffer
memset(&gpBuffer[0], TRANS_COLOR, frame.frameHeight * BUFFER_WIDTH);
CelClippedDraw(0, frame.frameHeight - 1, celBuf, frame.frameIndex + 1, frame.frameWidth);
memset(&gpBuffer[0], TRANS_COLOR, FRAME_HEIGHT * BUFFER_WIDTH);
CelClippedDraw(0, FRAME_HEIGHT - 1, celBuf, frameIndex + 1, FRAME_WIDTH);

if (idx == 0) {
for (int y = 44; y < 55; y++) {
Expand All @@ -63,7 +57,7 @@ BYTE* DRLP_L2_PatchDoors(BYTE* celBuf, size_t* celLen)
dstHeaderCursor[0] = SwapLE32((size_t)dstDataCursor - (size_t)resCelBuf);
dstHeaderCursor++;

dstDataCursor = EncodeFrame(dstDataCursor, frame.frameWidth, frame.frameHeight, SUB_HEADER_SIZE, TRANS_COLOR);
dstDataCursor = EncodeFrame(dstDataCursor, FRAME_WIDTH, FRAME_HEIGHT, SUB_HEADER_SIZE, TRANS_COLOR);

// skip the original frame
srcHeaderCursor++;
Expand All @@ -87,16 +81,9 @@ BYTE* DRLP_L2_PatchDoors(BYTE* celBuf, size_t* celLen)

BYTE* DRLP_L2_PatchSpec(BYTE* celBuf, size_t* celLen)
{
typedef struct {
int frameIndex;
int frameWidth;
int frameHeight;
} CelFrame;
const CelFrame frames[] = {
{ 0, 64, 160 },
{ 1, 64, 160 },
{ 4, 64, 160 },
};
const int frames[] = { 0, 1, 4 };
constexpr int FRAME_WIDTH = 64;
constexpr int FRAME_HEIGHT = 160;

constexpr BYTE TRANS_COLOR = 128;
constexpr BYTE SUB_HEADER_SIZE = 10;
Expand All @@ -117,11 +104,11 @@ BYTE* DRLP_L2_PatchSpec(BYTE* celBuf, size_t* celLen)

BYTE* dstDataCursor = resCelBuf + 4 * (srcCelEntries + 2);
for (int i = 0; i < srcCelEntries; i++) {
const CelFrame &frame = frames[idx];
if (i == frame.frameIndex) {
const int frameIndex = frames[idx];
if (i == frameIndex) {
// draw the frame to the back-buffer
memset(&gpBuffer[0], TRANS_COLOR, frame.frameHeight * BUFFER_WIDTH);
CelClippedDraw(0, frame.frameHeight - 1, celBuf, frame.frameIndex + 1, frame.frameWidth);
memset(&gpBuffer[0], TRANS_COLOR, FRAME_HEIGHT * BUFFER_WIDTH);
CelClippedDraw(0, FRAME_HEIGHT - 1, celBuf, frameIndex + 1, FRAME_WIDTH);

if (idx == 0) {
gpBuffer[10 + 52 * BUFFER_WIDTH] = 55;
Expand Down Expand Up @@ -152,7 +139,7 @@ BYTE* DRLP_L2_PatchSpec(BYTE* celBuf, size_t* celLen)
dstHeaderCursor[0] = SwapLE32((size_t)dstDataCursor - (size_t)resCelBuf);
dstHeaderCursor++;

dstDataCursor = EncodeFrame(dstDataCursor, frame.frameWidth, frame.frameHeight, SUB_HEADER_SIZE, TRANS_COLOR);
dstDataCursor = EncodeFrame(dstDataCursor, FRAME_WIDTH, FRAME_HEIGHT, SUB_HEADER_SIZE, TRANS_COLOR);

// skip the original frame
srcHeaderCursor++;
Expand Down
24 changes: 8 additions & 16 deletions tools/patcher/drlp_l3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,9 @@ DEVILUTION_BEGIN_NAMESPACE

BYTE* DRLP_L3_PatchDoors(BYTE* celBuf, size_t* celLen)
{
typedef struct {
int frameIndex;
int frameWidth;
int frameHeight;
} CelFrame;
const CelFrame frames[] = {
{ 0, 64, 128 },
{ 1, 64, 128 },
{ 2, 64, 128 },
{ 3, 64, 128 },
};
const CelFrame frames[] = { 0, 1, 2, 3 };
constexpr int FRAME_WIDTH = 64;
constexpr int FRAME_HEIGHT = 128;

constexpr BYTE TRANS_COLOR = 128;
constexpr BYTE SUB_HEADER_SIZE = 10;
Expand All @@ -42,11 +34,11 @@ BYTE* DRLP_L3_PatchDoors(BYTE* celBuf, size_t* celLen)

BYTE* dstDataCursor = resCelBuf + 4 * (srcCelEntries + 2);
for (int i = 0; i < srcCelEntries; i++) {
const CelFrame &frame = frames[idx];
if (i == frame.frameIndex) {
const int frameIndex = frames[idx];
if (i == frameIndex) {
// draw the frame to the back-buffer
memset(&gpBuffer[0], TRANS_COLOR, frame.frameHeight * BUFFER_WIDTH);
CelClippedDraw(0, frame.frameHeight - 1, celBuf, frame.frameIndex + 1, frame.frameWidth);
memset(&gpBuffer[0], TRANS_COLOR, FRAME_HEIGHT * BUFFER_WIDTH);
CelClippedDraw(0, FRAME_HEIGHT - 1, celBuf, frameIndex + 1, FRAME_WIDTH);

if (idx == 0) {
// add shadows
Expand Down Expand Up @@ -359,7 +351,7 @@ BYTE* DRLP_L3_PatchDoors(BYTE* celBuf, size_t* celLen)
dstHeaderCursor[0] = SwapLE32((size_t)dstDataCursor - (size_t)resCelBuf);
dstHeaderCursor++;

dstDataCursor = EncodeFrame(dstDataCursor, frame.frameWidth, frame.frameHeight, SUB_HEADER_SIZE, TRANS_COLOR);
dstDataCursor = EncodeFrame(dstDataCursor, FRAME_WIDTH, FRAME_HEIGHT, SUB_HEADER_SIZE, TRANS_COLOR);

// skip the original frame
srcHeaderCursor++;
Expand Down

0 comments on commit b2309f5

Please sign in to comment.