diff options
author | Nikita Popov <nikic@php.net> | 2016-11-17 23:18:05 +0100 |
---|---|---|
committer | Nikita Popov <nikic@php.net> | 2016-11-22 19:24:21 +0100 |
commit | 9befad6fc2abe124c1eab80e3dc33e044d3d5db2 (patch) | |
tree | c22e9f2ab62cbe6c7e0dfc226c451e70cd043279 | |
parent | 3e4538590384f1736c483b1f24bf3d79e0adcbe9 (diff) | |
download | php-git-9befad6fc2abe124c1eab80e3dc33e044d3d5db2.tar.gz |
Cleanup parse_url() gotos
Simplify some unnecessarily complicated code. In particular the
length updates are unnecessary (length is only used at the very
start) and we're goto'ing around a bit too much.
-rw-r--r-- | ext/standard/url.c | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/ext/standard/url.c b/ext/standard/url.c index 962718459a..94b9f20a16 100644 --- a/ext/standard/url.c +++ b/ext/standard/url.c @@ -122,7 +122,7 @@ PHPAPI php_url *php_url_parse_ex(char const *str, int length) if (*(e + 1) == '\0') { /* only scheme is available */ ret->scheme = estrndup(s, (e - s)); php_replace_controlchars_ex(ret->scheme, (e - s)); - goto end; + return ret; } /* @@ -145,8 +145,7 @@ PHPAPI php_url *php_url_parse_ex(char const *str, int length) ret->scheme = estrndup(s, (e-s)); php_replace_controlchars_ex(ret->scheme, (e - s)); - length -= ++e - s; - s = e; + s = e + 1; goto just_path; } else { ret->scheme = estrndup(s, (e-s)); @@ -162,18 +161,12 @@ PHPAPI php_url *php_url_parse_ex(char const *str, int length) if (*(e + 5) == ':') { s = e + 4; } - goto nohost; + goto just_path; } } } else { - if (!strncasecmp("file", ret->scheme, sizeof("file"))) { - s = e + 1; - goto nohost; - } else { - length -= ++e - s; - s = e; - goto just_path; - } + s = e + 1; + goto just_path; } } } else if (e) { /* no scheme; starts with colon: look for port */ @@ -212,9 +205,7 @@ PHPAPI php_url *php_url_parse_ex(char const *str, int length) } else if (*s == '/' && *(s + 1) == '/') { /* relative-scheme URL */ s += 2; } else { - just_path: - ue = s + length; - goto nohost; + goto just_path; } e = s + strcspn(s, "/?#"); @@ -296,7 +287,7 @@ PHPAPI php_url *php_url_parse_ex(char const *str, int length) s = e; - nohost: + just_path: if ((p = memchr(s, '?', (ue - s)))) { pp = memchr(s, '#', (ue - s)); @@ -343,7 +334,6 @@ PHPAPI php_url *php_url_parse_ex(char const *str, int length) ret->path = estrndup(s, (ue-s)); php_replace_controlchars_ex(ret->path, (ue - s)); } -end: return ret; } /* }}} */ |