From nobody Thu Dec 18 13:31:49 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520243285687667.3455512964247; Mon, 5 Mar 2018 01:48:05 -0800 (PST) Received: from localhost ([::1]:48198 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esmiy-0003lS-LW for importer@patchew.org; Mon, 05 Mar 2018 04:48:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49111) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esmbj-0005jP-8R for qemu-devel@nongnu.org; Mon, 05 Mar 2018 04:40:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1esmbe-00067Z-QJ for qemu-devel@nongnu.org; Mon, 05 Mar 2018 04:40:35 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33776 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1esmbX-00063E-Hp; Mon, 05 Mar 2018 04:40:23 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 016B54023150; Mon, 5 Mar 2018 09:40:23 +0000 (UTC) Received: from localhost (ovpn-116-254.ams2.redhat.com [10.36.116.254]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3F3A42026E03; Mon, 5 Mar 2018 09:40:22 +0000 (UTC) From: Stefan Hajnoczi To: Date: Mon, 5 Mar 2018 09:40:03 +0000 Message-Id: <20180305094006.21446-4-stefanha@redhat.com> In-Reply-To: <20180305094006.21446-1-stefanha@redhat.com> References: <20180305094006.21446-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 05 Mar 2018 09:40:23 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 05 Mar 2018 09:40:23 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'stefanha@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 3/6] util/uri.c: wrap single statement blocks with braces {} X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Su Hang , Stefan Hajnoczi , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Su Hang For this patch, using curly braces to wrap `if` `while` `else` statements, which only hold single statement. For example: ''' if (cond) statement; ''' to ''' if (cond) { statement; } ''' And using tricks that compare the disassemblies before and after code changes, to make sure code logic isn't changed: ''' git checkout master make util/uri.o strip util/uri.o objdump -Drx util/uri.o > /tmp/uri-master.txt git checkout cleanupbranch make util/uri.o strip util/uri.o objdump -Drx util/uri.o > /tmp/uri-cleanup.txt Signed-off-by: Stefan Hajnoczi --- util/uri.c | 463 +++++++++++++++++++++++++++++++++++++++------------------= ---- 1 file changed, 294 insertions(+), 169 deletions(-) diff --git a/util/uri.c b/util/uri.c index bb2576cf21..93ecefdaaf 100644 --- a/util/uri.c +++ b/util/uri.c @@ -211,16 +211,19 @@ static int rfc3986_parse_scheme(URI *uri, const char = **str) { const char *cur; =20 - if (str =3D=3D NULL) + if (str =3D=3D NULL) { return -1; + } =20 cur =3D *str; - if (!ISA_ALPHA(cur)) + if (!ISA_ALPHA(cur)) { return 2; + } cur++; while (ISA_ALPHA(cur) || ISA_DIGIT(cur) || (*cur =3D=3D '+') || (*cur = =3D=3D '-') || - (*cur =3D=3D '.')) + (*cur =3D=3D '.')) { cur++; + } if (uri !=3D NULL) { g_free(uri->scheme); uri->scheme =3D g_strndup(*str, cur - *str); @@ -248,21 +251,24 @@ static int rfc3986_parse_fragment(URI *uri, const cha= r **str) { const char *cur; =20 - if (str =3D=3D NULL) + if (str =3D=3D NULL) { return -1; + } =20 cur =3D *str; =20 while ((ISA_PCHAR(cur)) || (*cur =3D=3D '/') || (*cur =3D=3D '?') || (*cur =3D=3D '[') || (*cur =3D=3D ']') || - ((uri !=3D NULL) && (uri->cleanup & 1) && (IS_UNWISE(cur)))) + ((uri !=3D NULL) && (uri->cleanup & 1) && (IS_UNWISE(cur)))) { NEXT(cur); + } if (uri !=3D NULL) { g_free(uri->fragment); - if (uri->cleanup & 2) + if (uri->cleanup & 2) { uri->fragment =3D g_strndup(*str, cur - *str); - else + } else { uri->fragment =3D uri_string_unescape(*str, cur - *str, NULL); + } } *str =3D cur; return 0; @@ -283,14 +289,16 @@ static int rfc3986_parse_query(URI *uri, const char *= *str) { const char *cur; =20 - if (str =3D=3D NULL) + if (str =3D=3D NULL) { return -1; + } =20 cur =3D *str; =20 while ((ISA_PCHAR(cur)) || (*cur =3D=3D '/') || (*cur =3D=3D '?') || - ((uri !=3D NULL) && (uri->cleanup & 1) && (IS_UNWISE(cur)))) + ((uri !=3D NULL) && (uri->cleanup & 1) && (IS_UNWISE(cur)))) { NEXT(cur); + } if (uri !=3D NULL) { g_free(uri->query); uri->query =3D g_strndup(*str, cur - *str); @@ -351,15 +359,17 @@ static int rfc3986_parse_user_info(URI *uri, const ch= ar **str) =20 cur =3D *str; while (ISA_UNRESERVED(cur) || ISA_PCT_ENCODED(cur) || ISA_SUB_DELIM(cu= r) || - (*cur =3D=3D ':')) + (*cur =3D=3D ':')) { NEXT(cur); + } if (*cur =3D=3D '@') { if (uri !=3D NULL) { g_free(uri->user); - if (uri->cleanup & 2) + if (uri->cleanup & 2) { uri->user =3D g_strndup(*str, cur - *str); - else + } else { uri->user =3D uri_string_unescape(*str, cur - *str, NULL); + } } *str =3D cur; return 0; @@ -385,22 +395,24 @@ static int rfc3986_parse_dec_octet(const char **str) { const char *cur =3D *str; =20 - if (!(ISA_DIGIT(cur))) + if (!(ISA_DIGIT(cur))) { return 1; - if (!ISA_DIGIT(cur + 1)) + } + if (!ISA_DIGIT(cur + 1)) { cur++; - else if ((*cur !=3D '0') && (ISA_DIGIT(cur + 1)) && (!ISA_DIGIT(cur + = 2))) + } else if ((*cur !=3D '0') && (ISA_DIGIT(cur + 1)) && (!ISA_DIGIT(cur = + 2))) { cur +=3D 2; - else if ((*cur =3D=3D '1') && (ISA_DIGIT(cur + 1)) && (ISA_DIGIT(cur += 2))) + } else if ((*cur =3D=3D '1') && (ISA_DIGIT(cur + 1)) && (ISA_DIGIT(cur= + 2))) { cur +=3D 3; - else if ((*cur =3D=3D '2') && (*(cur + 1) >=3D '0') && (*(cur + 1) <= =3D '4') && - (ISA_DIGIT(cur + 2))) + } else if ((*cur =3D=3D '2') && (*(cur + 1) >=3D '0') && (*(cur + 1) <= =3D '4') && + (ISA_DIGIT(cur + 2))) { cur +=3D 3; - else if ((*cur =3D=3D '2') && (*(cur + 1) =3D=3D '5') && (*(cur + 2) >= =3D '0') && - (*(cur + 1) <=3D '5')) + } else if ((*cur =3D=3D '2') && (*(cur + 1) =3D=3D '5') && (*(cur + 2)= >=3D '0') && + (*(cur + 1) <=3D '5')) { cur +=3D 3; - else + } else { return 1; + } *str =3D cur; return 0; } @@ -430,10 +442,12 @@ static int rfc3986_parse_host(URI *uri, const char **= str) */ if (*cur =3D=3D '[') { cur++; - while ((*cur !=3D ']') && (*cur !=3D 0)) + while ((*cur !=3D ']') && (*cur !=3D 0)) { cur++; - if (*cur !=3D ']') + } + if (*cur !=3D ']') { return 1; + } cur++; goto found; } @@ -441,21 +455,28 @@ static int rfc3986_parse_host(URI *uri, const char **= str) * try to parse an IPv4 */ if (ISA_DIGIT(cur)) { - if (rfc3986_parse_dec_octet(&cur) !=3D 0) + if (rfc3986_parse_dec_octet(&cur) !=3D 0) { goto not_ipv4; - if (*cur !=3D '.') + } + if (*cur !=3D '.') { goto not_ipv4; + } cur++; - if (rfc3986_parse_dec_octet(&cur) !=3D 0) + if (rfc3986_parse_dec_octet(&cur) !=3D 0) { goto not_ipv4; - if (*cur !=3D '.') + } + if (*cur !=3D '.') { goto not_ipv4; - if (rfc3986_parse_dec_octet(&cur) !=3D 0) + } + if (rfc3986_parse_dec_octet(&cur) !=3D 0) { goto not_ipv4; - if (*cur !=3D '.') + } + if (*cur !=3D '.') { goto not_ipv4; - if (rfc3986_parse_dec_octet(&cur) !=3D 0) + } + if (rfc3986_parse_dec_octet(&cur) !=3D 0) { goto not_ipv4; + } goto found; not_ipv4: cur =3D *str; @@ -463,20 +484,23 @@ static int rfc3986_parse_host(URI *uri, const char **= str) /* * then this should be a hostname which can be empty */ - while (ISA_UNRESERVED(cur) || ISA_PCT_ENCODED(cur) || ISA_SUB_DELIM(cu= r)) + while (ISA_UNRESERVED(cur) || ISA_PCT_ENCODED(cur) || ISA_SUB_DELIM(cu= r)) { NEXT(cur); + } found: if (uri !=3D NULL) { g_free(uri->authority); uri->authority =3D NULL; g_free(uri->server); if (cur !=3D host) { - if (uri->cleanup & 2) + if (uri->cleanup & 2) { uri->server =3D g_strndup(host, cur - host); - else + } else { uri->server =3D uri_string_unescape(host, cur - host, NULL= ); - } else + } + } else { uri->server =3D NULL; + } } *str =3D cur; return 0; @@ -504,18 +528,21 @@ static int rfc3986_parse_authority(URI *uri, const ch= ar **str) * try to parse a userinfo and check for the trailing @ */ ret =3D rfc3986_parse_user_info(uri, &cur); - if ((ret !=3D 0) || (*cur !=3D '@')) + if ((ret !=3D 0) || (*cur !=3D '@')) { cur =3D *str; - else + } else { cur++; + } ret =3D rfc3986_parse_host(uri, &cur); - if (ret !=3D 0) + if (ret !=3D 0) { return ret; + } if (*cur =3D=3D ':') { cur++; ret =3D rfc3986_parse_port(uri, &cur); - if (ret !=3D 0) + if (ret !=3D 0) { return ret; + } } *str =3D cur; return 0; @@ -543,12 +570,14 @@ static int rfc3986_parse_segment(const char **str, ch= ar forbid, int empty) =20 cur =3D *str; if (!ISA_PCHAR(cur)) { - if (empty) + if (empty) { return 0; + } return 1; } - while (ISA_PCHAR(cur) && (*cur !=3D forbid)) + while (ISA_PCHAR(cur) && (*cur !=3D forbid)) { NEXT(cur); + } *str =3D cur; return 0; } @@ -575,16 +604,18 @@ static int rfc3986_parse_path_ab_empty(URI *uri, cons= t char **str) while (*cur =3D=3D '/') { cur++; ret =3D rfc3986_parse_segment(&cur, 0, 1); - if (ret !=3D 0) + if (ret !=3D 0) { return ret; + } } if (uri !=3D NULL) { g_free(uri->path); if (*str !=3D cur) { - if (uri->cleanup & 2) + if (uri->cleanup & 2) { uri->path =3D g_strndup(*str, cur - *str); - else + } else { uri->path =3D uri_string_unescape(*str, cur - *str, NULL); + } } else { uri->path =3D NULL; } @@ -612,25 +643,28 @@ static int rfc3986_parse_path_absolute(URI *uri, cons= t char **str) =20 cur =3D *str; =20 - if (*cur !=3D '/') + if (*cur !=3D '/') { return 1; + } cur++; ret =3D rfc3986_parse_segment(&cur, 0, 0); if (ret =3D=3D 0) { while (*cur =3D=3D '/') { cur++; ret =3D rfc3986_parse_segment(&cur, 0, 1); - if (ret !=3D 0) + if (ret !=3D 0) { return ret; + } } } if (uri !=3D NULL) { g_free(uri->path); if (cur !=3D *str) { - if (uri->cleanup & 2) + if (uri->cleanup & 2) { uri->path =3D g_strndup(*str, cur - *str); - else + } else { uri->path =3D uri_string_unescape(*str, cur - *str, NULL); + } } else { uri->path =3D NULL; } @@ -659,21 +693,24 @@ static int rfc3986_parse_path_rootless(URI *uri, cons= t char **str) cur =3D *str; =20 ret =3D rfc3986_parse_segment(&cur, 0, 0); - if (ret !=3D 0) + if (ret !=3D 0) { return ret; + } while (*cur =3D=3D '/') { cur++; ret =3D rfc3986_parse_segment(&cur, 0, 1); - if (ret !=3D 0) + if (ret !=3D 0) { return ret; + } } if (uri !=3D NULL) { g_free(uri->path); if (cur !=3D *str) { - if (uri->cleanup & 2) + if (uri->cleanup & 2) { uri->path =3D g_strndup(*str, cur - *str); - else + } else { uri->path =3D uri_string_unescape(*str, cur - *str, NULL); + } } else { uri->path =3D NULL; } @@ -702,21 +739,24 @@ static int rfc3986_parse_path_no_scheme(URI *uri, con= st char **str) cur =3D *str; =20 ret =3D rfc3986_parse_segment(&cur, ':', 0); - if (ret !=3D 0) + if (ret !=3D 0) { return ret; + } while (*cur =3D=3D '/') { cur++; ret =3D rfc3986_parse_segment(&cur, 0, 1); - if (ret !=3D 0) + if (ret !=3D 0) { return ret; + } } if (uri !=3D NULL) { g_free(uri->path); if (cur !=3D *str) { - if (uri->cleanup & 2) + if (uri->cleanup & 2) { uri->path =3D g_strndup(*str, cur - *str); - else + } else { uri->path =3D uri_string_unescape(*str, cur - *str, NULL); + } } else { uri->path =3D NULL; } @@ -750,21 +790,25 @@ static int rfc3986_parse_hier_part(URI *uri, const ch= ar **str) if ((*cur =3D=3D '/') && (*(cur + 1) =3D=3D '/')) { cur +=3D 2; ret =3D rfc3986_parse_authority(uri, &cur); - if (ret !=3D 0) + if (ret !=3D 0) { return ret; + } ret =3D rfc3986_parse_path_ab_empty(uri, &cur); - if (ret !=3D 0) + if (ret !=3D 0) { return ret; + } *str =3D cur; return 0; } else if (*cur =3D=3D '/') { ret =3D rfc3986_parse_path_absolute(uri, &cur); - if (ret !=3D 0) + if (ret !=3D 0) { return ret; + } } else if (ISA_PCHAR(cur)) { ret =3D rfc3986_parse_path_rootless(uri, &cur); - if (ret !=3D 0) + if (ret !=3D 0) { return ret; + } } else { /* path-empty is effectively empty */ if (uri !=3D NULL) { @@ -799,19 +843,23 @@ static int rfc3986_parse_relative_ref(URI *uri, const= char *str) if ((*str =3D=3D '/') && (*(str + 1) =3D=3D '/')) { str +=3D 2; ret =3D rfc3986_parse_authority(uri, &str); - if (ret !=3D 0) + if (ret !=3D 0) { return ret; + } ret =3D rfc3986_parse_path_ab_empty(uri, &str); - if (ret !=3D 0) + if (ret !=3D 0) { return ret; + } } else if (*str =3D=3D '/') { ret =3D rfc3986_parse_path_absolute(uri, &str); - if (ret !=3D 0) + if (ret !=3D 0) { return ret; + } } else if (ISA_PCHAR(str)) { ret =3D rfc3986_parse_path_no_scheme(uri, &str); - if (ret !=3D 0) + if (ret !=3D 0) { return ret; + } } else { /* path-empty is effectively empty */ if (uri !=3D NULL) { @@ -823,14 +871,16 @@ static int rfc3986_parse_relative_ref(URI *uri, const= char *str) if (*str =3D=3D '?') { str++; ret =3D rfc3986_parse_query(uri, &str); - if (ret !=3D 0) + if (ret !=3D 0) { return ret; + } } if (*str =3D=3D '#') { str++; ret =3D rfc3986_parse_fragment(uri, &str); - if (ret !=3D 0) + if (ret !=3D 0) { return ret; + } } if (*str !=3D 0) { uri_clean(uri); @@ -856,26 +906,30 @@ static int rfc3986_parse(URI *uri, const char *str) int ret; =20 ret =3D rfc3986_parse_scheme(uri, &str); - if (ret !=3D 0) + if (ret !=3D 0) { return ret; + } if (*str !=3D ':') { return 1; } str++; ret =3D rfc3986_parse_hier_part(uri, &str); - if (ret !=3D 0) + if (ret !=3D 0) { return ret; + } if (*str =3D=3D '?') { str++; ret =3D rfc3986_parse_query(uri, &str); - if (ret !=3D 0) + if (ret !=3D 0) { return ret; + } } if (*str =3D=3D '#') { str++; ret =3D rfc3986_parse_fragment(uri, &str); - if (ret !=3D 0) + if (ret !=3D 0) { return ret; + } } if (*str !=3D 0) { uri_clean(uri); @@ -900,8 +954,9 @@ static int rfc3986_parse_uri_reference(URI *uri, const = char *str) { int ret; =20 - if (str =3D=3D NULL) + if (str =3D=3D NULL) { return -1; + } uri_clean(uri); =20 /* @@ -935,8 +990,9 @@ URI *uri_parse(const char *str) URI *uri; int ret; =20 - if (str =3D=3D NULL) + if (str =3D=3D NULL) { return NULL; + } uri =3D uri_new(); ret =3D rfc3986_parse_uri_reference(uri, str); if (ret) { @@ -979,8 +1035,9 @@ URI *uri_parse_raw(const char *str, int raw) URI *uri; int ret; =20 - if (str =3D=3D NULL) + if (str =3D=3D NULL) { return NULL; + } uri =3D uri_new(); if (raw) { uri->cleanup |=3D 2; @@ -1047,8 +1104,9 @@ char *uri_to_string(URI *uri) int len; int max; =20 - if (uri =3D=3D NULL) + if (uri =3D=3D NULL) { return NULL; + } =20 max =3D 80; ret =3D g_malloc(max + 1); @@ -1076,9 +1134,9 @@ char *uri_to_string(URI *uri) temp =3D realloc2n(ret, &max); ret =3D temp; } - if (IS_RESERVED(*(p)) || IS_UNRESERVED(*(p))) + if (IS_RESERVED(*(p)) || IS_UNRESERVED(*(p))) { ret[len++] =3D *p++; - else { + } else { int val =3D *(unsigned char *)p++; int hi =3D val / 0x10, lo =3D val % 0x10; ret[len++] =3D '%'; @@ -1103,9 +1161,9 @@ char *uri_to_string(URI *uri) } if ((IS_UNRESERVED(*(p))) || ((*(p) =3D=3D ';')) || ((*(p) =3D=3D ':')) || ((*(p) =3D=3D '&')) || ((*(= p) =3D=3D '=3D')) || - ((*(p) =3D=3D '+')) || ((*(p) =3D=3D '$')) || ((*(= p) =3D=3D ','))) + ((*(p) =3D=3D '+')) || ((*(p) =3D=3D '$')) || ((*(= p) =3D=3D ','))) { ret[len++] =3D *p++; - else { + } else { int val =3D *(unsigned char *)p++; int hi =3D val / 0x10, lo =3D val % 0x10; ret[len++] =3D '%'; @@ -1150,9 +1208,9 @@ char *uri_to_string(URI *uri) if ((IS_UNRESERVED(*(p))) || ((*(p) =3D=3D '$')) || ((*(p) =3D=3D ',')) || ((*(p) =3D=3D ';')) || ((*(p) = =3D=3D ':')) || ((*(p) =3D=3D '@')) || ((*(p) =3D=3D '&')) || ((*(p) = =3D=3D '=3D')) || - ((*(p) =3D=3D '+'))) + ((*(p) =3D=3D '+'))) { ret[len++] =3D *p++; - else { + } else { int val =3D *(unsigned char *)p++; int hi =3D val / 0x10, lo =3D val % 0x10; ret[len++] =3D '%'; @@ -1194,9 +1252,9 @@ char *uri_to_string(URI *uri) if ((IS_UNRESERVED(*(p))) || ((*(p) =3D=3D '/')) || ((*(p) =3D=3D ';')) || ((*(p) =3D=3D '@')) || ((*(p) = =3D=3D '&')) || ((*(p) =3D=3D '=3D')) || ((*(p) =3D=3D '+')) || ((*(p)= =3D=3D '$')) || - ((*(p) =3D=3D ','))) + ((*(p) =3D=3D ','))) { ret[len++] =3D *p++; - else { + } else { int val =3D *(unsigned char *)p++; int hi =3D val / 0x10, lo =3D val % 0x10; ret[len++] =3D '%'; @@ -1233,9 +1291,9 @@ char *uri_to_string(URI *uri) temp =3D realloc2n(ret, &max); ret =3D temp; } - if ((IS_UNRESERVED(*(p))) || (IS_RESERVED(*(p)))) + if ((IS_UNRESERVED(*(p))) || (IS_RESERVED(*(p)))) { ret[len++] =3D *p++; - else { + } else { int val =3D *(unsigned char *)p++; int hi =3D val / 0x10, lo =3D val % 0x10; ret[len++] =3D '%'; @@ -1260,8 +1318,9 @@ char *uri_to_string(URI *uri) */ static void uri_clean(URI *uri) { - if (uri =3D=3D NULL) + if (uri =3D=3D NULL) { return; + } =20 g_free(uri->scheme); uri->scheme =3D NULL; @@ -1314,17 +1373,20 @@ static int normalize_uri_path(char *path) { char *cur, *out; =20 - if (path =3D=3D NULL) + if (path =3D=3D NULL) { return -1; + } =20 /* Skip all initial "/" chars. We want to get to the beginning of the * first non-empty segment. */ cur =3D path; - while (cur[0] =3D=3D '/') + while (cur[0] =3D=3D '/') { ++cur; - if (cur[0] =3D=3D '\0') + } + if (cur[0] =3D=3D '\0') { return 0; + } =20 /* Keep everything we've seen so far. */ out =3D cur; @@ -1340,8 +1402,9 @@ static int normalize_uri_path(char *path) if ((cur[0] =3D=3D '.') && (cur[1] =3D=3D '/')) { cur +=3D 2; /* '//' normalization should be done at this point too */ - while (cur[0] =3D=3D '/') + while (cur[0] =3D=3D '/') { cur++; + } continue; } =20 @@ -1349,18 +1412,21 @@ static int normalize_uri_path(char *path) * d) If the buffer string ends with "." as a complete path segmen= t, * that "." is removed. */ - if ((cur[0] =3D=3D '.') && (cur[1] =3D=3D '\0')) + if ((cur[0] =3D=3D '.') && (cur[1] =3D=3D '\0')) { break; + } =20 /* Otherwise keep the segment. */ while (cur[0] !=3D '/') { - if (cur[0] =3D=3D '\0') + if (cur[0] =3D=3D '\0') { goto done_cd; + } (out++)[0] =3D (cur++)[0]; } /* nomalize // */ - while ((cur[0] =3D=3D '/') && (cur[1] =3D=3D '/')) + while ((cur[0] =3D=3D '/') && (cur[1] =3D=3D '/')) { cur++; + } =20 (out++)[0] =3D (cur++)[0]; } @@ -1369,10 +1435,12 @@ done_cd: =20 /* Reset to the beginning of the first segment for the next sequence. = */ cur =3D path; - while (cur[0] =3D=3D '/') + while (cur[0] =3D=3D '/') { ++cur; - if (cur[0] =3D=3D '\0') + } + if (cur[0] =3D=3D '\0') { return 0; + } =20 /* * Analyze each segment in sequence for cases (e) and (f). @@ -1401,14 +1469,16 @@ done_cd: =20 /* Find the end of the current segment. */ segp =3D cur; - while ((segp[0] !=3D '/') && (segp[0] !=3D '\0')) + while ((segp[0] !=3D '/') && (segp[0] !=3D '\0')) { ++segp; + } =20 /* If this is the last segment, we're done (we need at least two * segments to meet the criteria for the (e) and (f) cases). */ - if (segp[0] =3D=3D '\0') + if (segp[0] =3D=3D '\0') { break; + } =20 /* If the first segment is "..", or if the next segment _isn't_ ".= .", * keep this segment and try the next one. @@ -1437,15 +1507,18 @@ done_cd: /* string will overlap, do not use strcpy */ tmp =3D cur; segp +=3D 3; - while ((*tmp++ =3D *segp++) !=3D 0) - ; + while ((*tmp++ =3D *segp++) !=3D 0) { + /* No further work */ + } =20 /* If there are no previous segments, then keep going from here. = */ segp =3D cur; - while ((segp > path) && ((--segp)[0] =3D=3D '/')) - ; - if (segp =3D=3D path) + while ((segp > path) && ((--segp)[0] =3D=3D '/')) { + /* No further work */ + } + if (segp =3D=3D path) { continue; + } =20 /* "segp" is pointing to the end of a previous segment; find it's * start. We need to back up to the previous segment and start @@ -1455,8 +1528,9 @@ done_cd: * remove the "foo/..". */ cur =3D segp; - while ((cur > path) && (cur[-1] !=3D '/')) + while ((cur > path) && (cur[-1] !=3D '/')) { --cur; + } } out[0] =3D '\0'; =20 @@ -1474,13 +1548,15 @@ done_cd: if (path[0] =3D=3D '/') { cur =3D path; while ((cur[0] =3D=3D '/') && (cur[1] =3D=3D '.') && (cur[2] =3D= =3D '.') && - ((cur[3] =3D=3D '/') || (cur[3] =3D=3D '\0'))) + ((cur[3] =3D=3D '/') || (cur[3] =3D=3D '\0'))) { cur +=3D 3; + } =20 if (cur !=3D path) { out =3D path; - while (cur[0] !=3D '\0') + while (cur[0] !=3D '\0') { (out++)[0] =3D (cur++)[0]; + } out[0] =3D 0; } } @@ -1491,8 +1567,9 @@ done_cd: static int is_hex(char c) { if (((c >=3D '0') && (c <=3D '9')) || ((c >=3D 'a') && (c <=3D 'f')) || - ((c >=3D 'A') && (c <=3D 'F'))) + ((c >=3D 'A') && (c <=3D 'F'))) { return 1; + } return 0; } =20 @@ -1515,35 +1592,41 @@ char *uri_string_unescape(const char *str, int len,= char *target) char *ret, *out; const char *in; =20 - if (str =3D=3D NULL) + if (str =3D=3D NULL) { return NULL; - if (len <=3D 0) + } + if (len <=3D 0) { len =3D strlen(str); - if (len < 0) + } + if (len < 0) { return NULL; + } =20 if (target =3D=3D NULL) { ret =3D g_malloc(len + 1); - } else + } else { ret =3D target; + } in =3D str; out =3D ret; while (len > 0) { if ((len > 2) && (*in =3D=3D '%') && (is_hex(in[1])) && (is_hex(in= [2]))) { in++; - if ((*in >=3D '0') && (*in <=3D '9')) + if ((*in >=3D '0') && (*in <=3D '9')) { *out =3D (*in - '0'); - else if ((*in >=3D 'a') && (*in <=3D 'f')) + } else if ((*in >=3D 'a') && (*in <=3D 'f')) { *out =3D (*in - 'a') + 10; - else if ((*in >=3D 'A') && (*in <=3D 'F')) + } else if ((*in >=3D 'A') && (*in <=3D 'F')) { *out =3D (*in - 'A') + 10; + } in++; - if ((*in >=3D '0') && (*in <=3D '9')) + if ((*in >=3D '0') && (*in <=3D '9')) { *out =3D *out * 16 + (*in - '0'); - else if ((*in >=3D 'a') && (*in <=3D 'f')) + } else if ((*in >=3D 'a') && (*in <=3D 'f')) { *out =3D *out * 16 + (*in - 'a') + 10; - else if ((*in >=3D 'A') && (*in <=3D 'F')) + } else if ((*in >=3D 'A') && (*in <=3D 'F')) { *out =3D *out * 16 + (*in - 'A') + 10; + } in++; len -=3D 3; out++; @@ -1573,13 +1656,16 @@ char *uri_string_escape(const char *str, const char= *list) const char *in; int len, out; =20 - if (str =3D=3D NULL) + if (str =3D=3D NULL) { return NULL; - if (str[0] =3D=3D 0) + } + if (str[0] =3D=3D 0) { return g_strdup(str); + } len =3D strlen(str); - if (!(len > 0)) + if (!(len > 0)) { return NULL; + } =20 len +=3D 20; ret =3D g_malloc(len); @@ -1597,15 +1683,17 @@ char *uri_string_escape(const char *str, const char= *list) unsigned char val; ret[out++] =3D '%'; val =3D ch >> 4; - if (val <=3D 9) + if (val <=3D 9) { ret[out++] =3D '0' + val; - else + } else { ret[out++] =3D 'A' + val - 0xA; + } val =3D ch & 0xF; - if (val <=3D 9) + if (val <=3D 9) { ret[out++] =3D '0' + val; - else + } else { ret[out++] =3D 'A' + val - 0xA; + } in++; } else { ret[out++] =3D *in++; @@ -1652,17 +1740,19 @@ char *uri_resolve(const char *uri, const char *base) * as a reference to "." rather than as a synonym for the current * URI. Should we do that here? */ - if (uri =3D=3D NULL) + if (uri =3D=3D NULL) { ret =3D -1; - else { + } else { if (*uri) { ref =3D uri_new(); ret =3D uri_parse_into(ref, uri); - } else + } else { ret =3D 0; + } } - if (ret !=3D 0) + if (ret !=3D 0) { goto done; + } if ((ref !=3D NULL) && (ref->scheme !=3D NULL)) { /* * The URI is absolute don't modify. @@ -1670,15 +1760,16 @@ char *uri_resolve(const char *uri, const char *base) val =3D g_strdup(uri); goto done; } - if (base =3D=3D NULL) + if (base =3D=3D NULL) { ret =3D -1; - else { + } else { bas =3D uri_new(); ret =3D uri_parse_into(bas, base); } if (ret !=3D 0) { - if (ref) + if (ref) { val =3D uri_to_string(ref); + } goto done; } if (ref =3D=3D NULL) { @@ -1707,9 +1798,9 @@ char *uri_resolve(const char *uri, const char *base) if ((ref->scheme =3D=3D NULL) && (ref->path =3D=3D NULL) && ((ref->authority =3D=3D NULL) && (ref->server =3D=3D NULL))) { res->scheme =3D g_strdup(bas->scheme); - if (bas->authority !=3D NULL) + if (bas->authority !=3D NULL) { res->authority =3D g_strdup(bas->authority); - else if (bas->server !=3D NULL) { + } else if (bas->server !=3D NULL) { res->server =3D g_strdup(bas->server); res->user =3D g_strdup(bas->user); res->port =3D bas->port; @@ -1747,9 +1838,9 @@ char *uri_resolve(const char *uri, const char *base) * use an authority component. */ if ((ref->authority !=3D NULL) || (ref->server !=3D NULL)) { - if (ref->authority !=3D NULL) + if (ref->authority !=3D NULL) { res->authority =3D g_strdup(ref->authority); - else { + } else { res->server =3D g_strdup(ref->server); res->user =3D g_strdup(ref->user); res->port =3D ref->port; @@ -1757,9 +1848,9 @@ char *uri_resolve(const char *uri, const char *base) res->path =3D g_strdup(ref->path); goto step_7; } - if (bas->authority !=3D NULL) + if (bas->authority !=3D NULL) { res->authority =3D g_strdup(bas->authority); - else if (bas->server !=3D NULL) { + } else if (bas->server !=3D NULL) { res->server =3D g_strdup(bas->server); res->user =3D g_strdup(bas->user); res->port =3D bas->port; @@ -1783,10 +1874,12 @@ char *uri_resolve(const char *uri, const char *base) * Allocate a buffer large enough for the result string. */ len =3D 2; /* extra / and 0 */ - if (ref->path !=3D NULL) + if (ref->path !=3D NULL) { len +=3D strlen(ref->path); - if (bas->path !=3D NULL) + } + if (bas->path !=3D NULL) { len +=3D strlen(bas->path); + } res->path =3D g_malloc(len); res->path[0] =3D 0; =20 @@ -1799,10 +1892,12 @@ char *uri_resolve(const char *uri, const char *base) out =3D 0; if (bas->path !=3D NULL) { while (bas->path[cur] !=3D 0) { - while ((bas->path[cur] !=3D 0) && (bas->path[cur] !=3D '/')) + while ((bas->path[cur] !=3D 0) && (bas->path[cur] !=3D '/')) { cur++; - if (bas->path[cur] =3D=3D 0) + } + if (bas->path[cur] =3D=3D 0) { break; + } =20 cur++; while (out < cur) { @@ -1822,8 +1917,9 @@ char *uri_resolve(const char *uri, const char *base) /* * Ensure the path includes a '/' */ - if ((out =3D=3D 0) && (bas->server !=3D NULL)) + if ((out =3D=3D 0) && (bas->server !=3D NULL)) { res->path[out++] =3D '/'; + } while (ref->path[indx] !=3D 0) { res->path[out++] =3D ref->path[indx++]; } @@ -1845,12 +1941,15 @@ step_7: val =3D uri_to_string(res); =20 done: - if (ref !=3D NULL) + if (ref !=3D NULL) { uri_free(ref); - if (bas !=3D NULL) + } + if (bas !=3D NULL) { uri_free(bas); - if (res !=3D NULL) + } + if (res !=3D NULL) { uri_free(res); + } return val; } =20 @@ -1899,8 +1998,9 @@ char *uri_resolve_relative(const char *uri, const cha= r *base) char *bptr, *uptr, *vptr; int remove_path =3D 0; =20 - if ((uri =3D=3D NULL) || (*uri =3D=3D 0)) + if ((uri =3D=3D NULL) || (*uri =3D=3D 0)) { return NULL; + } =20 /* * First parse URI into a standard form @@ -1909,10 +2009,12 @@ char *uri_resolve_relative(const char *uri, const c= har *base) /* If URI not already in "relative" form */ if (uri[0] !=3D '.') { ret =3D uri_parse_into(ref, uri); - if (ret !=3D 0) + if (ret !=3D 0) { goto done; /* Error in URI, return NULL */ - } else + } + } else { ref->path =3D g_strdup(uri); + } =20 /* * Next parse base into the same standard form @@ -1924,10 +2026,12 @@ char *uri_resolve_relative(const char *uri, const c= har *base) bas =3D uri_new(); if (base[0] !=3D '.') { ret =3D uri_parse_into(bas, base); - if (ret !=3D 0) + if (ret !=3D 0) { goto done; /* Error in base, return NULL */ - } else + } + } else { bas->path =3D g_strdup(base); + } =20 /* * If the scheme / server on the URI differs from the base, @@ -1962,8 +2066,9 @@ char *uri_resolve_relative(const char *uri, const cha= r *base) if (bas->path =3D=3D NULL) { if (ref->path !=3D NULL) { uptr =3D ref->path; - if (*uptr =3D=3D '/') + if (*uptr =3D=3D '/') { uptr++; + } /* exception characters from uri_to_string */ val =3D uri_string_escape(uptr, "/;&=3D+$,"); } @@ -1972,8 +2077,9 @@ char *uri_resolve_relative(const char *uri, const cha= r *base) bptr =3D bas->path; if (ref->path =3D=3D NULL) { for (ix =3D 0; bptr[ix] !=3D 0; ix++) { - if (bptr[ix] =3D=3D '/') + if (bptr[ix] =3D=3D '/') { nbslash++; + } } uptr =3D NULL; len =3D 1; /* this is for a string terminator only */ @@ -1981,14 +2087,17 @@ char *uri_resolve_relative(const char *uri, const c= har *base) /* * Next we compare the two strings and find where they first differ */ - if ((ref->path[pos] =3D=3D '.') && (ref->path[pos + 1] =3D=3D '/')) + if ((ref->path[pos] =3D=3D '.') && (ref->path[pos + 1] =3D=3D '/')= ) { pos +=3D 2; - if ((*bptr =3D=3D '.') && (bptr[1] =3D=3D '/')) + } + if ((*bptr =3D=3D '.') && (bptr[1] =3D=3D '/')) { bptr +=3D 2; - else if ((*bptr =3D=3D '/') && (ref->path[pos] !=3D '/')) + } else if ((*bptr =3D=3D '/') && (ref->path[pos] !=3D '/')) { bptr++; - while ((bptr[pos] =3D=3D ref->path[pos]) && (bptr[pos] !=3D 0)) + } + while ((bptr[pos] =3D=3D ref->path[pos]) && (bptr[pos] !=3D 0)) { pos++; + } =20 if (bptr[pos] =3D=3D ref->path[pos]) { val =3D g_strdup(""); @@ -2000,13 +2109,16 @@ char *uri_resolve_relative(const char *uri, const c= har *base) * beginning of the "unique" suffix of URI */ ix =3D pos; - if ((ref->path[ix] =3D=3D '/') && (ix > 0)) + if ((ref->path[ix] =3D=3D '/') && (ix > 0)) { ix--; - else if ((ref->path[ix] =3D=3D 0) && (ix > 1) && (ref->path[ix - 1= ] =3D=3D '/')) + } else if ((ref->path[ix] =3D=3D 0) && (ix > 1) + && (ref->path[ix - 1] =3D=3D '/')) { ix -=3D 2; + } for (; ix > 0; ix--) { - if (ref->path[ix] =3D=3D '/') + if (ref->path[ix] =3D=3D '/') { break; + } } if (ix =3D=3D 0) { uptr =3D ref->path; @@ -2020,17 +2132,19 @@ char *uri_resolve_relative(const char *uri, const c= har *base) */ if (bptr[pos] !=3D ref->path[pos]) { /* check for trivial URI =3D= =3D base */ for (; bptr[ix] !=3D 0; ix++) { - if (bptr[ix] =3D=3D '/') + if (bptr[ix] =3D=3D '/') { nbslash++; + } } } len =3D strlen(uptr) + 1; } =20 if (nbslash =3D=3D 0) { - if (uptr !=3D NULL) + if (uptr !=3D NULL) { /* exception characters from uri_to_string */ val =3D uri_string_escape(uptr, "/;&=3D+$,"); + } goto done; } =20 @@ -2075,12 +2189,15 @@ done: /* * Free the working variables */ - if (remove_path !=3D 0) + if (remove_path !=3D 0) { ref->path =3D NULL; - if (ref !=3D NULL) + } + if (ref !=3D NULL) { uri_free(ref); - if (bas !=3D NULL) + } + if (bas !=3D NULL) { uri_free(bas); + } =20 return val; } @@ -2093,8 +2210,9 @@ struct QueryParams *query_params_new(int init_alloc) { struct QueryParams *ps; =20 - if (init_alloc <=3D 0) + if (init_alloc <=3D 0) { init_alloc =3D 1; + } =20 ps =3D g_new(QueryParams, 1); ps->n =3D 0; @@ -2141,27 +2259,32 @@ struct QueryParams *query_params_parse(const char *= query) const char *end, *eq; =20 ps =3D query_params_new(0); - if (!query || query[0] =3D=3D '\0') + if (!query || query[0] =3D=3D '\0') { return ps; + } =20 while (*query) { char *name =3D NULL, *value =3D NULL; =20 /* Find the next separator, or end of the string. */ end =3D strchr(query, '&'); - if (!end) + if (!end) { end =3D strchr(query, ';'); - if (!end) + } + if (!end) { end =3D query + strlen(query); + } =20 /* Find the first '=3D' character between here and end. */ eq =3D strchr(query, '=3D'); - if (eq && eq >=3D end) + if (eq && eq >=3D end) { eq =3D NULL; + } =20 /* Empty section (eg. "&&"). */ - if (end =3D=3D query) + if (end =3D=3D query) { goto next; + } =20 /* If there is no '=3D' character, then we have just "name" * and consistent with CGI.pm we assume value is "". @@ -2180,8 +2303,9 @@ struct QueryParams *query_params_parse(const char *qu= ery) /* If the '=3D' character is at the beginning then we have * "=3Dvalue" and consistent with CGI.pm we _ignore_ this. */ - else if (query =3D=3D eq) + else if (query =3D=3D eq) { goto next; + } =20 /* Otherwise it's "name=3Dvalue". */ else { @@ -2196,8 +2320,9 @@ struct QueryParams *query_params_parse(const char *qu= ery) =20 next: query =3D end; - if (*query) + if (*query) { query++; /* skip '&' separator */ + } } =20 return ps; --=20 2.14.3