Serialize: Don't dereference unfilled pointers after a load fails

Containers of pointers are filled with nullptr and then DoClass'd, and
once an error switches the load to MODE_NOOP, every remaining element
called DoState on null.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
Henrik RydgårdandClaude Opus 5.5 committed 2026-09-28 09:34:06 -06:00
1 parent d6c74156b1
commit 7fa6be6a25
1 file changed
+5
+5
View File
@@ -66,6 +66,9 @@ void DoClass(PointerWrap &p, T *&x) {
if (p.mode == PointerWrap::MODE_READ) {
delete x;
x = new T();
} else if (p.mode == PointerWrap::MODE_NOOP && !x) {
// A load that failed partway leaves the rest of a container unfilled.
return;
}
x->DoState(p);
}
@@ -76,6 +79,8 @@ void DoSubClass(PointerWrap &p, T *&x, Args... args) {
if (x != nullptr)
delete x;
x = new S(args...);
} else if (p.mode == PointerWrap::MODE_NOOP && !x) {
return;
}
x->DoState(p);
}