[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi] xmlwrapp '-Wnull-dereference' warning
From: |
Greg Chicares |
Subject: |
[lmi] xmlwrapp '-Wnull-dereference' warning |
Date: |
Fri, 22 Mar 2019 00:23:21 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 |
Enabling '-Wnull-dereference' for lmi builds, I found:
In file included from /opt/lmi/src/lmi/xml_xslt_wrapp.cpp:35:0:
/opt/lmi/third_party/src/libxml/node_manip.cxx: In member function
'xml::node::iterator xml::node::
erase(const xml::node::iterator&)':
/opt/lmi/third_party/src/libxml/node_manip.cxx:140:16: error: potential null
pointer dereference [-Werror=null-dereference]
xmlNodePtr after = to_erase->next;
^~~~~
This simple patch avoids the warning, although...
- I'm not sure it's right (I'm guessing that this is a C-language
linked list inside libxml2, whose end is a null pointer)
- this may not be stylistically consonant with the rest of xmlwrapp,
e.g., because '0' is used elsewhere in this file where I've written
'nullptr'
---------8<--------8<--------8<--------8<--------8<--------8<--------8<-------
diff -U3 /opt/lmi/third_party/src/libxml/node_manip.cxx ./node_manip.cxx
--- /opt/lmi/third_party/src/libxml/node_manip.cxx 2018-03-06
00:27:08.000000000 +0000
+++ ./node_manip.cxx 2019-03-22 00:06:17.520438989 +0000
@@ -137,7 +137,7 @@
xmlNodePtr xml::impl::node_erase(xmlNodePtr to_erase)
{
- xmlNodePtr after = to_erase->next;
+ xmlNodePtr after = to_erase ? to_erase->next : nullptr;
xmlUnlinkNode(to_erase);
xmlFreeNode(to_erase);
--------->8-------->8-------->8-------->8-------->8-------->8-------->8-------
I also wonder whether a change like this would be desirable:
-#include "node_manip.h"
+#include "libxml/node_manip.h"
or
+#include <libxml/node_manip.h>
because a few lines later I see <libxml/another-header.h>:
// libxml includes
#include <libxml/tree.h>
- [lmi] xmlwrapp '-Wnull-dereference' warning,
Greg Chicares <=
- [lmi] xmlwrapp '-Wswitch-enum' warning [Was: xmlwrapp '-Wnull-dereference' warning], Greg Chicares, 2019/03/21
- [lmi] xmlwrapp '-Wconversion' warnings [Was: xmlwrapp '-Wnull-dereference' warning], Greg Chicares, 2019/03/23
- Re: [lmi] xmlwrapp '-Wconversion' warnings, Vadim Zeitlin, 2019/03/24
- Re: [lmi] xmlwrapp '-Wconversion' warnings, Greg Chicares, 2019/03/24
- Re: [lmi] xmlwrapp '-Wconversion' warnings, Vadim Zeitlin, 2019/03/26
- Re: [lmi] xmlwrapp '-Wconversion' warnings, Greg Chicares, 2019/03/26
- Re: [lmi] xmlwrapp '-Wconversion' warnings, Vadim Zeitlin, 2019/03/27
- Re: [lmi] xmlwrapp '-Wconversion' warnings, Greg Chicares, 2019/03/27