diff options
author | Brad King <brad.king@kitware.com> | 2023-05-22 13:57:06 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2023-05-22 20:51:15 (GMT) |
commit | e090f348d3d74f984bafd828ee36ed75b55d4076 (patch) | |
tree | 3994a8c2b8f07c094c6da6fe939a9af34f45006c | |
parent | 71817dc37c9c9013e475c856aec95a5fb27bce46 (diff) | |
download | CMake-e090f348d3d74f984bafd828ee36ed75b55d4076.zip CMake-e090f348d3d74f984bafd828ee36ed75b55d4076.tar.gz CMake-e090f348d3d74f984bafd828ee36ed75b55d4076.tar.bz2 |
curl: Avoid redundant getenv calls in curltest
Also avoid using the result without checking for NULL.
-rw-r--r-- | Utilities/cmcurl/curltest.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/Utilities/cmcurl/curltest.c b/Utilities/cmcurl/curltest.c index f80e758..cb87fce 100644 --- a/Utilities/cmcurl/curltest.c +++ b/Utilities/cmcurl/curltest.c @@ -10,21 +10,24 @@ int test_curl(const char* url) CURLcode r; char proxy[1024]; int proxy_type = 0; + const char* env_HTTP_PROXY = getenv("HTTP_PROXY"); - if (getenv("HTTP_PROXY")) { + if (env_HTTP_PROXY) { + const char* env_HTTP_PROXY_PORT = getenv("HTTP_PROXY_PORT"); + const char* env_HTTP_PROXY_TYPE = getenv("HTTP_PROXY_TYPE"); proxy_type = 1; - if (getenv("HTTP_PROXY_PORT")) { - sprintf(proxy, "%s:%s", getenv("HTTP_PROXY"), getenv("HTTP_PROXY_PORT")); + if (env_HTTP_PROXY_PORT) { + sprintf(proxy, "%s:%s", env_HTTP_PROXY, env_HTTP_PROXY_PORT); } else { - sprintf(proxy, "%s", getenv("HTTP_PROXY")); + sprintf(proxy, "%s", env_HTTP_PROXY); } - if (getenv("HTTP_PROXY_TYPE")) { + if (env_HTTP_PROXY_TYPE) { /* HTTP/SOCKS4/SOCKS5 */ - if (strcmp(getenv("HTTP_PROXY_TYPE"), "HTTP") == 0) { + if (strcmp(env_HTTP_PROXY_TYPE, "HTTP") == 0) { proxy_type = 1; - } else if (strcmp(getenv("HTTP_PROXY_TYPE"), "SOCKS4") == 0) { + } else if (strcmp(env_HTTP_PROXY_TYPE, "SOCKS4") == 0) { proxy_type = 2; - } else if (strcmp(getenv("HTTP_PROXY_TYPE"), "SOCKS5") == 0) { + } else if (strcmp(env_HTTP_PROXY_TYPE, "SOCKS5") == 0) { proxy_type = 3; } } |