mirror of https://github.com/OpenTTD/OpenTTD
Codefix: potential dangling pointer in strgen
parent
0fde979b21
commit
d96f359b3c
|
@ -39,16 +39,16 @@ struct LangString {
|
||||||
|
|
||||||
/** Information about the currently known strings. */
|
/** Information about the currently known strings. */
|
||||||
struct StringData {
|
struct StringData {
|
||||||
std::vector<std::unique_ptr<LangString>> strings; ///< List of all known strings.
|
std::vector<std::shared_ptr<LangString>> strings; ///< List of all known strings.
|
||||||
std::unordered_map<std::string_view, LangString *> name_to_string; ///< Lookup table for the 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 tabs; ///< The number of 'tabs' of strings.
|
||||||
size_t max_strings; ///< The maximum number of strings.
|
size_t max_strings; ///< The maximum number of strings.
|
||||||
size_t next_string_id;///< The next string ID to allocate.
|
size_t next_string_id;///< The next string ID to allocate.
|
||||||
|
|
||||||
StringData(size_t tabs);
|
StringData(size_t tabs);
|
||||||
void FreeTranslation();
|
void FreeTranslation();
|
||||||
void Add(std::unique_ptr<LangString> ls);
|
void Add(std::shared_ptr<LangString> ls);
|
||||||
LangString *Find(const std::string_view s);
|
LangString *Find(const std::string &s);
|
||||||
uint VersionHashStr(uint hash, const char *s) const;
|
uint VersionHashStr(uint hash, const char *s) const;
|
||||||
uint Version() const;
|
uint Version() const;
|
||||||
uint CountInUse(uint tab) const;
|
uint CountInUse(uint tab) const;
|
||||||
|
|
|
@ -85,10 +85,10 @@ void StringData::FreeTranslation()
|
||||||
* @param s The name of the string.
|
* @param s The name of the string.
|
||||||
* @param ls The string to add.
|
* @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->name_to_string[ls->name] = ls;
|
||||||
this->strings[ls->index].swap(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.
|
* @param s The string name to search on.
|
||||||
* @return The LangString or nullptr if it is not known.
|
* @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);
|
auto it = this->name_to_string.find(s);
|
||||||
if (it == this->name_to_string.end()) return nullptr;
|
if (it == this->name_to_string.end()) return nullptr;
|
||||||
|
|
||||||
return it->second;
|
return it->second.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue