[libxml2] Remove or annotate char casts



commit 6843fc726f7b22bb755d6d572c8f3cc0629a9c76
Author: Nick Wellnhofer <wellnhofer aevum de>
Date:   Thu Sep 1 02:58:00 2022 +0200

    Remove or annotate char casts

 HTMLparser.c      | 4 ++--
 parser.c          | 2 +-
 parserInternals.c | 8 ++++----
 uri.c             | 1 +
 xinclude.c        | 2 +-
 xmlstring.c       | 1 +
 xpath.c           | 2 +-
 7 files changed, 11 insertions(+), 9 deletions(-)
---
diff --git a/HTMLparser.c b/HTMLparser.c
index debbe50f..93b6661b 100644
--- a/HTMLparser.c
+++ b/HTMLparser.c
@@ -326,7 +326,7 @@ htmlNodeInfoPop(htmlParserCtxtPtr ctxt)
 #define CUR_SCHAR(s, l) xmlStringCurrentChar(ctxt, s, &l)
 
 #define COPY_BUF(l,b,i,v)                                              \
-    if (l == 1) b[i++] = (xmlChar) v;                                  \
+    if (l == 1) b[i++] = v;                                            \
     else i += xmlCopyChar(l,&b[i],v)
 
 /**
@@ -5924,7 +5924,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
                 * Handle preparsed entities and charRef
                 */
                if (ctxt->token != 0) {
-                   chr[0] = (xmlChar) ctxt->token;
+                   chr[0] = ctxt->token;
                    htmlCheckParagraph(ctxt);
                    if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL))
                        ctxt->sax->characters(ctxt->userData, chr, 1);
diff --git a/parser.c b/parser.c
index e701e57f..63cc9faa 100644
--- a/parser.c
+++ b/parser.c
@@ -2169,7 +2169,7 @@ static void xmlGROW (xmlParserCtxtPtr ctxt) {
 #define CUR_SCHAR(s, l) xmlStringCurrentChar(ctxt, s, &l)
 
 #define COPY_BUF(l,b,i,v)                                              \
-    if (l == 1) b[i++] = (xmlChar) v;                                  \
+    if (l == 1) b[i++] = v;                                            \
     else i += xmlCopyCharMultiByte(&b[i],v)
 
 #define CUR_CONSUMED \
diff --git a/parserInternals.c b/parserInternals.c
index 43f24bfa..9dbc8f26 100644
--- a/parserInternals.c
+++ b/parserInternals.c
@@ -812,7 +812,7 @@ encoding_error:
  */
 int
 xmlCopyCharMultiByte(xmlChar *out, int val) {
-    if (out == NULL) return(0);
+    if ((out == NULL) || (val < 0)) return(0);
     /*
      * We are supposed to handle UTF8, check it's valid
      * From rfc2044: encoding of the Unicode values on UTF-8:
@@ -838,7 +838,7 @@ xmlCopyCharMultiByte(xmlChar *out, int val) {
            *out++= ((val >> bits) & 0x3F) | 0x80 ;
        return (out - savedout);
     }
-    *out = (xmlChar) val;
+    *out = val;
     return 1;
 }
 
@@ -855,12 +855,12 @@ xmlCopyCharMultiByte(xmlChar *out, int val) {
 
 int
 xmlCopyChar(int len ATTRIBUTE_UNUSED, xmlChar *out, int val) {
-    if (out == NULL) return(0);
+    if ((out == NULL) || (val < 0)) return(0);
     /* the len parameter is ignored */
     if  (val >= 0x80) {
        return(xmlCopyCharMultiByte (out, val));
     }
-    *out = (xmlChar) val;
+    *out = val;
     return 1;
 }
 
diff --git a/uri.c b/uri.c
index cf23c3f4..e6f1c3e7 100644
--- a/uri.c
+++ b/uri.c
@@ -1657,6 +1657,7 @@ xmlURIUnescapeString(const char *str, int len, char *target) {
                c = c * 16 + (*in - 'A') + 10;
            in++;
            len -= 3;
+            /* Explicit sign change */
            *out++ = (char) c;
        } else {
            *out++ = *in++;
diff --git a/xinclude.c b/xinclude.c
index d4f2314b..93d7e525 100644
--- a/xinclude.c
+++ b/xinclude.c
@@ -1714,7 +1714,7 @@ loaded:
                       "trying to build relative URI from %s\n", URL);
            } else {
                /* If the URI doesn't contain a slash, it's not relative */
-               if (!xmlStrchr(curBase, (xmlChar) '/'))
+               if (!xmlStrchr(curBase, '/'))
                    xmlFree(curBase);
                else
                    base = curBase;
diff --git a/xmlstring.c b/xmlstring.c
index 639ad0a0..7fbf9d07 100644
--- a/xmlstring.c
+++ b/xmlstring.c
@@ -97,6 +97,7 @@ xmlCharStrndup(const char *cur, int len) {
         return(NULL);
     }
     for (i = 0;i < len;i++) {
+        /* Explicit sign change */
         ret[i] = (xmlChar) cur[i];
         if (ret[i] == 0) return(ret);
     }
diff --git a/xpath.c b/xpath.c
index 9ad0f0e1..aa8df613 100644
--- a/xpath.c
+++ b/xpath.c
@@ -3098,7 +3098,7 @@ xmlXPathPopExternal (xmlXPathParserContextPtr ctxt) {
 #define CUR_CHAR(l) xmlXPathCurrentChar(ctxt, &l)
 
 #define COPY_BUF(l,b,i,v)                                              \
-    if (l == 1) b[i++] = (xmlChar) v;                                  \
+    if (l == 1) b[i++] = v;                                            \
     else i += xmlCopyChar(l,&b[i],v)
 
 #define NEXTL(l)  ctxt->cur += l


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]