Do not cache atom name if XInternAtom fails

If `XInternAtom` is called with `onlyIfExists` set, then it can
legitimately return `None`. We should not cache this value because it
might change in the future.

This bug can sometimes be triggered because we use
`getAtom("UTF8_STRING", true)` and `getAtom("UTF8_STRING")`. If the
first call caches `None` because the atom didn't exist, then the
second call could return `None` instead of creating a new atom like it
should.
This commit is contained in:
James Cowgill 2024-11-30 19:29:16 +00:00 committed by Lukas Dürrenberger
parent f88b768ba6
commit ad70442246

View File

@ -129,6 +129,7 @@ Atom getAtom(const std::string& name, bool onlyIfExists)
const auto display = openDisplay(); const auto display = openDisplay();
const Atom atom = XInternAtom(display.get(), name.c_str(), onlyIfExists ? True : False); const Atom atom = XInternAtom(display.get(), name.c_str(), onlyIfExists ? True : False);
if (atom)
atoms[name] = atom; atoms[name] = atom;
return atom; return atom;