[Bug Fix] Fix use-after-free corruption with some DB calls (#1335)

This commit is contained in:
Michael Cook (mackal)
2021-04-27 19:53:34 -04:00
committed by GitHub
parent c063d9512e
commit 4358e24dab
6 changed files with 30 additions and 23 deletions
+12 -8
View File
@@ -870,36 +870,40 @@ void Database::GetCharName(uint32 char_id, char* name) {
}
}
const char* Database::GetCharNameByID(uint32 char_id) {
std::string Database::GetCharNameByID(uint32 char_id) {
std::string query = fmt::format("SELECT `name` FROM `character_data` WHERE id = {}", char_id);
auto results = QueryDatabase(query);
std::string res;
if (!results.Success()) {
return "";
return res;
}
if (results.RowCount() == 0) {
return "";
return res;
}
auto row = results.begin();
return row[0];
res = row[0];
return res;
}
const char* Database::GetNPCNameByID(uint32 npc_id) {
std::string Database::GetNPCNameByID(uint32 npc_id) {
std::string query = fmt::format("SELECT `name` FROM `npc_types` WHERE id = {}", npc_id);
auto results = QueryDatabase(query);
std::string res;
if (!results.Success()) {
return "";
return res;
}
if (results.RowCount() == 0) {
return "";
return res;
}
auto row = results.begin();
return row[0];
res = row[0];
return res;
}
bool Database::LoadVariables() {
+2 -2
View File
@@ -138,8 +138,8 @@ public:
void GetAccountName(uint32 accountid, char* name, uint32* oLSAccountID = 0);
void GetCharName(uint32 char_id, char* name);
const char *GetCharNameByID(uint32 char_id);
const char *GetNPCNameByID(uint32 npc_id);
std::string GetCharNameByID(uint32 char_id);
std::string GetNPCNameByID(uint32 npc_id);
void LoginIP(uint32 AccountID, const char* LoginIP);
/* Instancing */