From 1d38e473d768dc2a37b90c43f263748adf5592c6 Mon Sep 17 00:00:00 2001 From: Alex King <89047260+Kinglykrab@users.noreply.github.com> Date: Sat, 2 Mar 2024 16:18:57 -0500 Subject: [PATCH] [Bug Fix] GetBotNameByID Temporary Reference Warning (#4145) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Notes - We were getting a warning for returning `std::string()` from this method as it's a temporary reference. - Change from `const std::string&` to `const std::string` to avoid this. ``` /home/eqemu/source/zone/bot_database.cpp: In member function ‘const std::string& BotDatabase::GetBotNameByID(uint32)’: /home/eqemu/source/zone/bot_database.cpp:2374:25: warning: returning reference to temporary [-Wreturn-local-addr] 2374 | return e.bot_id ? e.name : std::string(); ``` --- zone/bot_database.cpp | 2 +- zone/bot_database.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/zone/bot_database.cpp b/zone/bot_database.cpp index 3ae90b68b..f43bde970 100644 --- a/zone/bot_database.cpp +++ b/zone/bot_database.cpp @@ -2367,7 +2367,7 @@ const uint8 BotDatabase::GetBotLevelByID(const uint32 bot_id) return e.bot_id ? e.level : 0; } -const std::string& BotDatabase::GetBotNameByID(const uint32 bot_id) +const std::string BotDatabase::GetBotNameByID(const uint32 bot_id) { const auto& e = BotDataRepository::FindOne(database, bot_id); diff --git a/zone/bot_database.h b/zone/bot_database.h index 0a03fa60e..5758a5bf1 100644 --- a/zone/bot_database.h +++ b/zone/bot_database.h @@ -164,7 +164,7 @@ public: const uint8 GetBotGenderByID(const uint32 bot_id); std::vector GetBotIDsByCharacterID(const uint32 character_id, uint8 class_id = Class::None); const uint8 GetBotLevelByID(const uint32 bot_id); - const std::string& GetBotNameByID(const uint32 bot_id); + const std::string GetBotNameByID(const uint32 bot_id); const uint16 GetBotRaceByID(const uint32 bot_id); class fail {