[libxml2] Add explicit cast in xmlURIUnescapeString



commit 0596d67ddc79c0c23370d92d4ecf0656f998c1e7
Author: Nick Wellnhofer <wellnhofer aevum de>
Date:   Tue Jan 25 01:39:41 2022 +0100

    Add explicit cast in xmlURIUnescapeString
    
    Avoids an integer conversion warning with UBSan.

 uri.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
---
diff --git a/uri.c b/uri.c
index 8204825f..ccc26aa5 100644
--- a/uri.c
+++ b/uri.c
@@ -1638,23 +1638,24 @@ xmlURIUnescapeString(const char *str, int len, char *target) {
     out = ret;
     while(len > 0) {
        if ((len > 2) && (*in == '%') && (is_hex(in[1])) && (is_hex(in[2]))) {
+            int c = 0;
            in++;
            if ((*in >= '0') && (*in <= '9'))
-               *out = (*in - '0');
+               c = (*in - '0');
            else if ((*in >= 'a') && (*in <= 'f'))
-               *out = (*in - 'a') + 10;
+               c = (*in - 'a') + 10;
            else if ((*in >= 'A') && (*in <= 'F'))
-               *out = (*in - 'A') + 10;
+               c = (*in - 'A') + 10;
            in++;
            if ((*in >= '0') && (*in <= '9'))
-               *out = *out * 16 + (*in - '0');
+               c = c * 16 + (*in - '0');
            else if ((*in >= 'a') && (*in <= 'f'))
-               *out = *out * 16 + (*in - 'a') + 10;
+               c = c * 16 + (*in - 'a') + 10;
            else if ((*in >= 'A') && (*in <= 'F'))
-               *out = *out * 16 + (*in - 'A') + 10;
+               c = c * 16 + (*in - 'A') + 10;
            in++;
            len -= 3;
-           out++;
+           *out++ = (char) c;
        } else {
            *out++ = *in++;
            len--;


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