Skip to content

Commit

Permalink
Fix an incorrect use of std::move (#1919)
Browse files Browse the repository at this point in the history
- When I adapted `GBACart::ParseROM` to use `unique_ptr` instead of a plain pointer, I forgot to remove the code that copied the SRAM data
- That code was made unnecessary because of the move
  • Loading branch information
JesseTG authored Dec 15, 2023
1 parent eedb0ba commit 1bec2a9
Showing 1 changed file with 2 additions and 20 deletions.
22 changes: 2 additions & 20 deletions src/GBACart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,24 +755,6 @@ std::unique_ptr<CartCommon> ParseROM(std::unique_ptr<u8[]>&& romdata, u32 romlen

auto [cartrom, cartromsize] = PadToPowerOf2(std::move(romdata), romlen);

std::unique_ptr<u8[]> cartsram;
try
{
cartsram = std::move(sramdata) ? std::make_unique<u8[]>(sramlen) : nullptr;
}
catch (const std::bad_alloc& e)
{
Log(LogLevel::Error, "GBACart: failed to allocate memory for ROM (%d bytes)\n", cartromsize);

return nullptr;
}

if (cartsram)
{
memset(cartsram.get(), 0, sramlen);
memcpy(cartsram.get(), sramdata.get(), sramlen);
}

char gamecode[5] = { '\0' };
memcpy(&gamecode, cartrom.get() + 0xAC, 4);

Expand All @@ -790,9 +772,9 @@ std::unique_ptr<CartCommon> ParseROM(std::unique_ptr<u8[]>&& romdata, u32 romlen

std::unique_ptr<CartCommon> cart;
if (solarsensor)
cart = std::make_unique<CartGameSolarSensor>(std::move(cartrom), cartromsize, std::move(cartsram), sramlen);
cart = std::make_unique<CartGameSolarSensor>(std::move(cartrom), cartromsize, std::move(sramdata), sramlen);
else
cart = std::make_unique<CartGame>(std::move(cartrom), cartromsize, std::move(cartsram), sramlen);
cart = std::make_unique<CartGame>(std::move(cartrom), cartromsize, std::move(sramdata), sramlen);

cart->Reset();

Expand Down

0 comments on commit 1bec2a9

Please sign in to comment.