rolled back to 2.9.1 because 2.9.2 doesn't work with connecting net
[platform/upstream/libxml2.git] / uri.c
diff --git a/uri.c b/uri.c
index 2bd5720..4ab0ce2 100644 (file)
--- a/uri.c
+++ b/uri.c
@@ -314,7 +314,7 @@ xmlParse3986Query(xmlURIPtr uri, const char **str)
  * @uri:  pointer to an URI structure
  * @str:  the string to analyze
  *
- * Parse a port part and fills in the appropriate fields
+ * Parse a port  part and fills in the appropriate fields
  * of the @uri structure
  *
  * port          = *DIGIT
@@ -325,16 +325,15 @@ static int
 xmlParse3986Port(xmlURIPtr uri, const char **str)
 {
     const char *cur = *str;
-    unsigned port = 0; /* unsigned for defined overflow behavior */
 
     if (ISA_DIGIT(cur)) {
+       if (uri != NULL)
+           uri->port = 0;
        while (ISA_DIGIT(cur)) {
-           port = port * 10 + (*cur - '0');
-
+           if (uri != NULL)
+               uri->port = uri->port * 10 + (*cur - '0');
            cur++;
        }
-       if (uri != NULL)
-           uri->port = port & INT_MAX; /* port value modulo INT_MAX+1 */
        *str = cur;
        return(0);
     }
@@ -760,8 +759,6 @@ xmlParse3986HierPart(xmlURIPtr uri, const char **str)
         cur += 2;
        ret = xmlParse3986Authority(uri, &cur);
        if (ret != 0) return(ret);
-       if (uri->server == NULL)
-           uri->port = -1;
        ret = xmlParse3986PathAbEmpty(uri, &cur);
        if (ret != 0) return(ret);
        *str = cur;
@@ -1109,7 +1106,7 @@ xmlSaveUri(xmlURIPtr uri) {
            }
        }
     } else {
-       if ((uri->server != NULL) || (uri->port == -1)) {
+       if (uri->server != NULL) {
            if (len + 3 >= max) {
                 temp = xmlSaveUriRealloc(ret, &max);
                 if (temp == NULL) goto mem_error;
@@ -1146,24 +1143,22 @@ xmlSaveUri(xmlURIPtr uri) {
                }
                ret[len++] = '@';
            }
-           if (uri->server != NULL) {
-               p = uri->server;
-               while (*p != 0) {
-                   if (len >= max) {
-                       temp = xmlSaveUriRealloc(ret, &max);
-                       if (temp == NULL) goto mem_error;
-                       ret = temp;
-                   }
-                   ret[len++] = *p++;
+           p = uri->server;
+           while (*p != 0) {
+               if (len >= max) {
+                    temp = xmlSaveUriRealloc(ret, &max);
+                    if (temp == NULL) goto mem_error;
+                    ret = temp;
                }
-               if (uri->port > 0) {
-                   if (len + 10 >= max) {
-                       temp = xmlSaveUriRealloc(ret, &max);
-                       if (temp == NULL) goto mem_error;
-                       ret = temp;
-                   }
-                   len += snprintf((char *) &ret[len], max - len, ":%d", uri->port);
+               ret[len++] = *p++;
+           }
+           if (uri->port > 0) {
+               if (len + 10 >= max) {
+                    temp = xmlSaveUriRealloc(ret, &max);
+                    if (temp == NULL) goto mem_error;
+                    ret = temp;
                }
+               len += snprintf((char *) &ret[len], max - len, ":%d", uri->port);
            }
        } else if (uri->authority != NULL) {
            if (len + 3 >= max) {
@@ -1199,6 +1194,8 @@ xmlSaveUri(xmlURIPtr uri) {
                 if (temp == NULL) goto mem_error;
                 ret = temp;
            }
+           ret[len++] = '/';
+           ret[len++] = '/';
        }
        if (uri->path != NULL) {
            p = uri->path;