From 1bec2a92935d7cb2e47088d00d89b69f25c82967 Mon Sep 17 00:00:00 2001 From: Jesse Talavera Date: Fri, 15 Dec 2023 18:05:43 -0500 Subject: [PATCH] Fix an incorrect use of `std::move` (#1919) - 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 --- src/GBACart.cpp | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/src/GBACart.cpp b/src/GBACart.cpp index 826444b6..37fa0449 100644 --- a/src/GBACart.cpp +++ b/src/GBACart.cpp @@ -755,24 +755,6 @@ std::unique_ptr ParseROM(std::unique_ptr&& romdata, u32 romlen auto [cartrom, cartromsize] = PadToPowerOf2(std::move(romdata), romlen); - std::unique_ptr cartsram; - try - { - cartsram = std::move(sramdata) ? std::make_unique(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); @@ -790,9 +772,9 @@ std::unique_ptr ParseROM(std::unique_ptr&& romdata, u32 romlen std::unique_ptr cart; if (solarsensor) - cart = std::make_unique(std::move(cartrom), cartromsize, std::move(cartsram), sramlen); + cart = std::make_unique(std::move(cartrom), cartromsize, std::move(sramdata), sramlen); else - cart = std::make_unique(std::move(cartrom), cartromsize, std::move(cartsram), sramlen); + cart = std::make_unique(std::move(cartrom), cartromsize, std::move(sramdata), sramlen); cart->Reset();