I've updated the patches.

On Wed, Nov 8, 2017 at 11:46 AM Nick Wellnhofer <wellnho...@aevum.de> wrote:

> On 08/11/2017 19:48, Vlad Tsyrklevich via xml wrote:
> > The patches fix type signature mismatches with xmlNop() and
> > xmlMemStrdup(). The first patch sets xmlNop() to have the same type
> > signature as xmlInputReadCallback, which is the only type it's ever
> > cast to.
>
> Can you rename xmlNop to something like xmlInputNopReadCallback and remove
> the
> now unnecessary casts when it is used? Also annotate the unused parameters
> with ATTRIBUTE_UNUSED.
>
> > Under some compiler flags, xmlMemStrdup() is a function
> > pointer pointing to xmlStrdup() despite a mismatched type signature.
> > In that case I set it to strdup() instead since it has the correct
> > type signature and the other xmlMem(Malloc|Realloc|Free) function
> > pointers around it point directly to the libc implementations as well.
>
> strdup is a POSIX extension and can't be used for platform compatibility
> reasons. You'll probably have to write a wrapper around xmlStrdup.
>
> If possible, please format patches with git-format-patch.
>
> Nick
>
>
From 09bcc4425132644c8a894f05325c68578298d5a3 Mon Sep 17 00:00:00 2001
From: Vlad Tsyrklevich <vtsyrklev...@google.com>
Date: Thu, 10 Aug 2017 15:08:48 -0700
Subject: [PATCH 1/2] Refactor name and type signature for xmlNop

Update xmlNop's name to xmlInputReadCallbackNop and its type signature
to match xmlInputReadCallback.
---
 libxml.h |  2 +-
 parser.c |  3 ++-
 xmlIO.c  | 10 ++++++----
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/libxml.h b/libxml.h
index 4fe56d21..2efa7047 100644
--- a/libxml.h
+++ b/libxml.h
@@ -96,7 +96,7 @@ int __xmlRandom(void);
 #endif
 
 XMLPUBFUN xmlChar * XMLCALL xmlEscapeFormatString(xmlChar **msg);
-int xmlNop(void);
+int xmlInputReadCallbackNop(void *context, char *buffer, int len);
 
 #ifdef IN_LIBXML
 #ifdef __GNUC__
diff --git a/parser.c b/parser.c
index 1c5e036e..515ced5f 100644
--- a/parser.c
+++ b/parser.c
@@ -2086,7 +2086,8 @@ static void xmlGROW (xmlParserCtxtPtr ctxt) {
 
     if (((curEnd > (unsigned long) XML_MAX_LOOKUP_LIMIT) ||
          (curBase > (unsigned long) XML_MAX_LOOKUP_LIMIT)) &&
-         ((ctxt->input->buf) && (ctxt->input->buf->readcallback != (xmlInputReadCallback) xmlNop)) &&
+         ((ctxt->input->buf) &&
+          (ctxt->input->buf->readcallback != xmlInputReadCallbackNop)) &&
         ((ctxt->options & XML_PARSE_HUGE) == 0)) {
         xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, "Huge input lookup");
         xmlHaltParser(ctxt);
diff --git a/xmlIO.c b/xmlIO.c
index 0fd8c496..1d490954 100644
--- a/xmlIO.c
+++ b/xmlIO.c
@@ -703,14 +703,16 @@ xmlCheckFilename (const char *path)
 }
 
 /**
- * xmlNop:
+ * xmlInputReadCallbackNop:
  *
- * No Operation function, does nothing, no input
+ * No Operation xmlInputReadCallback function, does nothing.
  *
  * Returns zero
  */
 int
-xmlNop(void) {
+xmlInputReadCallbackNop(void *context ATTRIBUTE_UNUSED,
+                        char *buffer ATTRIBUTE_UNUSED,
+                        int len ATTRIBUTE_UNUSED) {
     return(0);
 }
 
@@ -2932,7 +2934,7 @@ xmlParserInputBufferCreateMem(const char *mem, int size, xmlCharEncoding enc) {
     ret = xmlAllocParserInputBuffer(enc);
     if (ret != NULL) {
         ret->context = (void *) mem;
-	ret->readcallback = (xmlInputReadCallback) xmlNop;
+	ret->readcallback = xmlInputReadCallbackNop;
 	ret->closecallback = NULL;
 	errcode = xmlBufAdd(ret->buffer, (const xmlChar *) mem, size);
 	if (errcode != 0) {
-- 
2.15.0.448.gf294e3d99a-goog

From de00a77e1df3ecd357835586abec8508f7c3cc47 Mon Sep 17 00:00:00 2001
From: Vlad Tsyrklevich <vtsyrklev...@google.com>
Date: Wed, 8 Nov 2017 15:28:19 -0800
Subject: [PATCH 2/2] Introduce xmlPosixStrdup and update xmlMemStrdup

Introduce xmlPosixStrdup, an internal strdup implementation matching the
POSIX strdup type signature, and update xmlMemStrdup to use it.
---
 globals.c                  |  2 +-
 include/libxml/xmlstring.h |  2 ++
 xmlstring.c                | 14 ++++++++++++++
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/globals.c b/globals.c
index e351b03f..96865d68 100644
--- a/globals.c
+++ b/globals.c
@@ -131,7 +131,7 @@ xmlReallocFunc xmlRealloc = (xmlReallocFunc) realloc;
  *
  * Returns the copy of the string or NULL in case of error
  */
-xmlStrdupFunc xmlMemStrdup = (xmlStrdupFunc) xmlStrdup;
+xmlStrdupFunc xmlMemStrdup = xmlPosixStrdup;
 #endif /* DEBUG_MEMORY_LOCATION || DEBUG_MEMORY */
 
 #include <libxml/threads.h>
diff --git a/include/libxml/xmlstring.h b/include/libxml/xmlstring.h
index 2d0b2d16..df77c3ac 100644
--- a/include/libxml/xmlstring.h
+++ b/include/libxml/xmlstring.h
@@ -47,6 +47,8 @@ XMLPUBFUN xmlChar * XMLCALL
                                          int len);
 XMLPUBFUN xmlChar * XMLCALL
                 xmlCharStrdup            (const char *cur);
+XMLPUBFUN char * XMLCALL
+                xmlPosixStrdup           (const char *cur);
 XMLPUBFUN xmlChar * XMLCALL
                 xmlStrsub                (const xmlChar *str,
                                          int start,
diff --git a/xmlstring.c b/xmlstring.c
index 8d2e06f6..547f9577 100644
--- a/xmlstring.c
+++ b/xmlstring.c
@@ -118,6 +118,20 @@ xmlCharStrdup(const char *cur) {
     return(xmlCharStrndup(cur, p - cur));
 }
 
+/**
+ * xmlPosixStrdup
+ * @cur:  the input char *
+ *
+ * a strdup implementation with a type signature matching POSIX
+ *
+ * Returns a new xmlChar * or NULL
+ */
+
+char *
+xmlPosixStrdup(const char *cur) {
+    return((char*)xmlCharStrdup(cur));
+}
+
 /**
  * xmlStrcmp:
  * @str1:  the first xmlChar *
-- 
2.15.0.448.gf294e3d99a-goog

_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xml@gnome.org
https://mail.gnome.org/mailman/listinfo/xml

Reply via email to