From 1d22e50899308e2540fb5d1dcc5490d6a31ca035 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 21 May 2019 08:35:26 -0400 Subject: [PATCH] Core/Boot/Boot: Amend use-after-move cases in GenerateFromFile() In terms of order of operations, the move would occur first before the construction of the relevant reader would occur. However, given the local variable 'path' was declared const, this bug actually wouldn't occur, as std::move on a const variable does nothing (in a non-mutable context), resulting in a copy instead, masking this issue. Given this is a bug waiting to happen, we correct the code. --- Source/Core/Core/Boot/Boot.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Source/Core/Core/Boot/Boot.cpp b/Source/Core/Core/Boot/Boot.cpp index 5da27aac5f..3a3f38a7f5 100644 --- a/Source/Core/Core/Boot/Boot.cpp +++ b/Source/Core/Core/Boot/Boot.cpp @@ -155,7 +155,7 @@ BootParameters::GenerateFromFile(std::vector paths, std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower); } - const std::string path = paths.front(); + std::string path = paths.front(); if (paths.size() == 1) paths.clear(); @@ -172,14 +172,16 @@ BootParameters::GenerateFromFile(std::vector paths, if (extension == ".elf") { - return std::make_unique( - Executable{std::move(path), std::make_unique(path)}, savestate_path); + auto elf_reader = std::make_unique(path); + return std::make_unique(Executable{std::move(path), std::move(elf_reader)}, + savestate_path); } if (extension == ".dol") { - return std::make_unique( - Executable{std::move(path), std::make_unique(path)}, savestate_path); + auto dol_reader = std::make_unique(path); + return std::make_unique(Executable{std::move(path), std::move(dol_reader)}, + savestate_path); } if (is_drive)