clone cached string resources

don't share object references, need to be passed as new copies as the
array contents can be modified

need to clone on dict return to not pollute dict, and need to clone
after dict add so that the first return doesn't equal the dict copy --
this one could be on the dict add... keep returns same.
This commit is contained in:
Kurt 2017-11-07 17:12:04 -08:00
parent d08bd25b4f
commit 9af0876352

View file

@ -78,7 +78,7 @@ namespace PKHeX.Core
public static string[] GetStringList(string f)
{
if (stringListCache.ContainsKey(f))
return stringListCache[f];
return (string[])stringListCache[f].Clone();
var txt = GetStringResource(f); // Fetch File, \n to list.
if (txt == null) return new string[0];
@ -86,7 +86,7 @@ namespace PKHeX.Core
for (int i = 0; i < rawlist.Length; i++)
rawlist[i] = rawlist[i].Trim();
stringListCache.Add(f, rawlist);
return rawlist;
return (string[])rawlist.Clone();
}
public static string[] GetStringList(string f, string l, string type = "text") => GetStringList($"{type}_{f}_{l}");
public static string[] GetNulledStringArray(string[] SimpleStringList)