diff options
author | Florent Le Coz <louiz@louiz.org> | 2015-10-26 20:35:10 +0100 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2015-10-28 02:32:19 +0100 |
commit | 4e32fe213cccdc6cdc1dcba498fd74b8b97703ea (patch) | |
tree | 75ac4c332858ecba18253c58bb4e6197f744f58c /louloulibs/xmpp | |
parent | 450de4c33615fc8cd14bf3a7854ee615ed53df1c (diff) | |
download | biboumi-4e32fe213cccdc6cdc1dcba498fd74b8b97703ea.tar.gz biboumi-4e32fe213cccdc6cdc1dcba498fd74b8b97703ea.tar.bz2 biboumi-4e32fe213cccdc6cdc1dcba498fd74b8b97703ea.tar.xz biboumi-4e32fe213cccdc6cdc1dcba498fd74b8b97703ea.zip |
Refactor XmppParser::end_element to make it clearer
Both for me, and apparently for clang static analyzer, who reported a (imo)
false positive.
Diffstat (limited to 'louloulibs/xmpp')
-rw-r--r-- | louloulibs/xmpp/xmpp_parser.cpp | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/louloulibs/xmpp/xmpp_parser.cpp b/louloulibs/xmpp/xmpp_parser.cpp index f44d49a..25f2876 100644 --- a/louloulibs/xmpp/xmpp_parser.cpp +++ b/louloulibs/xmpp/xmpp_parser.cpp @@ -104,20 +104,24 @@ void XmppParser::start_element(const XML_Char* name, const XML_Char** attribute) void XmppParser::end_element(const XML_Char*) { this->level--; - if (this->level == 1) - { - this->stanza_event(*this->current_node); - } if (this->level == 0) - { + { // End of the whole stream this->stream_close_event(*this->current_node); this->current_node = nullptr; this->root.reset(); } else - this->current_node = this->current_node->get_parent(); - if (this->level == 1) - this->current_node->delete_all_children(); + { + auto parent = this->current_node->get_parent(); + if (this->level == 1) + { // End of a stanza + this->stanza_event(*this->current_node); + // Note: deleting all the children of our parent deletes ourself, + // so current_node is an invalid pointer after this line + this->current_node->get_parent()->delete_all_children(); + } + this->current_node = parent; + } } void XmppParser::char_data(const XML_Char* data, int len) |