1
0
Fork 0

Codefix: potential dangling pointer in strgen

pull/13171/merge
Rubidium 2025-03-12 20:03:20 +01:00 committed by rubidium42
parent 0fde979b21
commit d96f359b3c
2 changed files with 9 additions and 9 deletions

View File

@ -39,16 +39,16 @@ struct LangString {
/** Information about the currently known strings. */
struct StringData {
std::vector<std::unique_ptr<LangString>> strings; ///< List of all known strings.
std::unordered_map<std::string_view, LangString *> name_to_string; ///< Lookup table for the strings.
std::vector<std::shared_ptr<LangString>> strings; ///< List of all known strings.
std::unordered_map<std::string, std::shared_ptr<LangString>> name_to_string; ///< Lookup table for the strings.
size_t tabs; ///< The number of 'tabs' of strings.
size_t max_strings; ///< The maximum number of strings.
size_t next_string_id;///< The next string ID to allocate.
StringData(size_t tabs);
void FreeTranslation();
void Add(std::unique_ptr<LangString> ls);
LangString *Find(const std::string_view s);
void Add(std::shared_ptr<LangString> ls);
LangString *Find(const std::string &s);
uint VersionHashStr(uint hash, const char *s) const;
uint Version() const;
uint CountInUse(uint tab) const;

View File

@ -85,10 +85,10 @@ void StringData::FreeTranslation()
* @param s The name of the string.
* @param ls The string to add.
*/
void StringData::Add(std::unique_ptr<LangString> ls)
void StringData::Add(std::shared_ptr<LangString> ls)
{
this->name_to_string[ls->name] = ls.get();
this->strings[ls->index].swap(ls);
this->name_to_string[ls->name] = ls;
this->strings[ls->index] = std::move(ls);
}
/**
@ -96,12 +96,12 @@ void StringData::Add(std::unique_ptr<LangString> ls)
* @param s The string name to search on.
* @return The LangString or nullptr if it is not known.
*/
LangString *StringData::Find(const std::string_view s)
LangString *StringData::Find(const std::string &s)
{
auto it = this->name_to_string.find(s);
if (it == this->name_to_string.end()) return nullptr;
return it->second;
return it->second.get();
}
/**