Fix bug in traversing pkgmgr-info lists again 45/35845/1
authorYoumin Ha <youmin.ha@samsung.com>
Wed, 25 Feb 2015 09:42:58 +0000 (18:42 +0900)
committerYoumin Ha <youmin.ha@samsung.com>
Wed, 25 Feb 2015 09:45:55 +0000 (18:45 +0900)
Same issue to a5cb75ca.
This commit prevents segfault from accessing null pointer.

Change-Id: I0aac62923a5948f067c54b05b3edb88d39736c0e
Signed-Off-By: Youmin Ha <youmin.ha@samsung.com>
src/common/step/step_generate_xml.cc

index b367584..cd2b791 100644 (file)
 
 #include "common/utils.h"
 
+#define PKGMGR_LIST_MOVE_NODE_TO_HEAD(list, node) do {                        \
+    if (list) { LISTHEAD(list, node); }                                       \
+  } while (0)
+
 namespace fs = boost::filesystem;
 
 namespace common_installer {
@@ -201,11 +205,11 @@ Step::Status StepGenerateXml::process() {
 
   // add privilege element
   privileges_x *pvlg;
-  LISTHEAD(context_->manifest_data()->privileges, pvlg);
+  PKGMGR_LIST_MOVE_NODE_TO_HEAD(context_->manifest_data()->privileges, pvlg);
   for (;pvlg != nullptr; pvlg = pvlg->next) {
     xmlTextWriterStartElement(writer, BAD_CAST "privileges");
     privilege_x *pv;
-    LISTHEAD(pvlg->privilege, pv);
+    PKGMGR_LIST_MOVE_NODE_TO_HEAD(pvlg->privilege, pv);
     for (; pv != nullptr; pv = pv->next) {
       xmlTextWriterWriteFormatElement(writer, BAD_CAST "privilege",
         "%s", BAD_CAST pv->text);