From nobody Thu Dec 18 19:27:56 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 1520243031935171.96049458303082; Mon, 5 Mar 2018 01:43:51 -0800 (PST) Received: from localhost ([::1]:48160 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esmes-00089A-Px for importer@patchew.org; Mon, 05 Mar 2018 04:43:50 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49132) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esmbl-0005lZ-AJ for qemu-devel@nongnu.org; Mon, 05 Mar 2018 04:40:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1esmbf-00067l-OA for qemu-devel@nongnu.org; Mon, 05 Mar 2018 04:40:37 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40308 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 1esmbT-0005yD-7b; Mon, 05 Mar 2018 04:40:19 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F3605404084B; Mon, 5 Mar 2018 09:40:16 +0000 (UTC) Received: from localhost (ovpn-116-254.ams2.redhat.com [10.36.116.254]) by smtp.corp.redhat.com (Postfix) with ESMTP id DA5C02144B21; Mon, 5 Mar 2018 09:40:13 +0000 (UTC) From: Stefan Hajnoczi To: Date: Mon, 5 Mar 2018 09:40:01 +0000 Message-Id: <20180305094006.21446-2-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.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 05 Mar 2018 09:40:17 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 05 Mar 2018 09:40:17 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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 1/6] util/uri.c: Coding style check, Only whitespace involved 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 Using `clang-format -i util/uri.c` first, then change back few code manually, to make sure only whitespace involved. Signed-off-by: Su Hang Reviewed-by: Thomas Huth Message-id: 1519533358-13759-2-git-send-email-suhang16@mails.ucas.ac.cn Signed-off-by: Stefan Hajnoczi --- util/uri.c | 1450 ++++++++++++++++++++++++++++++--------------------------= ---- 1 file changed, 726 insertions(+), 724 deletions(-) diff --git a/util/uri.c b/util/uri.c index 21b1828170..cf09f41735 100644 --- a/util/uri.c +++ b/util/uri.c @@ -63,7 +63,6 @@ static void uri_clean(URI *uri); */ #define IS_ALPHA(x) (IS_LOWALPHA(x) || IS_UPALPHA(x)) =20 - /* * lowalpha =3D "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | * "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | @@ -97,27 +96,27 @@ static void uri_clean(URI *uri); * mark =3D "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")" */ =20 -#define IS_MARK(x) (((x) =3D=3D '-') || ((x) =3D=3D '_') || ((x) =3D=3D '.= ') || \ - ((x) =3D=3D '!') || ((x) =3D=3D '~') || ((x) =3D=3D '*') || ((x) =3D= =3D '\'') || \ +#define IS_MARK(x) (((x) =3D=3D '-') || ((x) =3D=3D '_') || ((x) =3D=3D '.= ') || \ + ((x) =3D=3D '!') || ((x) =3D=3D '~') || ((x) =3D=3D '*') || ((x) =3D= =3D '\'') || \ ((x) =3D=3D '(') || ((x) =3D=3D ')')) =20 /* * unwise =3D "{" | "}" | "|" | "\" | "^" | "`" */ =20 -#define IS_UNWISE(p) \ - (((*(p) =3D=3D '{')) || ((*(p) =3D=3D '}')) || ((*(p) =3D=3D '|')) |= | \ - ((*(p) =3D=3D '\\')) || ((*(p) =3D=3D '^')) || ((*(p) =3D=3D '[')) = || \ - ((*(p) =3D=3D ']')) || ((*(p) =3D=3D '`'))) +#define IS_UNWISE(p) = \ + (((*(p) =3D=3D '{')) || ((*(p) =3D=3D '}')) || ((*(p) =3D=3D '|')) || = \ + ((*(p) =3D=3D '\\')) || ((*(p) =3D=3D '^')) || ((*(p) =3D=3D '[')) ||= \ + ((*(p) =3D=3D ']')) || ((*(p) =3D=3D '`'))) /* * reserved =3D ";" | "/" | "?" | ":" | "@" | "&" | "=3D" | "+" | "$" | ",= " | * "[" | "]" */ =20 -#define IS_RESERVED(x) (((x) =3D=3D ';') || ((x) =3D=3D '/') || ((x) =3D= =3D '?') || \ - ((x) =3D=3D ':') || ((x) =3D=3D '@') || ((x) =3D=3D '&') || ((x) = =3D=3D '=3D') || \ - ((x) =3D=3D '+') || ((x) =3D=3D '$') || ((x) =3D=3D ',') || ((x) = =3D=3D '[') || \ - ((x) =3D=3D ']')) +#define IS_RESERVED(x) (((x) =3D=3D ';') || ((x) =3D=3D '/') || ((x) =3D= =3D '?') || \ + ((x) =3D=3D ':') || ((x) =3D=3D '@') || ((x) =3D=3D '&') || ((x) =3D= =3D '=3D') || \ + ((x) =3D=3D '+') || ((x) =3D=3D '$') || ((x) =3D=3D ',') || ((x) =3D= =3D '[') || \ + ((x) =3D=3D ']')) =20 /* * unreserved =3D alphanum | mark @@ -129,7 +128,7 @@ static void uri_clean(URI *uri); * Skip to next pointer char, handle escaped sequences */ =20 -#define NEXT(p) ((*p =3D=3D '%')? p +=3D 3 : p++) +#define NEXT(p) ((*p =3D=3D '%') ? p +=3D 3 : p++) =20 /* * Productions from the spec. @@ -141,37 +140,36 @@ static void uri_clean(URI *uri); * path =3D [ abs_path | opaque_part ] */ =20 - /************************************************************************ - * * - * RFC 3986 parser * - * * + * * + * RFC 3986 parser * + * * ************************************************************************/ =20 #define ISA_DIGIT(p) ((*(p) >=3D '0') && (*(p) <=3D '9')) -#define ISA_ALPHA(p) (((*(p) >=3D 'a') && (*(p) <=3D 'z')) || \ +#define ISA_ALPHA(p) (((*(p) >=3D 'a') && (*(p) <=3D 'z')) || = \ ((*(p) >=3D 'A') && (*(p) <=3D 'Z'))) -#define ISA_HEXDIG(p) \ - (ISA_DIGIT(p) || ((*(p) >=3D 'a') && (*(p) <=3D 'f')) || \ - ((*(p) >=3D 'A') && (*(p) <=3D 'F'))) +#define ISA_HEXDIG(p) = \ + (ISA_DIGIT(p) || ((*(p) >=3D 'a') && (*(p) <=3D 'f')) || = \ + ((*(p) >=3D 'A') && (*(p) <=3D 'F'))) =20 /* * sub-delims =3D "!" / "$" / "&" / "'" / "(" / ")" * / "*" / "+" / "," / ";" / "=3D" */ -#define ISA_SUB_DELIM(p) \ - (((*(p) =3D=3D '!')) || ((*(p) =3D=3D '$')) || ((*(p) =3D=3D '&')) |= | \ - ((*(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 '\''))) +#define ISA_SUB_DELIM(p) = \ + (((*(p) =3D=3D '!')) || ((*(p) =3D=3D '$')) || ((*(p) =3D=3D '&')) || = \ + ((*(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 '\''))) =20 /* * gen-delims =3D ":" / "/" / "?" / "#" / "[" / "]" / "@" */ -#define ISA_GEN_DELIM(p) \ - (((*(p) =3D=3D ':')) || ((*(p) =3D=3D '/')) || ((*(p) =3D=3D '?')) |= | \ - ((*(p) =3D=3D '#')) || ((*(p) =3D=3D '[')) || ((*(p) =3D=3D ']')) |= | \ - ((*(p) =3D=3D '@'))) +#define ISA_GEN_DELIM(p) = \ + (((*(p) =3D=3D ':')) || ((*(p) =3D=3D '/')) || ((*(p) =3D=3D '?')) || = \ + ((*(p) =3D=3D '#')) || ((*(p) =3D=3D '[')) || ((*(p) =3D=3D ']')) || = \ + ((*(p) =3D=3D '@'))) =20 /* * reserved =3D gen-delims / sub-delims @@ -181,22 +179,22 @@ static void uri_clean(URI *uri); /* * unreserved =3D ALPHA / DIGIT / "-" / "." / "_" / "~" */ -#define ISA_UNRESERVED(p) \ - ((ISA_ALPHA(p)) || (ISA_DIGIT(p)) || ((*(p) =3D=3D '-')) || \ - ((*(p) =3D=3D '.')) || ((*(p) =3D=3D '_')) || ((*(p) =3D=3D '~'))) +#define ISA_UNRESERVED(p) = \ + ((ISA_ALPHA(p)) || (ISA_DIGIT(p)) || ((*(p) =3D=3D '-')) || = \ + ((*(p) =3D=3D '.')) || ((*(p) =3D=3D '_')) || ((*(p) =3D=3D '~'))) =20 /* * pct-encoded =3D "%" HEXDIG HEXDIG */ -#define ISA_PCT_ENCODED(p) \ - ((*(p) =3D=3D '%') && (ISA_HEXDIG(p + 1)) && (ISA_HEXDIG(p + 2))) +#define ISA_PCT_ENCODED(p) = \ + ((*(p) =3D=3D '%') && (ISA_HEXDIG(p + 1)) && (ISA_HEXDIG(p + 2))) =20 /* * pchar =3D unreserved / pct-encoded / sub-delims / ":" / "@" */ -#define ISA_PCHAR(p) \ - (ISA_UNRESERVED(p) || ISA_PCT_ENCODED(p) || ISA_SUB_DELIM(p) || \ - ((*(p) =3D=3D ':')) || ((*(p) =3D=3D '@'))) +#define ISA_PCHAR(p) = \ + (ISA_UNRESERVED(p) || ISA_PCT_ENCODED(p) || ISA_SUB_DELIM(p) || = \ + ((*(p) =3D=3D ':')) || ((*(p) =3D=3D '@'))) =20 /** * rfc3986_parse_scheme: @@ -209,25 +207,26 @@ static void uri_clean(URI *uri); * * Returns 0 or the error code */ -static int -rfc3986_parse_scheme(URI *uri, const char **str) { +static int rfc3986_parse_scheme(URI *uri, const char **str) +{ const char *cur; =20 if (str =3D=3D NULL) - return(-1); + return (-1); =20 cur =3D *str; if (!ISA_ALPHA(cur)) - return(2); + return (2); cur++; - while (ISA_ALPHA(cur) || ISA_DIGIT(cur) || - (*cur =3D=3D '+') || (*cur =3D=3D '-') || (*cur =3D=3D '.')) cu= r++; + while (ISA_ALPHA(cur) || ISA_DIGIT(cur) || (*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); + uri->scheme =3D g_strndup(*str, cur - *str); } *str =3D cur; - return(0); + return (0); } =20 /** @@ -245,8 +244,7 @@ rfc3986_parse_scheme(URI *uri, const char **str) { * * Returns 0 or the error code */ -static int -rfc3986_parse_fragment(URI *uri, const char **str) +static int rfc3986_parse_fragment(URI *uri, const char **str) { const char *cur; =20 @@ -261,10 +259,10 @@ rfc3986_parse_fragment(URI *uri, const char **str) NEXT(cur); if (uri !=3D NULL) { g_free(uri->fragment); - if (uri->cleanup & 2) - uri->fragment =3D g_strndup(*str, cur - *str); - else - uri->fragment =3D uri_string_unescape(*str, cur - *str, NULL); + if (uri->cleanup & 2) + uri->fragment =3D g_strndup(*str, cur - *str); + else + uri->fragment =3D uri_string_unescape(*str, cur - *str, NULL); } *str =3D cur; return (0); @@ -281,8 +279,7 @@ rfc3986_parse_fragment(URI *uri, const char **str) * * Returns 0 or the error code */ -static int -rfc3986_parse_query(URI *uri, const char **str) +static int rfc3986_parse_query(URI *uri, const char **str) { const char *cur; =20 @@ -296,7 +293,7 @@ rfc3986_parse_query(URI *uri, const char **str) NEXT(cur); if (uri !=3D NULL) { g_free(uri->query); - uri->query =3D g_strndup (*str, cur - *str); + uri->query =3D g_strndup(*str, cur - *str); } *str =3D cur; return (0); @@ -314,8 +311,7 @@ rfc3986_parse_query(URI *uri, const char **str) * * Returns 0 or the error code */ -static int -rfc3986_parse_port(URI *uri, const char **str) +static int rfc3986_parse_port(URI *uri, const char **str) { const char *cur =3D *str; int port =3D 0; @@ -349,27 +345,26 @@ rfc3986_parse_port(URI *uri, const char **str) * * Returns 0 or the error code */ -static int -rfc3986_parse_user_info(URI *uri, const char **str) +static int rfc3986_parse_user_info(URI *uri, const char **str) { const char *cur; =20 cur =3D *str; - while (ISA_UNRESERVED(cur) || ISA_PCT_ENCODED(cur) || - ISA_SUB_DELIM(cur) || (*cur =3D=3D ':')) - NEXT(cur); + while (ISA_UNRESERVED(cur) || ISA_PCT_ENCODED(cur) || ISA_SUB_DELIM(cu= r) || + (*cur =3D=3D ':')) + NEXT(cur); if (*cur =3D=3D '@') { - if (uri !=3D NULL) { + if (uri !=3D NULL) { g_free(uri->user); - if (uri->cleanup & 2) - uri->user =3D g_strndup(*str, cur - *str); - else - uri->user =3D uri_string_unescape(*str, cur - *str, NULL); - } - *str =3D cur; - return(0); + if (uri->cleanup & 2) + uri->user =3D g_strndup(*str, cur - *str); + else + uri->user =3D uri_string_unescape(*str, cur - *str, NULL); + } + *str =3D cur; + return (0); } - return(1); + return (1); } =20 /** @@ -386,28 +381,28 @@ rfc3986_parse_user_info(URI *uri, const char **str) * * Returns 0 if found and skipped, 1 otherwise */ -static int -rfc3986_parse_dec_octet(const char **str) { +static int rfc3986_parse_dec_octet(const char **str) +{ const char *cur =3D *str; =20 if (!(ISA_DIGIT(cur))) - return(1); - if (!ISA_DIGIT(cur+1)) - cur++; - else if ((*cur !=3D '0') && (ISA_DIGIT(cur + 1)) && (!ISA_DIGIT(cur+2)= )) - cur +=3D 2; + return (1); + if (!ISA_DIGIT(cur + 1)) + cur++; + 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))) - cur +=3D 3; - 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')) - cur +=3D 3; + cur +=3D 3; + 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')) + cur +=3D 3; else - return(1); + return (1); *str =3D cur; - return(0); + return (0); } /** * rfc3986_parse_host: @@ -424,8 +419,7 @@ rfc3986_parse_dec_octet(const char **str) { * * Returns 0 or the error code */ -static int -rfc3986_parse_host(URI *uri, const char **str) +static int rfc3986_parse_host(URI *uri, const char **str) { const char *cur =3D *str; const char *host; @@ -436,34 +430,34 @@ rfc3986_parse_host(URI *uri, const char **str) */ if (*cur =3D=3D '[') { cur++; - while ((*cur !=3D ']') && (*cur !=3D 0)) - cur++; - if (*cur !=3D ']') - return(1); - cur++; - goto found; + while ((*cur !=3D ']') && (*cur !=3D 0)) + cur++; + if (*cur !=3D ']') + return (1); + cur++; + goto found; } /* * try to parse an IPv4 */ if (ISA_DIGIT(cur)) { if (rfc3986_parse_dec_octet(&cur) !=3D 0) - goto not_ipv4; - if (*cur !=3D '.') - goto not_ipv4; - cur++; + goto not_ipv4; + if (*cur !=3D '.') + goto not_ipv4; + cur++; if (rfc3986_parse_dec_octet(&cur) !=3D 0) - goto not_ipv4; - if (*cur !=3D '.') - goto not_ipv4; + goto not_ipv4; + if (*cur !=3D '.') + goto not_ipv4; if (rfc3986_parse_dec_octet(&cur) !=3D 0) - goto not_ipv4; - if (*cur !=3D '.') - goto not_ipv4; + goto not_ipv4; + if (*cur !=3D '.') + goto not_ipv4; if (rfc3986_parse_dec_octet(&cur) !=3D 0) - goto not_ipv4; - goto found; -not_ipv4: + goto not_ipv4; + goto found; + not_ipv4: cur =3D *str; } /* @@ -474,18 +468,18 @@ not_ipv4: found: if (uri !=3D NULL) { g_free(uri->authority); - uri->authority =3D NULL; + uri->authority =3D NULL; g_free(uri->server); - if (cur !=3D host) { - if (uri->cleanup & 2) - uri->server =3D g_strndup(host, cur - host); - else - uri->server =3D uri_string_unescape(host, cur - host, NULL); - } else - uri->server =3D NULL; + if (cur !=3D host) { + if (uri->cleanup & 2) + uri->server =3D g_strndup(host, cur - host); + else + uri->server =3D uri_string_unescape(host, cur - host, NULL= ); + } else + uri->server =3D NULL; } *str =3D cur; - return(0); + return (0); } =20 /** @@ -500,8 +494,7 @@ found: * * Returns 0 or the error code */ -static int -rfc3986_parse_authority(URI *uri, const char **str) +static int rfc3986_parse_authority(URI *uri, const char **str) { const char *cur; int ret; @@ -516,14 +509,16 @@ rfc3986_parse_authority(URI *uri, const char **str) else cur++; ret =3D rfc3986_parse_host(uri, &cur); - if (ret !=3D 0) return(ret); + if (ret !=3D 0) + return (ret); if (*cur =3D=3D ':') { cur++; ret =3D rfc3986_parse_port(uri, &cur); - if (ret !=3D 0) return(ret); + if (ret !=3D 0) + return (ret); } *str =3D cur; - return(0); + return (0); } =20 /** @@ -542,16 +537,15 @@ rfc3986_parse_authority(URI *uri, const char **str) * * Returns 0 or the error code */ -static int -rfc3986_parse_segment(const char **str, char forbid, int empty) +static int rfc3986_parse_segment(const char **str, char forbid, int empty) { const char *cur; =20 cur =3D *str; if (!ISA_PCHAR(cur)) { if (empty) - return(0); - return(1); + return (0); + return (1); } while (ISA_PCHAR(cur) && (*cur !=3D forbid)) NEXT(cur); @@ -571,8 +565,7 @@ rfc3986_parse_segment(const char **str, char forbid, in= t empty) * * Returns 0 or the error code */ -static int -rfc3986_parse_path_ab_empty(URI *uri, const char **str) +static int rfc3986_parse_path_ab_empty(URI *uri, const char **str) { const char *cur; int ret; @@ -581,8 +574,9 @@ rfc3986_parse_path_ab_empty(URI *uri, const char **str) =20 while (*cur =3D=3D '/') { cur++; - ret =3D rfc3986_parse_segment(&cur, 0, 1); - if (ret !=3D 0) return(ret); + ret =3D rfc3986_parse_segment(&cur, 0, 1); + if (ret !=3D 0) + return (ret); } if (uri !=3D NULL) { g_free(uri->path); @@ -611,8 +605,7 @@ rfc3986_parse_path_ab_empty(URI *uri, const char **str) * * Returns 0 or the error code */ -static int -rfc3986_parse_path_absolute(URI *uri, const char **str) +static int rfc3986_parse_path_absolute(URI *uri, const char **str) { const char *cur; int ret; @@ -620,15 +613,16 @@ rfc3986_parse_path_absolute(URI *uri, const char **st= r) cur =3D *str; =20 if (*cur !=3D '/') - return(1); + 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) return(ret); - } + while (*cur =3D=3D '/') { + cur++; + ret =3D rfc3986_parse_segment(&cur, 0, 1); + if (ret !=3D 0) + return (ret); + } } if (uri !=3D NULL) { g_free(uri->path); @@ -657,8 +651,7 @@ rfc3986_parse_path_absolute(URI *uri, const char **str) * * Returns 0 or the error code */ -static int -rfc3986_parse_path_rootless(URI *uri, const char **str) +static int rfc3986_parse_path_rootless(URI *uri, const char **str) { const char *cur; int ret; @@ -666,11 +659,13 @@ rfc3986_parse_path_rootless(URI *uri, const char **st= r) cur =3D *str; =20 ret =3D rfc3986_parse_segment(&cur, 0, 0); - if (ret !=3D 0) return(ret); + if (ret !=3D 0) + return (ret); while (*cur =3D=3D '/') { cur++; - ret =3D rfc3986_parse_segment(&cur, 0, 1); - if (ret !=3D 0) return(ret); + ret =3D rfc3986_parse_segment(&cur, 0, 1); + if (ret !=3D 0) + return (ret); } if (uri !=3D NULL) { g_free(uri->path); @@ -699,8 +694,7 @@ rfc3986_parse_path_rootless(URI *uri, const char **str) * * Returns 0 or the error code */ -static int -rfc3986_parse_path_no_scheme(URI *uri, const char **str) +static int rfc3986_parse_path_no_scheme(URI *uri, const char **str) { const char *cur; int ret; @@ -708,11 +702,13 @@ rfc3986_parse_path_no_scheme(URI *uri, const char **s= tr) cur =3D *str; =20 ret =3D rfc3986_parse_segment(&cur, ':', 0); - if (ret !=3D 0) return(ret); + if (ret !=3D 0) + return (ret); while (*cur =3D=3D '/') { cur++; - ret =3D rfc3986_parse_segment(&cur, 0, 1); - if (ret !=3D 0) return(ret); + ret =3D rfc3986_parse_segment(&cur, 0, 1); + if (ret !=3D 0) + return (ret); } if (uri !=3D NULL) { g_free(uri->path); @@ -744,8 +740,7 @@ rfc3986_parse_path_no_scheme(URI *uri, const char **str) * * Returns 0 or the error code */ -static int -rfc3986_parse_hier_part(URI *uri, const char **str) +static int rfc3986_parse_hier_part(URI *uri, const char **str) { const char *cur; int ret; @@ -754,24 +749,28 @@ rfc3986_parse_hier_part(URI *uri, const char **str) =20 if ((*cur =3D=3D '/') && (*(cur + 1) =3D=3D '/')) { cur +=3D 2; - ret =3D rfc3986_parse_authority(uri, &cur); - if (ret !=3D 0) return(ret); - ret =3D rfc3986_parse_path_ab_empty(uri, &cur); - if (ret !=3D 0) return(ret); - *str =3D cur; - return(0); + ret =3D rfc3986_parse_authority(uri, &cur); + if (ret !=3D 0) + return (ret); + ret =3D rfc3986_parse_path_ab_empty(uri, &cur); + 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) return(ret); + if (ret !=3D 0) + return (ret); } else if (ISA_PCHAR(cur)) { ret =3D rfc3986_parse_path_rootless(uri, &cur); - if (ret !=3D 0) return(ret); + if (ret !=3D 0) + return (ret); } else { - /* path-empty is effectively empty */ - if (uri !=3D NULL) { + /* path-empty is effectively empty */ + if (uri !=3D NULL) { g_free(uri->path); - uri->path =3D NULL; - } + uri->path =3D NULL; + } } *str =3D cur; return (0); @@ -793,48 +792,53 @@ rfc3986_parse_hier_part(URI *uri, const char **str) * * Returns 0 or the error code */ -static int -rfc3986_parse_relative_ref(URI *uri, const char *str) { +static int rfc3986_parse_relative_ref(URI *uri, const char *str) +{ int ret; =20 if ((*str =3D=3D '/') && (*(str + 1) =3D=3D '/')) { str +=3D 2; - ret =3D rfc3986_parse_authority(uri, &str); - if (ret !=3D 0) return(ret); - ret =3D rfc3986_parse_path_ab_empty(uri, &str); - if (ret !=3D 0) return(ret); + ret =3D rfc3986_parse_authority(uri, &str); + if (ret !=3D 0) + return (ret); + ret =3D rfc3986_parse_path_ab_empty(uri, &str); + if (ret !=3D 0) + return (ret); } else if (*str =3D=3D '/') { - ret =3D rfc3986_parse_path_absolute(uri, &str); - if (ret !=3D 0) return(ret); + ret =3D rfc3986_parse_path_absolute(uri, &str); + if (ret !=3D 0) + return (ret); } else if (ISA_PCHAR(str)) { ret =3D rfc3986_parse_path_no_scheme(uri, &str); - if (ret !=3D 0) return(ret); + if (ret !=3D 0) + return (ret); } else { - /* path-empty is effectively empty */ - if (uri !=3D NULL) { + /* path-empty is effectively empty */ + if (uri !=3D NULL) { g_free(uri->path); - uri->path =3D NULL; - } + uri->path =3D NULL; + } } =20 if (*str =3D=3D '?') { - str++; - ret =3D rfc3986_parse_query(uri, &str); - if (ret !=3D 0) return(ret); + str++; + ret =3D rfc3986_parse_query(uri, &str); + if (ret !=3D 0) + return (ret); } if (*str =3D=3D '#') { - str++; - ret =3D rfc3986_parse_fragment(uri, &str); - if (ret !=3D 0) return(ret); + str++; + ret =3D rfc3986_parse_fragment(uri, &str); + if (ret !=3D 0) + return (ret); } if (*str !=3D 0) { - uri_clean(uri); - return(1); + uri_clean(uri); + return (1); } - return(0); + return (0); } =20 - /** * rfc3986_parse: * @uri: pointer to an URI structure @@ -847,33 +851,37 @@ rfc3986_parse_relative_ref(URI *uri, const char *str)= { * * Returns 0 or the error code */ -static int -rfc3986_parse(URI *uri, const char *str) { +static int rfc3986_parse(URI *uri, const char *str) +{ int ret; =20 ret =3D rfc3986_parse_scheme(uri, &str); - if (ret !=3D 0) return(ret); + if (ret !=3D 0) + return (ret); if (*str !=3D ':') { - return(1); + return (1); } str++; ret =3D rfc3986_parse_hier_part(uri, &str); - if (ret !=3D 0) return(ret); + if (ret !=3D 0) + return (ret); if (*str =3D=3D '?') { - str++; - ret =3D rfc3986_parse_query(uri, &str); - if (ret !=3D 0) return(ret); + str++; + ret =3D rfc3986_parse_query(uri, &str); + if (ret !=3D 0) + return (ret); } if (*str =3D=3D '#') { - str++; - ret =3D rfc3986_parse_fragment(uri, &str); - if (ret !=3D 0) return(ret); + str++; + ret =3D rfc3986_parse_fragment(uri, &str); + if (ret !=3D 0) + return (ret); } if (*str !=3D 0) { - uri_clean(uri); - return(1); + uri_clean(uri); + return (1); } - return(0); + return (0); } =20 /** @@ -888,12 +896,12 @@ rfc3986_parse(URI *uri, const char *str) { * * Returns 0 or the error code */ -static int -rfc3986_parse_uri_reference(URI *uri, const char *str) { +static int rfc3986_parse_uri_reference(URI *uri, const char *str) +{ int ret; =20 if (str =3D=3D NULL) - return(-1); + return (-1); uri_clean(uri); =20 /* @@ -902,14 +910,14 @@ rfc3986_parse_uri_reference(URI *uri, const char *str= ) { */ ret =3D rfc3986_parse(uri, str); if (ret !=3D 0) { - uri_clean(uri); + uri_clean(uri); ret =3D rfc3986_parse_relative_ref(uri, str); - if (ret !=3D 0) { - uri_clean(uri); - return(ret); - } + if (ret !=3D 0) { + uri_clean(uri); + return (ret); + } } - return(0); + return (0); } =20 /** @@ -922,20 +930,20 @@ rfc3986_parse_uri_reference(URI *uri, const char *str= ) { * * Returns a newly built URI or NULL in case of error */ -URI * -uri_parse(const char *str) { +URI *uri_parse(const char *str) +{ URI *uri; int ret; =20 if (str =3D=3D NULL) - return(NULL); + return (NULL); uri =3D uri_new(); ret =3D rfc3986_parse_uri_reference(uri, str); if (ret) { uri_free(uri); - return(NULL); + return (NULL); } - return(uri); + return (uri); } =20 /** @@ -950,9 +958,9 @@ uri_parse(const char *str) { * * Returns 0 or the error code */ -int -uri_parse_into(URI *uri, const char *str) { - return(rfc3986_parse_uri_reference(uri, str)); +int uri_parse_into(URI *uri, const char *str) +{ + return (rfc3986_parse_uri_reference(uri, str)); } =20 /** @@ -966,13 +974,13 @@ uri_parse_into(URI *uri, const char *str) { * * Returns a newly built URI or NULL in case of error */ -URI * -uri_parse_raw(const char *str, int raw) { +URI *uri_parse_raw(const char *str, int raw) +{ URI *uri; int ret; =20 if (str =3D=3D NULL) - return(NULL); + return (NULL); uri =3D uri_new(); if (raw) { uri->cleanup |=3D 2; @@ -980,15 +988,15 @@ uri_parse_raw(const char *str, int raw) { ret =3D uri_parse_into(uri, str); if (ret) { uri_free(uri); - return(NULL); + return (NULL); } - return(uri); + return (uri); } =20 /************************************************************************ - * * - * Generic URI structure functions * - * * + * * + * Generic URI structure functions * + * * ************************************************************************/ =20 /** @@ -998,12 +1006,12 @@ uri_parse_raw(const char *str, int raw) { * * Returns the new structure or NULL in case of error */ -URI * -uri_new(void) { +URI *uri_new(void) +{ URI *ret; =20 ret =3D g_new0(URI, 1); - return(ret); + return (ret); } =20 /** @@ -1012,15 +1020,15 @@ uri_new(void) { * Function to handle properly a reallocation when saving an URI * Also imposes some limit on the length of an URI string output */ -static char * -realloc2n(char *ret, int *max) { +static char *realloc2n(char *ret, int *max) +{ char *temp; int tmp; =20 tmp =3D *max * 2; temp =3D g_realloc(ret, (tmp + 1)); *max =3D tmp; - return(temp); + return (temp); } =20 /** @@ -1031,221 +1039,217 @@ realloc2n(char *ret, int *max) { * * Returns a new string (to be deallocated by caller) */ -char * -uri_to_string(URI *uri) { +char *uri_to_string(URI *uri) +{ char *ret =3D NULL; char *temp; const char *p; int len; int max; =20 - if (uri =3D=3D NULL) return(NULL); - + if (uri =3D=3D NULL) + return (NULL); =20 max =3D 80; ret =3D g_malloc(max + 1); len =3D 0; =20 if (uri->scheme !=3D NULL) { - p =3D uri->scheme; - while (*p !=3D 0) { - if (len >=3D max) { + p =3D uri->scheme; + while (*p !=3D 0) { + if (len >=3D max) { temp =3D realloc2n(ret, &max); - ret =3D temp; - } - ret[len++] =3D *p++; - } - if (len >=3D max) { + ret =3D temp; + } + ret[len++] =3D *p++; + } + if (len >=3D max) { temp =3D realloc2n(ret, &max); ret =3D temp; - } - ret[len++] =3D ':'; + } + ret[len++] =3D ':'; } if (uri->opaque !=3D NULL) { - p =3D uri->opaque; - while (*p !=3D 0) { - if (len + 3 >=3D max) { + p =3D uri->opaque; + while (*p !=3D 0) { + if (len + 3 >=3D max) { temp =3D realloc2n(ret, &max); ret =3D temp; - } - if (IS_RESERVED(*(p)) || IS_UNRESERVED(*(p))) - ret[len++] =3D *p++; - else { - int val =3D *(unsigned char *)p++; - int hi =3D val / 0x10, lo =3D val % 0x10; - ret[len++] =3D '%'; - ret[len++] =3D hi + (hi > 9? 'A'-10 : '0'); - ret[len++] =3D lo + (lo > 9? 'A'-10 : '0'); - } - } + } + if (IS_RESERVED(*(p)) || IS_UNRESERVED(*(p))) + ret[len++] =3D *p++; + else { + int val =3D *(unsigned char *)p++; + int hi =3D val / 0x10, lo =3D val % 0x10; + ret[len++] =3D '%'; + ret[len++] =3D hi + (hi > 9 ? 'A' - 10 : '0'); + ret[len++] =3D lo + (lo > 9 ? 'A' - 10 : '0'); + } + } } else { - if (uri->server !=3D NULL) { - if (len + 3 >=3D max) { + if (uri->server !=3D NULL) { + if (len + 3 >=3D max) { temp =3D realloc2n(ret, &max); ret =3D temp; - } - ret[len++] =3D '/'; - ret[len++] =3D '/'; - if (uri->user !=3D NULL) { - p =3D uri->user; - while (*p !=3D 0) { - if (len + 3 >=3D max) { + } + ret[len++] =3D '/'; + ret[len++] =3D '/'; + if (uri->user !=3D NULL) { + p =3D uri->user; + while (*p !=3D 0) { + if (len + 3 >=3D max) { temp =3D realloc2n(ret, &max); ret =3D temp; - } - 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 ','))) - ret[len++] =3D *p++; - else { - int val =3D *(unsigned char *)p++; - int hi =3D val / 0x10, lo =3D val % 0x10; - ret[len++] =3D '%'; - ret[len++] =3D hi + (hi > 9? 'A'-10 : '0'); - ret[len++] =3D lo + (lo > 9? 'A'-10 : '0'); - } - } - if (len + 3 >=3D max) { + } + 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 ','))) + ret[len++] =3D *p++; + else { + int val =3D *(unsigned char *)p++; + int hi =3D val / 0x10, lo =3D val % 0x10; + ret[len++] =3D '%'; + ret[len++] =3D hi + (hi > 9 ? 'A' - 10 : '0'); + ret[len++] =3D lo + (lo > 9 ? 'A' - 10 : '0'); + } + } + if (len + 3 >=3D max) { temp =3D realloc2n(ret, &max); ret =3D temp; - } - ret[len++] =3D '@'; - } - p =3D uri->server; - while (*p !=3D 0) { - if (len >=3D max) { + } + ret[len++] =3D '@'; + } + p =3D uri->server; + while (*p !=3D 0) { + if (len >=3D max) { temp =3D realloc2n(ret, &max); ret =3D temp; - } - ret[len++] =3D *p++; - } - if (uri->port > 0) { - if (len + 10 >=3D max) { + } + ret[len++] =3D *p++; + } + if (uri->port > 0) { + if (len + 10 >=3D max) { temp =3D realloc2n(ret, &max); ret =3D temp; - } - len +=3D snprintf(&ret[len], max - len, ":%d", uri->port); - } - } else if (uri->authority !=3D NULL) { - if (len + 3 >=3D max) { + } + len +=3D snprintf(&ret[len], max - len, ":%d", uri->port); + } + } else if (uri->authority !=3D NULL) { + if (len + 3 >=3D max) { temp =3D realloc2n(ret, &max); ret =3D temp; - } - ret[len++] =3D '/'; - ret[len++] =3D '/'; - p =3D uri->authority; - while (*p !=3D 0) { - if (len + 3 >=3D max) { + } + ret[len++] =3D '/'; + ret[len++] =3D '/'; + p =3D uri->authority; + while (*p !=3D 0) { + if (len + 3 >=3D max) { temp =3D realloc2n(ret, &max); ret =3D temp; - } - 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 '+'))) - ret[len++] =3D *p++; - else { - int val =3D *(unsigned char *)p++; - int hi =3D val / 0x10, lo =3D val % 0x10; - ret[len++] =3D '%'; - ret[len++] =3D hi + (hi > 9? 'A'-10 : '0'); - ret[len++] =3D lo + (lo > 9? 'A'-10 : '0'); - } - } - } else if (uri->scheme !=3D NULL) { - if (len + 3 >=3D max) { + } + 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 '+'))) + ret[len++] =3D *p++; + else { + int val =3D *(unsigned char *)p++; + int hi =3D val / 0x10, lo =3D val % 0x10; + ret[len++] =3D '%'; + ret[len++] =3D hi + (hi > 9 ? 'A' - 10 : '0'); + ret[len++] =3D lo + (lo > 9 ? 'A' - 10 : '0'); + } + } + } else if (uri->scheme !=3D NULL) { + if (len + 3 >=3D max) { temp =3D realloc2n(ret, &max); ret =3D temp; - } - ret[len++] =3D '/'; - ret[len++] =3D '/'; - } - if (uri->path !=3D NULL) { - p =3D uri->path; - /* - * the colon in file:///d: should not be escaped or - * Windows accesses fail later. - */ - if ((uri->scheme !=3D NULL) && - (p[0] =3D=3D '/') && - (((p[1] >=3D 'a') && (p[1] <=3D 'z')) || - ((p[1] >=3D 'A') && (p[1] <=3D 'Z'))) && - (p[2] =3D=3D ':') && - (!strcmp(uri->scheme, "file"))) { - if (len + 3 >=3D max) { + } + ret[len++] =3D '/'; + ret[len++] =3D '/'; + } + if (uri->path !=3D NULL) { + p =3D uri->path; + /* + * the colon in file:///d: should not be escaped or + * Windows accesses fail later. + */ + if ((uri->scheme !=3D NULL) && (p[0] =3D=3D '/') && + (((p[1] >=3D 'a') && (p[1] <=3D 'z')) || + ((p[1] >=3D 'A') && (p[1] <=3D 'Z'))) && + (p[2] =3D=3D ':') && (!strcmp(uri->scheme, "file"))) { + if (len + 3 >=3D max) { temp =3D realloc2n(ret, &max); ret =3D temp; - } - ret[len++] =3D *p++; - ret[len++] =3D *p++; - ret[len++] =3D *p++; - } - while (*p !=3D 0) { - if (len + 3 >=3D max) { + } + ret[len++] =3D *p++; + ret[len++] =3D *p++; + ret[len++] =3D *p++; + } + while (*p !=3D 0) { + if (len + 3 >=3D max) { temp =3D realloc2n(ret, &max); ret =3D temp; - } - if ((IS_UNRESERVED(*(p))) || ((*(p) =3D=3D '/')) || + } + 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 ','))) - ret[len++] =3D *p++; - else { - int val =3D *(unsigned char *)p++; - int hi =3D val / 0x10, lo =3D val % 0x10; - ret[len++] =3D '%'; - ret[len++] =3D hi + (hi > 9? 'A'-10 : '0'); - ret[len++] =3D lo + (lo > 9? 'A'-10 : '0'); - } - } - } - if (uri->query !=3D NULL) { - if (len + 1 >=3D max) { + ((*(p) =3D=3D '=3D')) || ((*(p) =3D=3D '+')) || ((*(p)= =3D=3D '$')) || + ((*(p) =3D=3D ','))) + ret[len++] =3D *p++; + else { + int val =3D *(unsigned char *)p++; + int hi =3D val / 0x10, lo =3D val % 0x10; + ret[len++] =3D '%'; + ret[len++] =3D hi + (hi > 9 ? 'A' - 10 : '0'); + ret[len++] =3D lo + (lo > 9 ? 'A' - 10 : '0'); + } + } + } + if (uri->query !=3D NULL) { + if (len + 1 >=3D max) { temp =3D realloc2n(ret, &max); ret =3D temp; - } - ret[len++] =3D '?'; - p =3D uri->query; - while (*p !=3D 0) { - if (len + 1 >=3D max) { + } + ret[len++] =3D '?'; + p =3D uri->query; + while (*p !=3D 0) { + if (len + 1 >=3D max) { temp =3D realloc2n(ret, &max); ret =3D temp; - } - ret[len++] =3D *p++; - } - } + } + ret[len++] =3D *p++; + } + } } if (uri->fragment !=3D NULL) { - if (len + 3 >=3D max) { + if (len + 3 >=3D max) { temp =3D realloc2n(ret, &max); ret =3D temp; - } - ret[len++] =3D '#'; - p =3D uri->fragment; - while (*p !=3D 0) { - if (len + 3 >=3D max) { + } + ret[len++] =3D '#'; + p =3D uri->fragment; + while (*p !=3D 0) { + if (len + 3 >=3D max) { temp =3D realloc2n(ret, &max); ret =3D temp; - } - if ((IS_UNRESERVED(*(p))) || (IS_RESERVED(*(p)))) - ret[len++] =3D *p++; - else { - int val =3D *(unsigned char *)p++; - int hi =3D val / 0x10, lo =3D val % 0x10; - ret[len++] =3D '%'; - ret[len++] =3D hi + (hi > 9? 'A'-10 : '0'); - ret[len++] =3D lo + (lo > 9? 'A'-10 : '0'); - } - } + } + if ((IS_UNRESERVED(*(p))) || (IS_RESERVED(*(p)))) + ret[len++] =3D *p++; + else { + int val =3D *(unsigned char *)p++; + int hi =3D val / 0x10, lo =3D val % 0x10; + ret[len++] =3D '%'; + ret[len++] =3D hi + (hi > 9 ? 'A' - 10 : '0'); + ret[len++] =3D lo + (lo > 9 ? 'A' - 10 : '0'); + } + } } if (len >=3D max) { temp =3D realloc2n(ret, &max); ret =3D temp; } ret[len] =3D 0; - return(ret); + return (ret); } =20 /** @@ -1254,9 +1258,10 @@ uri_to_string(URI *uri) { * * Make sure the URI struct is free of content */ -static void -uri_clean(URI *uri) { - if (uri =3D=3D NULL) return; +static void uri_clean(URI *uri) +{ + if (uri =3D=3D NULL) + return; =20 g_free(uri->scheme); uri->scheme =3D NULL; @@ -1282,16 +1287,16 @@ uri_clean(URI *uri) { * * Free up the URI struct */ -void -uri_free(URI *uri) { +void uri_free(URI *uri) +{ uri_clean(uri); g_free(uri); } =20 /************************************************************************ - * * - * Helper functions * - * * + * * + * Helper functions * + * * ************************************************************************/ =20 /** @@ -1305,21 +1310,21 @@ uri_free(URI *uri) { * * Returns 0 or an error code */ -static int -normalize_uri_path(char *path) { +static int normalize_uri_path(char *path) +{ char *cur, *out; =20 if (path =3D=3D NULL) - return(-1); + 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 '/') - ++cur; + ++cur; if (cur[0] =3D=3D '\0') - return(0); + return (0); =20 /* Keep everything we've seen so far. */ out =3D cur; @@ -1328,46 +1333,46 @@ normalize_uri_path(char *path) { * Analyze each segment in sequence for cases (c) and (d). */ while (cur[0] !=3D '\0') { - /* - * c) All occurrences of "./", where "." is a complete path segment, - * are removed from the buffer string. - */ - 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 '/') - cur++; - continue; - } + /* + * c) All occurrences of "./", where "." is a complete path segmen= t, + * are removed from the buffer string. + */ + 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 '/') + cur++; + continue; + } =20 - /* - * d) If the buffer string ends with "." as a complete path segment, - * that "." is removed. - */ - if ((cur[0] =3D=3D '.') && (cur[1] =3D=3D '\0')) - break; + /* + * 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')) + break; =20 - /* Otherwise keep the segment. */ - while (cur[0] !=3D '/') { + /* Otherwise keep the segment. */ + while (cur[0] !=3D '/') { if (cur[0] =3D=3D '\0') - goto done_cd; - (out++)[0] =3D (cur++)[0]; - } - /* nomalize // */ - while ((cur[0] =3D=3D '/') && (cur[1] =3D=3D '/')) - cur++; + goto done_cd; + (out++)[0] =3D (cur++)[0]; + } + /* nomalize // */ + while ((cur[0] =3D=3D '/') && (cur[1] =3D=3D '/')) + cur++; =20 (out++)[0] =3D (cur++)[0]; } - done_cd: +done_cd: out[0] =3D '\0'; =20 /* Reset to the beginning of the first segment for the next sequence. = */ cur =3D path; while (cur[0] =3D=3D '/') - ++cur; + ++cur; if (cur[0] =3D=3D '\0') - return(0); + return (0); =20 /* * Analyze each segment in sequence for cases (e) and (f). @@ -1397,23 +1402,23 @@ normalize_uri_path(char *path) { /* Find the end of the current segment. */ segp =3D cur; while ((segp[0] !=3D '/') && (segp[0] !=3D '\0')) - ++segp; + ++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') - break; + break; =20 /* If the first segment is "..", or if the next segment _isn't_ ".= .", * keep this segment and try the next one. */ ++segp; - if (((cur[0] =3D=3D '.') && (cur[1] =3D=3D '.') && (segp =3D=3D cu= r+3)) - || ((segp[0] !=3D '.') || (segp[1] !=3D '.') - || ((segp[2] !=3D '/') && (segp[2] !=3D '\0')))) { - cur =3D segp; - continue; + if (((cur[0] =3D=3D '.') && (cur[1] =3D=3D '.') && (segp =3D=3D cu= r + 3)) || + ((segp[0] !=3D '.') || (segp[1] !=3D '.') || + ((segp[2] !=3D '/') && (segp[2] !=3D '\0')))) { + cur =3D segp; + continue; } =20 /* If we get here, remove this segment and the next one and back up @@ -1425,22 +1430,22 @@ normalize_uri_path(char *path) { =20 /* If this is the end of the buffer, we're done. */ if (segp[2] =3D=3D '\0') { - cur[0] =3D '\0'; - break; + cur[0] =3D '\0'; + break; } /* Valgrind complained, strcpy(cur, segp + 3); */ /* string will overlap, do not use strcpy */ tmp =3D cur; segp +=3D 3; while ((*tmp++ =3D *segp++) !=3D 0) - ; + ; =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) - continue; + 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 @@ -1451,7 +1456,7 @@ normalize_uri_path(char *path) { */ cur =3D segp; while ((cur > path) && (cur[-1] !=3D '/')) - --cur; + --cur; } out[0] =3D '\0'; =20 @@ -1467,31 +1472,30 @@ normalize_uri_path(char *path) { * We discard them from the final path. */ 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 +=3D 3; + 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 +=3D 3; =20 - if (cur !=3D path) { - out =3D path; - while (cur[0] !=3D '\0') - (out++)[0] =3D (cur++)[0]; - out[0] =3D 0; - } + if (cur !=3D path) { + out =3D path; + while (cur[0] !=3D '\0') + (out++)[0] =3D (cur++)[0]; + out[0] =3D 0; + } } =20 - return(0); + return (0); } =20 -static int is_hex(char c) { - if (((c >=3D '0') && (c <=3D '9')) || - ((c >=3D 'a') && (c <=3D 'f')) || +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'))) - return(1); - return(0); + return (1); + return (0); } =20 - /** * uri_string_unescape: * @str: the string to unescape @@ -1506,48 +1510,50 @@ static int is_hex(char c) { * Returns a copy of the string, but unescaped, will return NULL only in c= ase * of error */ -char * -uri_string_unescape(const char *str, int len, char *target) { +char *uri_string_unescape(const char *str, int len, char *target) +{ char *ret, *out; const char *in; =20 if (str =3D=3D NULL) - return(NULL); - if (len <=3D 0) len =3D strlen(str); - if (len < 0) return(NULL); + return (NULL); + if (len <=3D 0) + len =3D strlen(str); + if (len < 0) + return (NULL); =20 if (target =3D=3D NULL) { - ret =3D g_malloc(len + 1); + ret =3D g_malloc(len + 1); } else - ret =3D target; + 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')) - *out =3D (*in - '0'); - else if ((*in >=3D 'a') && (*in <=3D 'f')) - *out =3D (*in - 'a') + 10; - else if ((*in >=3D 'A') && (*in <=3D 'F')) - *out =3D (*in - 'A') + 10; - in++; - if ((*in >=3D '0') && (*in <=3D '9')) - *out =3D *out * 16 + (*in - '0'); - else if ((*in >=3D 'a') && (*in <=3D 'f')) - *out =3D *out * 16 + (*in - 'a') + 10; - else if ((*in >=3D 'A') && (*in <=3D 'F')) - *out =3D *out * 16 + (*in - 'A') + 10; - in++; - len -=3D 3; - out++; - } else { - *out++ =3D *in++; - len--; - } + 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')) + *out =3D (*in - '0'); + else if ((*in >=3D 'a') && (*in <=3D 'f')) + *out =3D (*in - 'a') + 10; + else if ((*in >=3D 'A') && (*in <=3D 'F')) + *out =3D (*in - 'A') + 10; + in++; + if ((*in >=3D '0') && (*in <=3D '9')) + *out =3D *out * 16 + (*in - '0'); + else if ((*in >=3D 'a') && (*in <=3D 'f')) + *out =3D *out * 16 + (*in - 'a') + 10; + else if ((*in >=3D 'A') && (*in <=3D 'F')) + *out =3D *out * 16 + (*in - 'A') + 10; + in++; + len -=3D 3; + out++; + } else { + *out++ =3D *in++; + len--; + } } *out =3D 0; - return(ret); + return (ret); } =20 /** @@ -1560,59 +1566,59 @@ uri_string_unescape(const char *str, int len, char = *target) { * * Returns a new escaped string or NULL in case of error. */ -char * -uri_string_escape(const char *str, const char *list) { +char *uri_string_escape(const char *str, const char *list) +{ char *ret, ch; char *temp; const char *in; int len, out; =20 if (str =3D=3D NULL) - return(NULL); + return (NULL); if (str[0] =3D=3D 0) - return(g_strdup(str)); + return (g_strdup(str)); len =3D strlen(str); - if (!(len > 0)) return(NULL); + if (!(len > 0)) + return (NULL); =20 len +=3D 20; ret =3D g_malloc(len); in =3D str; out =3D 0; - while(*in !=3D 0) { - if (len - out <=3D 3) { + while (*in !=3D 0) { + if (len - out <=3D 3) { temp =3D realloc2n(ret, &len); - ret =3D temp; - } + ret =3D temp; + } =20 - ch =3D *in; - - if ((ch !=3D '@') && (!IS_UNRESERVED(ch)) && (!strchr(list, ch))) { - unsigned char val; - ret[out++] =3D '%'; - val =3D ch >> 4; - if (val <=3D 9) - ret[out++] =3D '0' + val; - else - ret[out++] =3D 'A' + val - 0xA; - val =3D ch & 0xF; - if (val <=3D 9) - ret[out++] =3D '0' + val; - else - ret[out++] =3D 'A' + val - 0xA; - in++; - } else { - ret[out++] =3D *in++; - } + ch =3D *in; =20 + if ((ch !=3D '@') && (!IS_UNRESERVED(ch)) && (!strchr(list, ch))) { + unsigned char val; + ret[out++] =3D '%'; + val =3D ch >> 4; + if (val <=3D 9) + ret[out++] =3D '0' + val; + else + ret[out++] =3D 'A' + val - 0xA; + val =3D ch & 0xF; + if (val <=3D 9) + ret[out++] =3D '0' + val; + else + ret[out++] =3D 'A' + val - 0xA; + in++; + } else { + ret[out++] =3D *in++; + } } ret[out] =3D 0; - return(ret); + return (ret); } =20 /************************************************************************ - * * - * Public functions * - * * + * * + * Public functions * + * * ************************************************************************/ =20 /** @@ -1630,8 +1636,8 @@ uri_string_escape(const char *str, const char *list) { * Returns a new URI string (to be freed by the caller) or NULL in case * of error. */ -char * -uri_resolve(const char *uri, const char *base) { +char *uri_resolve(const char *uri, const char *base) +{ char *val =3D NULL; int ret, len, indx, cur, out; URI *ref =3D NULL; @@ -1647,43 +1653,42 @@ uri_resolve(const char *uri, const char *base) { * URI. Should we do that here? */ if (uri =3D=3D NULL) - ret =3D -1; + ret =3D -1; else { - if (*uri) { - ref =3D uri_new(); - ret =3D uri_parse_into(ref, uri); - } - else - ret =3D 0; + if (*uri) { + ref =3D uri_new(); + ret =3D uri_parse_into(ref, uri); + } else + ret =3D 0; } if (ret !=3D 0) - goto done; + goto done; if ((ref !=3D NULL) && (ref->scheme !=3D NULL)) { - /* - * The URI is absolute don't modify. - */ - val =3D g_strdup(uri); - goto done; + /* + * The URI is absolute don't modify. + */ + val =3D g_strdup(uri); + goto done; } if (base =3D=3D NULL) - ret =3D -1; + ret =3D -1; else { - bas =3D uri_new(); - ret =3D uri_parse_into(bas, base); + bas =3D uri_new(); + ret =3D uri_parse_into(bas, base); } if (ret !=3D 0) { - if (ref) - val =3D uri_to_string(ref); - goto done; + if (ref) + val =3D uri_to_string(ref); + goto done; } if (ref =3D=3D NULL) { - /* - * the base fragment must be ignored - */ + /* + * the base fragment must be ignored + */ g_free(bas->fragment); bas->fragment =3D NULL; - val =3D uri_to_string(bas); - goto done; + val =3D uri_to_string(bas); + goto done; } =20 /* @@ -1700,23 +1705,23 @@ uri_resolve(const char *uri, const char *base) { */ res =3D uri_new(); if ((ref->scheme =3D=3D NULL) && (ref->path =3D=3D NULL) && - ((ref->authority =3D=3D NULL) && (ref->server =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) - res->authority =3D g_strdup(bas->authority); - else if (bas->server !=3D NULL) { + if (bas->authority !=3D NULL) + res->authority =3D g_strdup(bas->authority); + 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; - } + } res->path =3D g_strdup(bas->path); if (ref->query !=3D NULL) { - res->query =3D g_strdup (ref->query); + res->query =3D g_strdup(ref->query); } else { res->query =3D g_strdup(bas->query); } res->fragment =3D g_strdup(ref->fragment); - goto step_7; + goto step_7; } =20 /* @@ -1726,8 +1731,8 @@ uri_resolve(const char *uri, const char *base) { * scheme is inherited from the base URI's scheme component. */ if (ref->scheme !=3D NULL) { - val =3D uri_to_string(ref); - goto done; + val =3D uri_to_string(ref); + goto done; } res->scheme =3D g_strdup(bas->scheme); =20 @@ -1742,22 +1747,22 @@ 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) - res->authority =3D g_strdup(ref->authority); - else { - res->server =3D g_strdup(ref->server); + if (ref->authority !=3D NULL) + res->authority =3D g_strdup(ref->authority); + else { + res->server =3D g_strdup(ref->server); res->user =3D g_strdup(ref->user); res->port =3D ref->port; - } + } res->path =3D g_strdup(ref->path); - goto step_7; + goto step_7; } if (bas->authority !=3D NULL) - res->authority =3D g_strdup(bas->authority); + res->authority =3D g_strdup(bas->authority); 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; + res->port =3D bas->port; } =20 /* @@ -1765,11 +1770,10 @@ uri_resolve(const char *uri, const char *base) { * the reference is an absolute-path and we skip to step 7. */ if ((ref->path !=3D NULL) && (ref->path[0] =3D=3D '/')) { - res->path =3D g_strdup(ref->path); - goto step_7; + res->path =3D g_strdup(ref->path); + goto step_7; } =20 - /* * 6) If this step is reached, then we are resolving a relative-path * reference. The relative path needs to be merged with the base @@ -1780,9 +1784,9 @@ uri_resolve(const char *uri, const char *base) { */ len =3D 2; /* extra / and 0 */ if (ref->path !=3D NULL) - len +=3D strlen(ref->path); + len +=3D strlen(ref->path); if (bas->path !=3D NULL) - len +=3D strlen(bas->path); + len +=3D strlen(bas->path); res->path =3D g_malloc(len); res->path[0] =3D 0; =20 @@ -1794,18 +1798,18 @@ uri_resolve(const char *uri, const char *base) { cur =3D 0; out =3D 0; if (bas->path !=3D NULL) { - while (bas->path[cur] !=3D 0) { - while ((bas->path[cur] !=3D 0) && (bas->path[cur] !=3D '/')) - cur++; - if (bas->path[cur] =3D=3D 0) - break; + while (bas->path[cur] !=3D 0) { + while ((bas->path[cur] !=3D 0) && (bas->path[cur] !=3D '/')) + cur++; + if (bas->path[cur] =3D=3D 0) + break; =20 - cur++; - while (out < cur) { - res->path[out] =3D bas->path[out]; - out++; - } - } + cur++; + while (out < cur) { + res->path[out] =3D bas->path[out]; + out++; + } + } } res->path[out] =3D 0; =20 @@ -1814,15 +1818,15 @@ uri_resolve(const char *uri, const char *base) { * string. */ if (ref->path !=3D NULL && ref->path[0] !=3D 0) { - indx =3D 0; - /* - * Ensure the path includes a '/' - */ - 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++]; - } + indx =3D 0; + /* + * Ensure the path includes a '/' + */ + 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++]; + } } res->path[out] =3D 0; =20 @@ -1842,12 +1846,12 @@ step_7: =20 done: if (ref !=3D NULL) - uri_free(ref); + uri_free(ref); if (bas !=3D NULL) - uri_free(bas); + uri_free(bas); if (res !=3D NULL) - uri_free(res); - return(val); + uri_free(res); + return (val); } =20 /** @@ -1882,8 +1886,7 @@ done: * Returns a new URI string (to be freed by the caller) or NULL in case * error. */ -char * -uri_resolve_relative (const char *uri, const char * base) +char *uri_resolve_relative(const char *uri, const char *base) { char *val =3D NULL; int ret; @@ -1897,58 +1900,57 @@ uri_resolve_relative (const char *uri, const char *= base) int remove_path =3D 0; =20 if ((uri =3D=3D NULL) || (*uri =3D=3D 0)) - return NULL; + return NULL; =20 /* * First parse URI into a standard form */ - ref =3D uri_new (); + ref =3D uri_new(); /* If URI not already in "relative" form */ if (uri[0] !=3D '.') { - ret =3D uri_parse_into (ref, uri); - if (ret !=3D 0) - goto done; /* Error in URI, return NULL */ + ret =3D uri_parse_into(ref, uri); + if (ret !=3D 0) + goto done; /* Error in URI, return NULL */ } else - ref->path =3D g_strdup(uri); + ref->path =3D g_strdup(uri); =20 /* * Next parse base into the same standard form */ if ((base =3D=3D NULL) || (*base =3D=3D 0)) { - val =3D g_strdup (uri); - goto done; + val =3D g_strdup(uri); + goto done; } - bas =3D uri_new (); + bas =3D uri_new(); if (base[0] !=3D '.') { - ret =3D uri_parse_into (bas, base); - if (ret !=3D 0) - goto done; /* Error in base, return NULL */ + ret =3D uri_parse_into(bas, base); + if (ret !=3D 0) + goto done; /* Error in base, return NULL */ } else - bas->path =3D g_strdup(base); + bas->path =3D g_strdup(base); =20 /* * If the scheme / server on the URI differs from the base, * just return the URI */ if ((ref->scheme !=3D NULL) && - ((bas->scheme =3D=3D NULL) || - (strcmp (bas->scheme, ref->scheme)) || - (strcmp (bas->server, ref->server)))) { - val =3D g_strdup (uri); - goto done; + ((bas->scheme =3D=3D NULL) || (strcmp(bas->scheme, ref->scheme)) || + (strcmp(bas->server, ref->server)))) { + val =3D g_strdup(uri); + goto done; } if (bas->path =3D=3D ref->path || (bas->path && ref->path && !strcmp(bas->path, ref->path))) { - val =3D g_strdup(""); - goto done; + val =3D g_strdup(""); + goto done; } if (bas->path =3D=3D NULL) { - val =3D g_strdup(ref->path); - goto done; + val =3D g_strdup(ref->path); + goto done; } if (ref->path =3D=3D NULL) { - ref->path =3D (char *) "/"; - remove_path =3D 1; + ref->path =3D (char *)"/"; + remove_path =3D 1; } =20 /* @@ -1958,78 +1960,78 @@ uri_resolve_relative (const char *uri, const char *= base) * two path components may be missing (bug 316224) */ if (bas->path =3D=3D NULL) { - if (ref->path !=3D NULL) { - uptr =3D ref->path; - if (*uptr =3D=3D '/') - uptr++; - /* exception characters from uri_to_string */ - val =3D uri_string_escape(uptr, "/;&=3D+$,"); - } - goto done; + if (ref->path !=3D NULL) { + uptr =3D ref->path; + if (*uptr =3D=3D '/') + uptr++; + /* exception characters from uri_to_string */ + val =3D uri_string_escape(uptr, "/;&=3D+$,"); + } + goto done; } bptr =3D bas->path; if (ref->path =3D=3D NULL) { - for (ix =3D 0; bptr[ix] !=3D 0; ix++) { - if (bptr[ix] =3D=3D '/') - nbslash++; - } - uptr =3D NULL; - len =3D 1; /* this is for a string terminator only */ + for (ix =3D 0; bptr[ix] !=3D 0; ix++) { + if (bptr[ix] =3D=3D '/') + nbslash++; + } + uptr =3D NULL; + len =3D 1; /* this is for a string terminator only */ } else { - /* - * Next we compare the two strings and find where they first differ - */ - if ((ref->path[pos] =3D=3D '.') && (ref->path[pos+1] =3D=3D '/')) + /* + * Next we compare the two strings and find where they first differ + */ + 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 '/')) - bptr++; - while ((bptr[pos] =3D=3D ref->path[pos]) && (bptr[pos] !=3D 0)) - pos++; + else if ((*bptr =3D=3D '/') && (ref->path[pos] !=3D '/')) + bptr++; + 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(""); - goto done; /* (I can't imagine why anyone would do this) */ - } + if (bptr[pos] =3D=3D ref->path[pos]) { + val =3D g_strdup(""); + goto done; /* (I can't imagine why anyone would do this) */ + } =20 - /* - * In URI, "back up" to the last '/' encountered. This will be the - * beginning of the "unique" suffix of URI - */ - ix =3D pos; - 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 '/')) - ix -=3D 2; - for (; ix > 0; ix--) { - if (ref->path[ix] =3D=3D '/') - break; - } - if (ix =3D=3D 0) { - uptr =3D ref->path; - } else { - ix++; - uptr =3D &ref->path[ix]; - } + /* + * In URI, "back up" to the last '/' encountered. This will be the + * beginning of the "unique" suffix of URI + */ + ix =3D pos; + 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 '/')) + ix -=3D 2; + for (; ix > 0; ix--) { + if (ref->path[ix] =3D=3D '/') + break; + } + if (ix =3D=3D 0) { + uptr =3D ref->path; + } else { + ix++; + uptr =3D &ref->path[ix]; + } =20 - /* - * In base, count the number of '/' from the differing point - */ - 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 '/') - nbslash++; - } - } - len =3D strlen (uptr) + 1; + /* + * In base, count the number of '/' from the differing point + */ + 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 '/') + nbslash++; + } + } + len =3D strlen(uptr) + 1; } =20 if (nbslash =3D=3D 0) { - if (uptr !=3D NULL) - /* exception characters from uri_to_string */ - val =3D uri_string_escape(uptr, "/;&=3D+$,"); - goto done; + if (uptr !=3D NULL) + /* exception characters from uri_to_string */ + val =3D uri_string_escape(uptr, "/;&=3D+$,"); + goto done; } =20 /* @@ -2037,35 +2039,35 @@ uri_resolve_relative (const char *uri, const char *= base) * length of the remainder of the URI, plus enough space * for the "../" groups, plus one for the terminator */ - val =3D g_malloc (len + 3 * nbslash); + val =3D g_malloc(len + 3 * nbslash); vptr =3D val; /* * Put in as many "../" as needed */ - for (; nbslash>0; nbslash--) { - *vptr++ =3D '.'; - *vptr++ =3D '.'; - *vptr++ =3D '/'; + for (; nbslash > 0; nbslash--) { + *vptr++ =3D '.'; + *vptr++ =3D '.'; + *vptr++ =3D '/'; } /* * Finish up with the end of the URI */ if (uptr !=3D NULL) { - if ((vptr > val) && (len > 0) && - (uptr[0] =3D=3D '/') && (vptr[-1] =3D=3D '/')) { - memcpy (vptr, uptr + 1, len - 1); - vptr[len - 2] =3D 0; - } else { - memcpy (vptr, uptr, len); - vptr[len - 1] =3D 0; - } + if ((vptr > val) && (len > 0) && (uptr[0] =3D=3D '/') && + (vptr[-1] =3D=3D '/')) { + memcpy(vptr, uptr + 1, len - 1); + vptr[len - 2] =3D 0; + } else { + memcpy(vptr, uptr, len); + vptr[len - 1] =3D 0; + } } else { - vptr[len - 1] =3D 0; + vptr[len - 1] =3D 0; } =20 /* escape the freshly-built path */ vptr =3D val; - /* exception characters from uri_to_string */ + /* exception characters from uri_to_string */ val =3D uri_string_escape(vptr, "/;&=3D+$,"); g_free(vptr); =20 @@ -2076,9 +2078,9 @@ done: if (remove_path !=3D 0) ref->path =3D NULL; if (ref !=3D NULL) - uri_free (ref); + uri_free(ref); if (bas !=3D NULL) - uri_free (bas); + uri_free(bas); =20 return val; } @@ -2087,12 +2089,12 @@ done: * Utility functions to help parse and assemble query strings. */ =20 -struct QueryParams * -query_params_new (int init_alloc) +struct QueryParams *query_params_new(int init_alloc) { struct QueryParams *ps; =20 - if (init_alloc <=3D 0) init_alloc =3D 1; + if (init_alloc <=3D 0) + init_alloc =3D 1; =20 ps =3D g_new(QueryParams, 1); ps->n =3D 0; @@ -2105,9 +2107,8 @@ query_params_new (int init_alloc) /* Ensure there is space to store at least one more parameter * at the end of the set. */ -static int -query_params_append (struct QueryParams *ps, - const char *name, const char *value) +static int query_params_append(struct QueryParams *ps, const char *name, + const char *value) { if (ps->n >=3D ps->alloc) { ps->p =3D g_renew(QueryParam, ps->p, ps->alloc * 2); @@ -2122,41 +2123,41 @@ query_params_append (struct QueryParams *ps, return 0; } =20 -void -query_params_free (struct QueryParams *ps) +void query_params_free(struct QueryParams *ps) { int i; =20 for (i =3D 0; i < ps->n; ++i) { - g_free (ps->p[i].name); - g_free (ps->p[i].value); + g_free(ps->p[i].name); + g_free(ps->p[i].value); } - g_free (ps->p); - g_free (ps); + g_free(ps->p); + g_free(ps); } =20 -struct QueryParams * -query_params_parse (const char *query) +struct QueryParams *query_params_parse(const char *query) { struct QueryParams *ps; const char *end, *eq; =20 - ps =3D query_params_new (0); - if (!query || query[0] =3D=3D '\0') return ps; + ps =3D query_params_new(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, '&'); + end =3D strchr(query, '&'); if (!end) - end =3D strchr (query, ';'); + end =3D strchr(query, ';'); if (!end) - end =3D query + strlen (query); + 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) eq =3D NULL; + eq =3D strchr(query, '=3D'); + if (eq && eq >=3D end) + eq =3D NULL; =20 /* Empty section (eg. "&&"). */ if (end =3D=3D query) @@ -2166,14 +2167,14 @@ query_params_parse (const char *query) * and consistent with CGI.pm we assume value is "". */ else if (!eq) { - name =3D uri_string_unescape (query, end - query, NULL); + name =3D uri_string_unescape(query, end - query, NULL); value =3D NULL; } /* Or if we have "name=3D" here (works around annoying * problem when calling uri_string_unescape with len =3D 0). */ - else if (eq+1 =3D=3D end) { - name =3D uri_string_unescape (query, eq - query, NULL); + else if (eq + 1 =3D=3D end) { + name =3D uri_string_unescape(query, eq - query, NULL); value =3D g_new0(char, 1); } /* If the '=3D' character is at the beginning then we have @@ -2184,18 +2185,19 @@ query_params_parse (const char *query) =20 /* Otherwise it's "name=3Dvalue". */ else { - name =3D uri_string_unescape (query, eq - query, NULL); - value =3D uri_string_unescape (eq+1, end - (eq+1), NULL); + name =3D uri_string_unescape(query, eq - query, NULL); + value =3D uri_string_unescape(eq + 1, end - (eq + 1), NULL); } =20 /* Append to the parameter set. */ - query_params_append (ps, name, value); + query_params_append(ps, name, value); g_free(name); g_free(value); =20 next: query =3D end; - if (*query) query ++; /* skip '&' separator */ + if (*query) + query++; /* skip '&' separator */ } =20 return ps; --=20 2.14.3 From nobody Thu Dec 18 19:27:56 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 1520242986688811.2937428107971; Mon, 5 Mar 2018 01:43:06 -0800 (PST) Received: from localhost ([::1]:48159 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esme4-0007RW-Vc for importer@patchew.org; Mon, 05 Mar 2018 04:43:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49050) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esmbc-0005di-9c for qemu-devel@nongnu.org; Mon, 05 Mar 2018 04:40:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1esmba-00065b-Hu for qemu-devel@nongnu.org; Mon, 05 Mar 2018 04:40:28 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33770 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 1esmbV-0005zb-Cv; Mon, 05 Mar 2018 04:40:21 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EC780402314E; Mon, 5 Mar 2018 09:40:20 +0000 (UTC) Received: from localhost (ovpn-116-254.ams2.redhat.com [10.36.116.254]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2C2BFAFD58; Mon, 5 Mar 2018 09:40:18 +0000 (UTC) From: Stefan Hajnoczi To: Date: Mon, 5 Mar 2018 09:40:02 +0000 Message-Id: <20180305094006.21446-3-stefanha@redhat.com> In-Reply-To: <20180305094006.21446-1-stefanha@redhat.com> References: <20180305094006.21446-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 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:21 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 05 Mar 2018 09:40:21 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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 2/6] util/uri.c: remove brackets that wrap `return` statement's content. 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 only remove brackets that wrap `return` statements' content. use `perl -pi -e "s/return \((.*?)\);/return \1;/g" util/uri.c` to remove pattern like this: "return (1);" Signed-off-by: Su Hang Reviewed-by: Thomas Huth Message-id: 1519533358-13759-3-git-send-email-suhang16@mails.ucas.ac.cn Signed-off-by: Stefan Hajnoczi --- util/uri.c | 160 ++++++++++++++++++++++++++++++---------------------------= ---- 1 file changed, 80 insertions(+), 80 deletions(-) diff --git a/util/uri.c b/util/uri.c index cf09f41735..bb2576cf21 100644 --- a/util/uri.c +++ b/util/uri.c @@ -212,11 +212,11 @@ static int rfc3986_parse_scheme(URI *uri, const char = **str) const char *cur; =20 if (str =3D=3D NULL) - return (-1); + return -1; =20 cur =3D *str; if (!ISA_ALPHA(cur)) - return (2); + return 2; cur++; while (ISA_ALPHA(cur) || ISA_DIGIT(cur) || (*cur =3D=3D '+') || (*cur = =3D=3D '-') || (*cur =3D=3D '.')) @@ -226,7 +226,7 @@ static int rfc3986_parse_scheme(URI *uri, const char **= str) uri->scheme =3D g_strndup(*str, cur - *str); } *str =3D cur; - return (0); + return 0; } =20 /** @@ -249,7 +249,7 @@ static int rfc3986_parse_fragment(URI *uri, const char = **str) const char *cur; =20 if (str =3D=3D NULL) - return (-1); + return -1; =20 cur =3D *str; =20 @@ -265,7 +265,7 @@ static int rfc3986_parse_fragment(URI *uri, const char = **str) uri->fragment =3D uri_string_unescape(*str, cur - *str, NULL); } *str =3D cur; - return (0); + return 0; } =20 /** @@ -284,7 +284,7 @@ static int rfc3986_parse_query(URI *uri, const char **s= tr) const char *cur; =20 if (str =3D=3D NULL) - return (-1); + return -1; =20 cur =3D *str; =20 @@ -296,7 +296,7 @@ static int rfc3986_parse_query(URI *uri, const char **s= tr) uri->query =3D g_strndup(*str, cur - *str); } *str =3D cur; - return (0); + return 0; } =20 /** @@ -362,9 +362,9 @@ static int rfc3986_parse_user_info(URI *uri, const char= **str) uri->user =3D uri_string_unescape(*str, cur - *str, NULL); } *str =3D cur; - return (0); + return 0; } - return (1); + return 1; } =20 /** @@ -386,7 +386,7 @@ static int rfc3986_parse_dec_octet(const char **str) const char *cur =3D *str; =20 if (!(ISA_DIGIT(cur))) - return (1); + return 1; if (!ISA_DIGIT(cur + 1)) cur++; else if ((*cur !=3D '0') && (ISA_DIGIT(cur + 1)) && (!ISA_DIGIT(cur + = 2))) @@ -400,9 +400,9 @@ static int rfc3986_parse_dec_octet(const char **str) (*(cur + 1) <=3D '5')) cur +=3D 3; else - return (1); + return 1; *str =3D cur; - return (0); + return 0; } /** * rfc3986_parse_host: @@ -433,7 +433,7 @@ static int rfc3986_parse_host(URI *uri, const char **st= r) while ((*cur !=3D ']') && (*cur !=3D 0)) cur++; if (*cur !=3D ']') - return (1); + return 1; cur++; goto found; } @@ -479,7 +479,7 @@ found: uri->server =3D NULL; } *str =3D cur; - return (0); + return 0; } =20 /** @@ -510,15 +510,15 @@ static int rfc3986_parse_authority(URI *uri, const ch= ar **str) cur++; ret =3D rfc3986_parse_host(uri, &cur); if (ret !=3D 0) - return (ret); + return ret; if (*cur =3D=3D ':') { cur++; ret =3D rfc3986_parse_port(uri, &cur); if (ret !=3D 0) - return (ret); + return ret; } *str =3D cur; - return (0); + return 0; } =20 /** @@ -544,13 +544,13 @@ static int rfc3986_parse_segment(const char **str, ch= ar forbid, int empty) cur =3D *str; if (!ISA_PCHAR(cur)) { if (empty) - return (0); - return (1); + return 0; + return 1; } while (ISA_PCHAR(cur) && (*cur !=3D forbid)) NEXT(cur); *str =3D cur; - return (0); + return 0; } =20 /** @@ -576,7 +576,7 @@ static int rfc3986_parse_path_ab_empty(URI *uri, const = char **str) cur++; ret =3D rfc3986_parse_segment(&cur, 0, 1); if (ret !=3D 0) - return (ret); + return ret; } if (uri !=3D NULL) { g_free(uri->path); @@ -590,7 +590,7 @@ static int rfc3986_parse_path_ab_empty(URI *uri, const = char **str) } } *str =3D cur; - return (0); + return 0; } =20 /** @@ -613,7 +613,7 @@ static int rfc3986_parse_path_absolute(URI *uri, const = char **str) cur =3D *str; =20 if (*cur !=3D '/') - return (1); + return 1; cur++; ret =3D rfc3986_parse_segment(&cur, 0, 0); if (ret =3D=3D 0) { @@ -621,7 +621,7 @@ static int rfc3986_parse_path_absolute(URI *uri, const = char **str) cur++; ret =3D rfc3986_parse_segment(&cur, 0, 1); if (ret !=3D 0) - return (ret); + return ret; } } if (uri !=3D NULL) { @@ -636,7 +636,7 @@ static int rfc3986_parse_path_absolute(URI *uri, const = char **str) } } *str =3D cur; - return (0); + return 0; } =20 /** @@ -660,12 +660,12 @@ static int rfc3986_parse_path_rootless(URI *uri, cons= t char **str) =20 ret =3D rfc3986_parse_segment(&cur, 0, 0); if (ret !=3D 0) - return (ret); + return ret; while (*cur =3D=3D '/') { cur++; ret =3D rfc3986_parse_segment(&cur, 0, 1); if (ret !=3D 0) - return (ret); + return ret; } if (uri !=3D NULL) { g_free(uri->path); @@ -679,7 +679,7 @@ static int rfc3986_parse_path_rootless(URI *uri, const = char **str) } } *str =3D cur; - return (0); + return 0; } =20 /** @@ -703,12 +703,12 @@ static int rfc3986_parse_path_no_scheme(URI *uri, con= st char **str) =20 ret =3D rfc3986_parse_segment(&cur, ':', 0); if (ret !=3D 0) - return (ret); + return ret; while (*cur =3D=3D '/') { cur++; ret =3D rfc3986_parse_segment(&cur, 0, 1); if (ret !=3D 0) - return (ret); + return ret; } if (uri !=3D NULL) { g_free(uri->path); @@ -722,7 +722,7 @@ static int rfc3986_parse_path_no_scheme(URI *uri, const= char **str) } } *str =3D cur; - return (0); + return 0; } =20 /** @@ -751,20 +751,20 @@ static int rfc3986_parse_hier_part(URI *uri, const ch= ar **str) cur +=3D 2; ret =3D rfc3986_parse_authority(uri, &cur); if (ret !=3D 0) - return (ret); + return ret; ret =3D rfc3986_parse_path_ab_empty(uri, &cur); if (ret !=3D 0) - return (ret); + return ret; *str =3D cur; - return (0); + return 0; } else if (*cur =3D=3D '/') { ret =3D rfc3986_parse_path_absolute(uri, &cur); if (ret !=3D 0) - return (ret); + return ret; } else if (ISA_PCHAR(cur)) { ret =3D rfc3986_parse_path_rootless(uri, &cur); if (ret !=3D 0) - return (ret); + return ret; } else { /* path-empty is effectively empty */ if (uri !=3D NULL) { @@ -773,7 +773,7 @@ static int rfc3986_parse_hier_part(URI *uri, const char= **str) } } *str =3D cur; - return (0); + return 0; } =20 /** @@ -800,18 +800,18 @@ static int rfc3986_parse_relative_ref(URI *uri, const= char *str) str +=3D 2; ret =3D rfc3986_parse_authority(uri, &str); if (ret !=3D 0) - return (ret); + return ret; ret =3D rfc3986_parse_path_ab_empty(uri, &str); if (ret !=3D 0) - return (ret); + return ret; } else if (*str =3D=3D '/') { ret =3D rfc3986_parse_path_absolute(uri, &str); if (ret !=3D 0) - return (ret); + return ret; } else if (ISA_PCHAR(str)) { ret =3D rfc3986_parse_path_no_scheme(uri, &str); if (ret !=3D 0) - return (ret); + return ret; } else { /* path-empty is effectively empty */ if (uri !=3D NULL) { @@ -824,19 +824,19 @@ static int rfc3986_parse_relative_ref(URI *uri, const= char *str) str++; ret =3D rfc3986_parse_query(uri, &str); if (ret !=3D 0) - return (ret); + return ret; } if (*str =3D=3D '#') { str++; ret =3D rfc3986_parse_fragment(uri, &str); if (ret !=3D 0) - return (ret); + return ret; } if (*str !=3D 0) { uri_clean(uri); - return (1); + return 1; } - return (0); + return 0; } =20 /** @@ -857,31 +857,31 @@ static int rfc3986_parse(URI *uri, const char *str) =20 ret =3D rfc3986_parse_scheme(uri, &str); if (ret !=3D 0) - return (ret); + return ret; if (*str !=3D ':') { - return (1); + return 1; } str++; ret =3D rfc3986_parse_hier_part(uri, &str); if (ret !=3D 0) - return (ret); + return ret; if (*str =3D=3D '?') { str++; ret =3D rfc3986_parse_query(uri, &str); if (ret !=3D 0) - return (ret); + return ret; } if (*str =3D=3D '#') { str++; ret =3D rfc3986_parse_fragment(uri, &str); if (ret !=3D 0) - return (ret); + return ret; } if (*str !=3D 0) { uri_clean(uri); - return (1); + return 1; } - return (0); + return 0; } =20 /** @@ -901,7 +901,7 @@ static int rfc3986_parse_uri_reference(URI *uri, const = char *str) int ret; =20 if (str =3D=3D NULL) - return (-1); + return -1; uri_clean(uri); =20 /* @@ -914,10 +914,10 @@ static int rfc3986_parse_uri_reference(URI *uri, cons= t char *str) ret =3D rfc3986_parse_relative_ref(uri, str); if (ret !=3D 0) { uri_clean(uri); - return (ret); + return ret; } } - return (0); + return 0; } =20 /** @@ -936,14 +936,14 @@ URI *uri_parse(const char *str) int ret; =20 if (str =3D=3D NULL) - return (NULL); + return NULL; uri =3D uri_new(); ret =3D rfc3986_parse_uri_reference(uri, str); if (ret) { uri_free(uri); - return (NULL); + return NULL; } - return (uri); + return uri; } =20 /** @@ -960,7 +960,7 @@ URI *uri_parse(const char *str) */ int uri_parse_into(URI *uri, const char *str) { - return (rfc3986_parse_uri_reference(uri, str)); + return rfc3986_parse_uri_reference(uri, str); } =20 /** @@ -980,7 +980,7 @@ URI *uri_parse_raw(const char *str, int raw) int ret; =20 if (str =3D=3D NULL) - return (NULL); + return NULL; uri =3D uri_new(); if (raw) { uri->cleanup |=3D 2; @@ -988,9 +988,9 @@ URI *uri_parse_raw(const char *str, int raw) ret =3D uri_parse_into(uri, str); if (ret) { uri_free(uri); - return (NULL); + return NULL; } - return (uri); + return uri; } =20 /************************************************************************ @@ -1011,7 +1011,7 @@ URI *uri_new(void) URI *ret; =20 ret =3D g_new0(URI, 1); - return (ret); + return ret; } =20 /** @@ -1028,7 +1028,7 @@ static char *realloc2n(char *ret, int *max) tmp =3D *max * 2; temp =3D g_realloc(ret, (tmp + 1)); *max =3D tmp; - return (temp); + return temp; } =20 /** @@ -1048,7 +1048,7 @@ char *uri_to_string(URI *uri) int max; =20 if (uri =3D=3D NULL) - return (NULL); + return NULL; =20 max =3D 80; ret =3D g_malloc(max + 1); @@ -1249,7 +1249,7 @@ char *uri_to_string(URI *uri) ret =3D temp; } ret[len] =3D 0; - return (ret); + return ret; } =20 /** @@ -1315,7 +1315,7 @@ static int normalize_uri_path(char *path) char *cur, *out; =20 if (path =3D=3D NULL) - return (-1); + return -1; =20 /* Skip all initial "/" chars. We want to get to the beginning of the * first non-empty segment. @@ -1324,7 +1324,7 @@ static int normalize_uri_path(char *path) while (cur[0] =3D=3D '/') ++cur; if (cur[0] =3D=3D '\0') - return (0); + return 0; =20 /* Keep everything we've seen so far. */ out =3D cur; @@ -1372,7 +1372,7 @@ done_cd: while (cur[0] =3D=3D '/') ++cur; if (cur[0] =3D=3D '\0') - return (0); + return 0; =20 /* * Analyze each segment in sequence for cases (e) and (f). @@ -1485,15 +1485,15 @@ done_cd: } } =20 - return (0); + return 0; } =20 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'))) - return (1); - return (0); + return 1; + return 0; } =20 /** @@ -1516,11 +1516,11 @@ char *uri_string_unescape(const char *str, int len,= char *target) const char *in; =20 if (str =3D=3D NULL) - return (NULL); + return NULL; if (len <=3D 0) len =3D strlen(str); if (len < 0) - return (NULL); + return NULL; =20 if (target =3D=3D NULL) { ret =3D g_malloc(len + 1); @@ -1553,7 +1553,7 @@ char *uri_string_unescape(const char *str, int len, c= har *target) } } *out =3D 0; - return (ret); + return ret; } =20 /** @@ -1574,12 +1574,12 @@ char *uri_string_escape(const char *str, const char= *list) int len, out; =20 if (str =3D=3D NULL) - return (NULL); + return NULL; if (str[0] =3D=3D 0) - return (g_strdup(str)); + return g_strdup(str); len =3D strlen(str); if (!(len > 0)) - return (NULL); + return NULL; =20 len +=3D 20; ret =3D g_malloc(len); @@ -1612,7 +1612,7 @@ char *uri_string_escape(const char *str, const char *= list) } } ret[out] =3D 0; - return (ret); + return ret; } =20 /************************************************************************ @@ -1851,7 +1851,7 @@ done: uri_free(bas); if (res !=3D NULL) uri_free(res); - return (val); + return val; } =20 /** --=20 2.14.3 From nobody Thu Dec 18 19:27:56 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 From nobody Thu Dec 18 19:27:56 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 1520243130215459.5437234610381; Mon, 5 Mar 2018 01:45:30 -0800 (PST) Received: from localhost ([::1]:48172 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esmgR-0001Kc-9i for importer@patchew.org; Mon, 05 Mar 2018 04:45:27 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49056) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esmbc-0005e1-NV for qemu-devel@nongnu.org; Mon, 05 Mar 2018 04:40:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1esmbb-00066H-V2 for qemu-devel@nongnu.org; Mon, 05 Mar 2018 04:40:28 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40678 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 1esmbZ-000654-Tw; Mon, 05 Mar 2018 04:40:25 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 73FEA8D75F; Mon, 5 Mar 2018 09:40:25 +0000 (UTC) Received: from localhost (ovpn-116-254.ams2.redhat.com [10.36.116.254]) by smtp.corp.redhat.com (Postfix) with ESMTP id 208DA2144B21; Mon, 5 Mar 2018 09:40:25 +0000 (UTC) From: Stefan Hajnoczi To: Date: Mon, 5 Mar 2018 09:40:04 +0000 Message-Id: <20180305094006.21446-5-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.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 05 Mar 2018 09:40:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 05 Mar 2018 09:40:25 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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 4/6] tests/libqos: Check for valid dev pointer when looking for PCI devices 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 , Thomas Huth , 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: Thomas Huth dev could be NULL if the PCI device can not be found due to some reasons, so we must not dereference the pointer in this case. Signed-off-by: Thomas Huth Message-id: 1519713884-2346-1-git-send-email-thuth@redhat.com Signed-off-by: Stefan Hajnoczi --- tests/libqos/virtio-pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/libqos/virtio-pci.c b/tests/libqos/virtio-pci.c index 7ac15c04e1..550dede0a2 100644 --- a/tests/libqos/virtio-pci.c +++ b/tests/libqos/virtio-pci.c @@ -315,7 +315,9 @@ QVirtioPCIDevice *qvirtio_pci_device_find(QPCIBus *bus,= uint16_t device_type) qvirtio_pci_foreach(bus, device_type, false, 0, qvirtio_pci_assign_device, &dev); =20 - dev->vdev.bus =3D &qvirtio_pci; + if (dev) { + dev->vdev.bus =3D &qvirtio_pci; + } =20 return dev; } --=20 2.14.3 From nobody Thu Dec 18 19:27:56 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 1520243150979406.95320780900965; Mon, 5 Mar 2018 01:45:50 -0800 (PST) Received: from localhost ([::1]:48178 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esmgn-0001lQ-Qb for importer@patchew.org; Mon, 05 Mar 2018 04:45:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49104) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esmbi-0005is-Mk for qemu-devel@nongnu.org; Mon, 05 Mar 2018 04:40:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1esmbe-00067U-LZ for qemu-devel@nongnu.org; Mon, 05 Mar 2018 04:40:34 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:36518 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 1esmbb-00065v-Bk; Mon, 05 Mar 2018 04:40:27 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EF95FEB6F7; Mon, 5 Mar 2018 09:40:26 +0000 (UTC) Received: from localhost (ovpn-116-254.ams2.redhat.com [10.36.116.254]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9DB282144B21; Mon, 5 Mar 2018 09:40:26 +0000 (UTC) From: Stefan Hajnoczi To: Date: Mon, 5 Mar 2018 09:40:05 +0000 Message-Id: <20180305094006.21446-6-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.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 05 Mar 2018 09:40:27 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 05 Mar 2018 09:40:27 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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 5/6] Add a git-publish configuration file 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 , Fam Zheng , 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: Fam Zheng git-publish [1] is a convenient tool to send patches and has been popular among QEMU developers. Recently it has been made available in Fedora/Debian official repo. One nice feature of the tool is a per-project configuration with profiles, especially in which the cccmd option is a handy method to create the Cc list. [1]: https://github.com/stefanha/git-publish Signed-off-by: Fam Zheng Message-id: 20180226030326.20219-2-famz@redhat.com Signed-off-by: Stefan Hajnoczi --- .gitpublish | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 .gitpublish diff --git a/.gitpublish b/.gitpublish new file mode 100644 index 0000000000..a13f8c7c0e --- /dev/null +++ b/.gitpublish @@ -0,0 +1,51 @@ +# +# Common git-publish profiles that can be used to send patches to QEMU ups= tream. +# +# See https://github.com/stefanha/git-publish for more information +# +[gitpublishprofile "default"] +base =3D master +to =3D qemu-devel@nongnu.org +cccmd =3D scripts/get_maintainer.pl --noroles --norolestats --nogit --nogi= t-fallback 2>/dev/null + +[gitpublishprofile "rfc"] +base =3D master +prefix =3D RFC PATCH +to =3D qemu-devel@nongnu.org +cccmd =3D scripts/get_maintainer.pl --noroles --norolestats --nogit --nogi= t-fallback 2>/dev/null + +[gitpublishprofile "stable"] +base =3D master +to =3D qemu-devel@nongnu.org +cc =3D qemu-stable@nongnu.org +cccmd =3D scripts/get_maintainer.pl --noroles --norolestats --nogit --nogi= t-fallback 2>/dev/null + +[gitpublishprofile "trivial"] +base =3D master +to =3D qemu-devel@nongnu.org +cc =3D qemu-trivial@nongnu.org +cccmd =3D scripts/get_maintainer.pl --noroles --norolestats --nogit --nogi= t-fallback 2>/dev/null + +[gitpublishprofile "block"] +base =3D master +to =3D qemu-devel@nongnu.org +cc =3D qemu-block@nongnu.org +cccmd =3D scripts/get_maintainer.pl --noroles --norolestats --nogit --nogi= t-fallback 2>/dev/null + +[gitpublishprofile "arm"] +base =3D master +to =3D qemu-devel@nongnu.org +cc =3D qemu-arm@nongnu.org +cccmd =3D scripts/get_maintainer.pl --noroles --norolestats --nogit --nogi= t-fallback 2>/dev/null + +[gitpublishprofile "s390"] +base =3D master +to =3D qemu-devel@nongnu.org +cc =3D qemu-s390@nongnu.org +cccmd =3D scripts/get_maintainer.pl --noroles --norolestats --nogit --nogi= t-fallback 2>/dev/null + +[gitpublishprofile "ppc"] +base =3D master +to =3D qemu-devel@nongnu.org +cc =3D qemu-ppc@nongnu.org +cccmd =3D scripts/get_maintainer.pl --noroles --norolestats --nogit --nogi= t-fallback 2>/dev/null --=20 2.14.3 From nobody Thu Dec 18 19:27:56 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 1520242979884536.8359350598553; Mon, 5 Mar 2018 01:42:59 -0800 (PST) Received: from localhost ([::1]:48158 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esme2-0007Qw-LM for importer@patchew.org; Mon, 05 Mar 2018 04:42:58 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49117) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esmbj-0005je-GI for qemu-devel@nongnu.org; Mon, 05 Mar 2018 04:40:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1esmbi-000687-Fv for qemu-devel@nongnu.org; Mon, 05 Mar 2018 04:40:35 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40686 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 1esmbd-00066l-1B; Mon, 05 Mar 2018 04:40:29 -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 9602B8D75F; Mon, 5 Mar 2018 09:40:28 +0000 (UTC) Received: from localhost (ovpn-116-254.ams2.redhat.com [10.36.116.254]) by smtp.corp.redhat.com (Postfix) with ESMTP id 45686202699C; Mon, 5 Mar 2018 09:40:28 +0000 (UTC) From: Stefan Hajnoczi To: Date: Mon, 5 Mar 2018 09:40:06 +0000 Message-Id: <20180305094006.21446-7-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.2]); Mon, 05 Mar 2018 09:40:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 05 Mar 2018 09:40:28 +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 6/6] README: Document 'git-publish' workflow 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 , Fam Zheng , 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: Fam Zheng Signed-off-by: Fam Zheng Message-id: 20180226030326.20219-3-famz@redhat.com Signed-off-by: Stefan Hajnoczi --- README | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/README b/README index 2c8e1c8cc4..7833b97365 100644 --- a/README +++ b/README @@ -56,7 +56,7 @@ The QEMU source code is maintained under the GIT version = control system. =20 git clone git://git.qemu.org/qemu.git =20 -When submitting patches, the preferred approach is to use 'git +When submitting patches, one common approach is to use 'git format-patch' and/or 'git send-email' to format & send the mail to the qemu-devel@nongnu.org mailing list. All patches submitted must contain a 'Signed-off-by' line from the author. Patches should follow the @@ -73,6 +73,35 @@ The QEMU website is also maintained under source control. git clone git://git.qemu.org/qemu-web.git https://www.qemu.org/2017/02/04/the-new-qemu-website-is-up/ =20 +A 'git-profile' utility was created to make above process less +cumbersome, and is highly recommended for making regular contributions, +or even just for sending consecutive patch series revisions. It also +requires a working 'git send-email' setup, and by default doesn't +automate everything, so you may want to go through the above steps +manually for once. + +For installation instructions, please go to + + https://github.com/stefanha/git-publish + +The workflow with 'git-publish' is: + + $ git checkout master -b my-feature + $ # work on new commits, add your 'Signed-off-by' lines to each + $ git publish + +Your patch series will be sent and tagged as my-feature-v1 if you need to = refer +back to it in the future. + +Sending v2: + + $ git checkout my-feature # same topic branch + $ # making changes to the commits (using 'git rebase', for example) + $ git publish + +Your patch series will be sent with 'v2' tag in the subject and the git tip +will be tagged as my-feature-v2. + Bug reporting =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 --=20 2.14.3