Fix #1285 - __builtin___snprintf_chk warning. Tighten test flags and refactor the code to squash all warnings

This commit is contained in:
cpq committed 2021-05-28 18:30:42 +01:00
1 parent db27fae40e
commit 736b8ad7b7
30 files changed
+708 -691

No files matched your search

+9 -8
View File
@@ -2,7 +2,7 @@
#include "url.h"
struct url {
int key, user, pass, host, port, uri, end;
size_t key, user, pass, host, port, uri, end;
};
int mg_url_is_ssl(const char *url) {
@@ -12,7 +12,7 @@ int mg_url_is_ssl(const char *url) {
}
static struct url urlparse(const char *url) {
int i;
size_t i;
struct url u;
memset(&u, 0, sizeof(u));
for (i = 0; url[i] != '\0'; i++) {
@@ -41,8 +41,9 @@ static struct url urlparse(const char *url) {
struct mg_str mg_url_host(const char *url) {
struct url u = urlparse(url);
int n =
u.port ? u.port - u.host - 1 : u.uri ? u.uri - u.host : u.end - u.host;
size_t n = u.port ? u.port - u.host - 1
: u.uri ? u.uri - u.host
: u.end - u.host;
struct mg_str s = mg_str_n(url + u.host, n);
if (s.len > 2 && s.ptr[0] == '[' && s.ptr[s.len - 1] == ']') {
s.len -= 2;
@@ -63,7 +64,7 @@ unsigned short mg_url_port(const char *url) {
if (memcmp(url, "wss:", 4) == 0 || memcmp(url, "https:", 6) == 0) port = 443;
if (memcmp(url, "mqtt:", 5) == 0) port = 1883;
if (memcmp(url, "mqtts:", 6) == 0) port = 8883;
if (u.port) port = atoi(url + u.port);
if (u.port) port = (uint16_t) atoi(url + u.port);
return port;
}
@@ -71,7 +72,7 @@ struct mg_str mg_url_user(const char *url) {
struct url u = urlparse(url);
struct mg_str s = mg_str("");
if (u.user && (u.pass || u.host)) {
int n = u.pass ? u.pass - u.user - 1 : u.host - u.user - 1;
size_t n = u.pass ? u.pass - u.user - 1 : u.host - u.user - 1;
s = mg_str_n(url + u.user, n);
}
return s;
@@ -79,9 +80,9 @@ struct mg_str mg_url_user(const char *url) {
struct mg_str mg_url_pass(const char *url) {
struct url u = urlparse(url);
struct mg_str s = mg_str("");
struct mg_str s = mg_str_n("", 0UL);
if (u.pass && u.host) {
int n = u.host - u.pass - 1;
size_t n = u.host - u.pass - 1;
s = mg_str_n(url + u.pass, n);
}
return s;