diff options
author | David Robillard <d@drobilla.net> | 2019-03-30 20:13:48 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2019-03-30 20:23:43 +0100 |
commit | c0a3fc67642385626e1b6093844272cee0a3ea77 (patch) | |
tree | aa59f72ed9f1b1e0673b68f1d13f8cd3c956e258 /lv2/atom/forge.h | |
parent | a5486dbf5e1ae2fe0f2a8d8cc248a351794b97a1 (diff) | |
download | lv2-c0a3fc67642385626e1b6093844272cee0a3ea77.tar.xz |
Fix crash when forging containers into a short buffer
Diffstat (limited to 'lv2/atom/forge.h')
-rw-r--r-- | lv2/atom/forge.h | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/lv2/atom/forge.h b/lv2/atom/forge.h index e866b38..5bcd816 100644 --- a/lv2/atom/forge.h +++ b/lv2/atom/forge.h @@ -176,7 +176,11 @@ lv2_atom_forge_push(LV2_Atom_Forge* forge, { frame->parent = forge->stack; frame->ref = ref; - forge->stack = frame; + + if (ref) { + forge->stack = frame; // Don't push, so walking the stack is always safe + } + return ref; } @@ -184,8 +188,12 @@ lv2_atom_forge_push(LV2_Atom_Forge* forge, static inline void lv2_atom_forge_pop(LV2_Atom_Forge* forge, LV2_Atom_Forge_Frame* frame) { - assert(frame == forge->stack); - forge->stack = frame->parent; + if (frame->ref) { + // If frame has a valid ref, it must be the top of the stack + assert(frame == forge->stack); + forge->stack = frame->parent; + } + // Otherwise, frame was not pushed because of overflow, do nothing } /** Return true iff the top of the stack has the given type. */ |