aboutsummaryrefslogtreecommitdiff
path: root/src/NDSCart.cpp
diff options
context:
space:
mode:
authorJesse Talavera <jesse@jesse.tg>2023-12-15 08:56:10 -0500
committerGitHub <noreply@github.com>2023-12-15 14:56:10 +0100
commite1821d00235d33b2fe384fffa7e34b00b7af3ec9 (patch)
treed3d02ec34f90c72dbe50805e94923af7337f2966 /src/NDSCart.cpp
parent24c402af51fe9c0537582173fc48d1ad3daff459 (diff)
Simplify the SRAM's representation in `NDSCartArgs` (#1914)
* Simplify the SRAM's representation in `NDSCartArgs` - I overthought this one. - I could've just checked `args && args->SRAM`, but then some other poor bastard might make this mistake. - Don't mix `pair`, `optional`, and `unique_ptr` all at once, kids. * Fix a `nullptr` read
Diffstat (limited to 'src/NDSCart.cpp')
-rw-r--r--src/NDSCart.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/NDSCart.cpp b/src/NDSCart.cpp
index 1f2fe69..a5fe318 100644
--- a/src/NDSCart.cpp
+++ b/src/NDSCart.cpp
@@ -404,7 +404,11 @@ CartRetail::CartRetail(std::unique_ptr<u8[]>&& rom, u32 len, u32 chipid, bool ba
{ // Copy in what we can, truncate the rest.
SRAM = std::make_unique<u8[]>(SRAMLength);
memset(SRAM.get(), 0xFF, SRAMLength);
- memcpy(SRAM.get(), sram.get(), std::min(sramlen, SRAMLength));
+
+ if (sram)
+ { // If we have anything to copy, that is.
+ memcpy(SRAM.get(), sram.get(), std::min(sramlen, SRAMLength));
+ }
}
}
@@ -1650,7 +1654,8 @@ std::unique_ptr<CartCommon> ParseROM(std::unique_ptr<u8[]>&& romdata, u32 romlen
}
std::unique_ptr<CartCommon> cart;
- auto [sram, sramlen] = args ? std::move(*args->SRAM) : std::make_pair(nullptr, 0);
+ std::unique_ptr<u8[]> sram = args ? std::move(args->SRAM) : nullptr;
+ u32 sramlen = args ? args->SRAMLength : 0;
if (homebrew)
cart = std::make_unique<CartHomebrew>(std::move(cartrom), cartromsize, cartid, romparams, args ? std::move(args->SDCard) : std::nullopt);
else if (gametitle[0] == 0 && !strncmp("SD/TF-NDS", gametitle + 1, 9) && gamecode == 0x414D5341)