[libxml2] Fix list callback signatures
- From: Nick Wellnhofer <nwellnhof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libxml2] Fix list callback signatures
- Date: Thu, 9 Nov 2017 17:02:31 +0000 (UTC)
commit 4dd6d7a58e3694af7ed42589affcfa9a1550dada
Author: Nick Wellnhofer <wellnhofer aevum de>
Date: Thu Nov 9 17:28:00 2017 +0100
Fix list callback signatures
Make sure that all parameters and return values of list callback
functions exactly match the callback function type. This is required
to pass clang's Control Flow Integrity checks and to allow compilation
to asm.js with Emscripten.
Also change the `user` parameter type from `const void *` to `void *`.
c14n.c | 29 ++++++++++++++++++++---------
include/libxml/list.h | 6 +++---
list.c | 4 ++--
valid.c | 4 ++--
xmlwriter.c | 8 ++------
5 files changed, 29 insertions(+), 22 deletions(-)
---
diff --git a/c14n.c b/c14n.c
index be687ea..b7cb7b0 100644
--- a/c14n.c
+++ b/c14n.c
@@ -513,8 +513,10 @@ xmlC14NIsXmlNs(xmlNsPtr ns)
* Returns -1 if ns1 < ns2, 0 if ns1 == ns2 or 1 if ns1 > ns2.
*/
static int
-xmlC14NNsCompare(xmlNsPtr ns1, xmlNsPtr ns2)
+xmlC14NNsCompare(const void *data1, const void *data2)
{
+ const xmlNsPtr ns1 = (const xmlNsPtr) data1;
+ const xmlNsPtr ns2 = (const xmlNsPtr) data2;
if (ns1 == ns2)
return (0);
if (ns1 == NULL)
@@ -559,6 +561,11 @@ xmlC14NPrintNamespaces(const xmlNsPtr ns, xmlC14NCtxPtr ctx)
return (1);
}
+static int
+xmlC14NPrintNamespacesWalker(const void *ns, void *ctx) {
+ return xmlC14NPrintNamespaces((const xmlNsPtr) ns, (xmlC14NCtxPtr) ctx);
+}
+
/**
* xmlC14NProcessNamespacesAxis:
* @ctx: the C14N context
@@ -615,7 +622,7 @@ xmlC14NProcessNamespacesAxis(xmlC14NCtxPtr ctx, xmlNodePtr cur, int visible)
/*
* Create a sorted list to store element namespaces
*/
- list = xmlListCreate(NULL, (xmlListDataCompare) xmlC14NNsCompare);
+ list = xmlListCreate(NULL, xmlC14NNsCompare);
if (list == NULL) {
xmlC14NErrInternal("creating namespaces list (c14n)");
return (-1);
@@ -663,7 +670,7 @@ xmlC14NProcessNamespacesAxis(xmlC14NCtxPtr ctx, xmlNodePtr cur, int visible)
/*
* print out all elements from list
*/
- xmlListWalk(list, (xmlListWalker) xmlC14NPrintNamespaces, (const void *) ctx);
+ xmlListWalk(list, xmlC14NPrintNamespacesWalker, (void *) ctx);
/*
* Cleanup
@@ -728,7 +735,7 @@ xmlExcC14NProcessNamespacesAxis(xmlC14NCtxPtr ctx, xmlNodePtr cur, int visible)
/*
* Create a sorted list to store element namespaces
*/
- list = xmlListCreate(NULL, (xmlListDataCompare) xmlC14NNsCompare);
+ list = xmlListCreate(NULL, xmlC14NNsCompare);
if (list == NULL) {
xmlC14NErrInternal("creating namespaces list (exc c14n)");
return (-1);
@@ -840,7 +847,7 @@ xmlExcC14NProcessNamespacesAxis(xmlC14NCtxPtr ctx, xmlNodePtr cur, int visible)
/*
* print out all elements from list
*/
- xmlListWalk(list, (xmlListWalker) xmlC14NPrintNamespaces, (const void *) ctx);
+ xmlListWalk(list, xmlC14NPrintNamespacesWalker, (void *) ctx);
/*
* Cleanup
@@ -879,8 +886,10 @@ xmlC14NIsXmlAttr(xmlAttrPtr attr)
* Returns -1 if attr1 < attr2, 0 if attr1 == attr2 or 1 if attr1 > attr2.
*/
static int
-xmlC14NAttrsCompare(xmlAttrPtr attr1, xmlAttrPtr attr2)
+xmlC14NAttrsCompare(const void *data1, const void *data2)
{
+ const xmlAttrPtr attr1 = (const xmlAttrPtr) data1;
+ const xmlAttrPtr attr2 = (const xmlAttrPtr) data2;
int ret = 0;
/*
@@ -931,8 +940,10 @@ xmlC14NAttrsCompare(xmlAttrPtr attr1, xmlAttrPtr attr2)
* Returns 1 on success or 0 on fail.
*/
static int
-xmlC14NPrintAttrs(const xmlAttrPtr attr, xmlC14NCtxPtr ctx)
+xmlC14NPrintAttrs(const void *data, void *user)
{
+ const xmlAttrPtr attr = (const xmlAttrPtr) data;
+ xmlC14NCtxPtr ctx = (xmlC14NCtxPtr) user;
xmlChar *value;
xmlChar *buffer;
@@ -1142,7 +1153,7 @@ xmlC14NProcessAttrsAxis(xmlC14NCtxPtr ctx, xmlNodePtr cur, int parent_visible)
/*
* Create a sorted list to store element attributes
*/
- list = xmlListCreate(NULL, (xmlListDataCompare) xmlC14NAttrsCompare);
+ list = xmlListCreate(NULL, xmlC14NAttrsCompare);
if (list == NULL) {
xmlC14NErrInternal("creating attributes list");
return (-1);
@@ -1331,7 +1342,7 @@ xmlC14NProcessAttrsAxis(xmlC14NCtxPtr ctx, xmlNodePtr cur, int parent_visible)
/*
* print out all elements from list
*/
- xmlListWalk(list, (xmlListWalker) xmlC14NPrintAttrs, (const void *) ctx);
+ xmlListWalk(list, xmlC14NPrintAttrs, (void *) ctx);
/*
* Cleanup
diff --git a/include/libxml/list.h b/include/libxml/list.h
index 0504e0c..3211c75 100644
--- a/include/libxml/list.h
+++ b/include/libxml/list.h
@@ -49,7 +49,7 @@ typedef int (*xmlListDataCompare) (const void *data0, const void *data1);
*
* Returns 0 to stop walking the list, 1 otherwise.
*/
-typedef int (*xmlListWalker) (const void *data, const void *user);
+typedef int (*xmlListWalker) (const void *data, void *user);
/* Creation/Deletion */
XMLPUBFUN xmlListPtr XMLCALL
@@ -110,11 +110,11 @@ XMLPUBFUN void XMLCALL
XMLPUBFUN void XMLCALL
xmlListWalk (xmlListPtr l,
xmlListWalker walker,
- const void *user);
+ void *user);
XMLPUBFUN void XMLCALL
xmlListReverseWalk (xmlListPtr l,
xmlListWalker walker,
- const void *user);
+ void *user);
XMLPUBFUN void XMLCALL
xmlListMerge (xmlListPtr l1,
xmlListPtr l2);
diff --git a/list.c b/list.c
index caa8333..24da6b1 100644
--- a/list.c
+++ b/list.c
@@ -673,7 +673,7 @@ xmlListSort(xmlListPtr l)
* apply the walker function to it
*/
void
-xmlListWalk(xmlListPtr l, xmlListWalker walker, const void *user) {
+xmlListWalk(xmlListPtr l, xmlListWalker walker, void *user) {
xmlLinkPtr lk;
if ((l == NULL) || (walker == NULL))
@@ -694,7 +694,7 @@ xmlListWalk(xmlListPtr l, xmlListWalker walker, const void *user) {
* apply the walker function to it
*/
void
-xmlListReverseWalk(xmlListPtr l, xmlListWalker walker, const void *user) {
+xmlListReverseWalk(xmlListPtr l, xmlListWalker walker, void *user) {
xmlLinkPtr lk;
if ((l == NULL) || (walker == NULL))
diff --git a/valid.c b/valid.c
index 92de541..b1cfede 100644
--- a/valid.c
+++ b/valid.c
@@ -2888,7 +2888,7 @@ xmlFreeRefTableEntry(void *payload, const xmlChar *name ATTRIBUTE_UNUSED) {
* Returns 0 to abort the walk or 1 to continue
*/
static int
-xmlWalkRemoveRef(const void *data, const void *user)
+xmlWalkRemoveRef(const void *data, void *user)
{
xmlAttrPtr attr0 = ((xmlRefPtr)data)->attr;
xmlAttrPtr attr1 = ((xmlRemoveMemoPtr)user)->ap;
@@ -6555,7 +6555,7 @@ xmlValidateRef(xmlRefPtr ref, xmlValidCtxtPtr ctxt,
* Returns 0 to abort the walk or 1 to continue
*/
static int
-xmlWalkValidateList(const void *data, const void *user)
+xmlWalkValidateList(const void *data, void *user)
{
xmlValidateMemoPtr memo = (xmlValidateMemoPtr)user;
xmlValidateRef((xmlRefPtr)data, memo->ctxt, memo->name);
diff --git a/xmlwriter.c b/xmlwriter.c
index eb94e6e..2533a23 100644
--- a/xmlwriter.c
+++ b/xmlwriter.c
@@ -190,9 +190,7 @@ xmlNewTextWriter(xmlOutputBufferPtr out)
}
memset(ret, 0, (size_t) sizeof(xmlTextWriter));
- ret->nodes = xmlListCreate((xmlListDeallocator)
- xmlFreeTextWriterStackEntry,
- (xmlListDataCompare)
+ ret->nodes = xmlListCreate(xmlFreeTextWriterStackEntry,
xmlCmpTextWriterStackEntry);
if (ret->nodes == NULL) {
xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
@@ -201,9 +199,7 @@ xmlNewTextWriter(xmlOutputBufferPtr out)
return NULL;
}
- ret->nsstack = xmlListCreate((xmlListDeallocator)
- xmlFreeTextWriterNsStackEntry,
- (xmlListDataCompare)
+ ret->nsstack = xmlListCreate(xmlFreeTextWriterNsStackEntry,
xmlCmpTextWriterNsStackEntry);
if (ret->nsstack == NULL) {
xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]