[qfcc] Make save_string null-safe

It simply returns nullptr when the saved string is null.
This commit is contained in:
Bill Currie 2024-07-07 15:18:51 +09:00
parent 628e3d2aed
commit f2609b1a9b

View file

@ -139,12 +139,16 @@ ss_get_key (const void *s, void *unused)
const char * const char *
save_string (const char *str) save_string (const char *str)
{ {
char *s; if (!str) {
if (!saved_strings) return nullptr;
}
if (!saved_strings) {
saved_strings = Hash_NewTable (16381, ss_get_key, 0, 0, 0); saved_strings = Hash_NewTable (16381, ss_get_key, 0, 0, 0);
s = Hash_Find (saved_strings, str); }
if (s) char *s = Hash_Find (saved_strings, str);
if (s) {
return s; return s;
}
s = strdup (str); s = strdup (str);
Hash_Add (saved_strings, s); Hash_Add (saved_strings, s);
return s; return s;