-
Notifications
You must be signed in to change notification settings - Fork 423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[EXPORTER] fix clang-tidy warnings in UrlParser #3146
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
#include <cstdint> | ||
#include <cstdlib> | ||
#include <string> | ||
#include <utility> | ||
|
||
#include "opentelemetry/version.h" | ||
|
||
|
@@ -34,7 +35,7 @@ class UrlParser | |
std::string query_; | ||
bool success_; | ||
|
||
UrlParser(std::string url) : url_(url), success_(true) | ||
UrlParser(std::string url) : url_(std::move(url)), success_(true) | ||
{ | ||
if (url_.length() == 0) | ||
{ | ||
|
@@ -50,15 +51,16 @@ class UrlParser | |
} | ||
else | ||
{ | ||
scheme_ = std::string(url_.begin() + cpos, url_.begin() + pos); | ||
scheme_ = std::string(url_.begin() + static_cast<std::string::difference_type>(cpos), | ||
url_.begin() + static_cast<std::string::difference_type>(pos)); | ||
Comment on lines
-53
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one and similar issues:
https://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/narrowing-conversions.html |
||
cpos = pos + 3; | ||
} | ||
|
||
// credentials | ||
size_t pos1 = url_.find_first_of("@", cpos); | ||
size_t pos2 = url_.find_first_of("/", cpos); | ||
size_t pos1 = url_.find_first_of('@', cpos); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
https://clang.llvm.org/extra/clang-tidy/checks/performance/faster-string-find.html |
||
if (pos1 != std::string::npos) | ||
{ | ||
size_t pos2 = url_.find_first_of('/', cpos); | ||
// TODO - handle credentials | ||
if (pos2 == std::string::npos || pos1 < pos2) | ||
{ | ||
|
@@ -80,7 +82,8 @@ class UrlParser | |
{ | ||
// port present | ||
is_port = true; | ||
host_ = std::string(url_.begin() + cpos, url_.begin() + pos); | ||
host_ = std::string(url_.begin() + static_cast<std::string::difference_type>(cpos), | ||
url_.begin() + static_cast<std::string::difference_type>(pos)); | ||
cpos = pos + 1; | ||
} | ||
pos = url_.find_first_of("/?", cpos); | ||
|
@@ -97,7 +100,9 @@ class UrlParser | |
} | ||
else | ||
{ | ||
host_ = std::string(url_.begin() + cpos, url_.begin() + url_.length()); | ||
host_ = | ||
std::string(url_.begin() + static_cast<std::string::difference_type>(cpos), | ||
url_.begin() + static_cast<std::string::difference_type>(url_.length())); | ||
} | ||
return; | ||
} | ||
|
@@ -109,7 +114,8 @@ class UrlParser | |
} | ||
else | ||
{ | ||
host_ = std::string(url_.begin() + cpos, url_.begin() + pos); | ||
host_ = std::string(url_.begin() + static_cast<std::string::difference_type>(cpos), | ||
url_.begin() + static_cast<std::string::difference_type>(pos)); | ||
} | ||
cpos = pos; | ||
|
||
|
@@ -118,21 +124,27 @@ class UrlParser | |
pos = url_.find('?', cpos); | ||
if (pos == std::string::npos) | ||
{ | ||
path_ = std::string(url_.begin() + cpos, url_.begin() + url_.length()); | ||
path_ = | ||
std::string(url_.begin() + static_cast<std::string::difference_type>(cpos), | ||
url_.begin() + static_cast<std::string::difference_type>(url_.length())); | ||
query_ = ""; | ||
} | ||
else | ||
{ | ||
path_ = std::string(url_.begin() + cpos, url_.begin() + pos); | ||
cpos = pos + 1; | ||
query_ = std::string(url_.begin() + cpos, url_.begin() + url_.length()); | ||
path_ = std::string(url_.begin() + static_cast<std::string::difference_type>(cpos), | ||
url_.begin() + static_cast<std::string::difference_type>(pos)); | ||
cpos = pos + 1; | ||
query_ = | ||
std::string(url_.begin() + static_cast<std::string::difference_type>(cpos), | ||
url_.begin() + static_cast<std::string::difference_type>(url_.length())); | ||
} | ||
return; | ||
} | ||
path_ = std::string("/"); | ||
if (url_[cpos] == '?') | ||
{ | ||
query_ = std::string(url_.begin() + cpos, url_.begin() + url_.length()); | ||
query_ = std::string(url_.begin() + static_cast<std::string::difference_type>(cpos), | ||
url_.begin() + static_cast<std::string::difference_type>(url_.length())); | ||
} | ||
} | ||
|
||
|
@@ -209,7 +221,7 @@ class UrlDecoder | |
hex[1] = encoded[++pos]; | ||
|
||
char *endptr; | ||
long value = strtol(hex, &endptr, 16); | ||
int value = static_cast<int>(std::strtol(hex, &endptr, 16)); | ||
Comment on lines
-212
to
+224
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
||
// Invalid input: no valid hex characters after '%' | ||
if (endptr != &hex[2]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://clang.llvm.org/extra/clang-tidy/checks/performance/unnecessary-value-param.html