Repository navigation
Conversation
Moving or swapping a basic_pbf_writer that has an open submessage leaves the sub-writer pointing to the moved-from object. In debug builds this later fails with an unrelated assert, in release builds it silently produces a corrupt message. Assert in the move constructor and swap() instead. We also add assert_tests, where a failed assert ends the process and we check for the correct assert being triggered in case of API misuse.
|
A move that only works sometimes isn't great. But I don't have an idea either how to do the move with an open submessage. Regarding the assertion tests: Without looking too much into the details, it seems all rather complex for not many cases. There isn't much need for functions being "noexcept", destructors, move and swap are really the only cases where this is important. What about making all the "noexcept"s for functions with |
|
Fair; the setup is a bit heavy for four tests. I'd still rather not make The annoying part is really the hand-maintained list of test names in As for the move: I also don't see a good way to make it always work without adding a back-pointer from parent to child, which would make every writer bigger. Since we already disallow adding fields to a parent while a submessage is open, I think "don't move a writer with an open submessage" is a reasonable precondition along the same lines. |
Moving or swapping a
basic_pbf_writerthat has an open submessage leaves the sub-writer pointing to the moved-from object. In debug builds this later fails with an unrelated assert, in release builds it silently produces a corrupt message.The "fix" is to assert in the move constructor and swap() instead, and prohibit moving writers with an open submessage.
This PR also adds assertion tests, where a failed assert ends the process and we check for the correct assert being triggered in case of API misuse. This is the first place where we're checking that we fire the correct assertions in case of API misuse, but I think we should extend this pattern to other places to ensure we're correctly hitting them in case of misuse. WDYT, @joto?