From 1ff61837ac88e26349840ac51eb41d05b49ddc9e Mon Sep 17 00:00:00 2001
From: Dmitry Frank <dmitry.frank@cesanta.com>
Date: Wed, 23 Nov 2016 19:48:50 +0200
Subject: [PATCH] Fix mg_http_common_url_parse

The only client of `mg_http_common_url_parse` (namely,
`mg_connect_http_base`) expects `port_i` to be the index in the address
string at which the port was added.

PUBLISHED_FROM=b095926b5485e4674e3c59ff8481171831fb61ae
---
 mongoose.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mongoose.c b/mongoose.c
index 84217e3a8..e5ba8322c 100644
--- a/mongoose.c
+++ b/mongoose.c
@@ -7421,8 +7421,8 @@ MG_INTERNAL int mg_http_common_url_parse(const char *url, const char *schema,
 
   if (addr_len == 0) goto cleanup;
   if (port_pos < 0) {
-    *port_i = *use_ssl ? 443 : 80;
-    addr_len += sprintf(*addr + addr_len, ":%d", *port_i);
+    *port_i = addr_len;
+    addr_len += sprintf(*addr + addr_len, ":%d", *use_ssl ? 443 : 80);
   } else {
     *port_i = -1;
   }
-- 
GitLab