Skip to content

Commit

Permalink
more explicit protection of memcpy
Browse files Browse the repository at this point in the history
  • Loading branch information
bbbradsmith committed Mar 30, 2024
1 parent a8b1cee commit 643888a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions xgm/devices/Memory/nes_bank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,16 @@ namespace xgm
bankmax = (total_size >> 12); // count of full banks
if (total_size & 0xfff) bankmax += 1; // include last partial bank
if (bankmax > 256) bankmax = 256;
UINT32 image_size = 0x1000 * bankmax;

if (image)
delete[]image;
image = new UINT8[0x1000 * bankmax];
memset (image, 0, 0x1000 * bankmax);
image = new UINT8[image_size];
memset (image, 0, image_size);

UINT32 start = offset & 0xfff;
if ((start + size) > image_size)
size = image_size;
memcpy (image + (offset & 0xfff), data, size);

#if FDS_MEMCPY
Expand Down

0 comments on commit 643888a

Please sign in to comment.