Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sjinks
Copy link
Contributor

@sjinks sjinks commented Nov 15, 2024

Changes

This PR fixes issues found by clang-tidy in UrlParser.

Please provide a brief description of the changes here.

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

Copy link

netlify bot commented Nov 15, 2024

Deploy Preview for opentelemetry-cpp-api-docs canceled.

Name Link
🔨 Latest commit 478139d
🔍 Latest deploy log https://app.netlify.com/sites/opentelemetry-cpp-api-docs/deploys/67372aa6140d8b0008a17694

Comment on lines -37 to +38
UrlParser(std::string url) : url_(url), success_(true)
UrlParser(std::string url) : url_(std::move(url)), success_(true)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parameter 'url' is passed by value and only copied once; consider moving it to avoid unnecessary copies

https://clang.llvm.org/extra/clang-tidy/checks/performance/unnecessary-value-param.html

Comment on lines -53 to +55
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));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one and similar issues:

Narrowing conversion from 'size_t' (aka 'unsigned long') to signed type 'difference_type' (aka 'long') is implementation-defined

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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'find_first_of' called with a string literal consisting of a single character; consider using the more effective overload accepting a character

https://clang.llvm.org/extra/clang-tidy/checks/performance/faster-string-find.html

Comment on lines -212 to +224
long value = strtol(hex, &endptr, 16);
int value = static_cast<int>(std::strtol(hex, &endptr, 16));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The google-runtime-int rule suggests replacing 'long' with 'int64', which seems overkill. Because two hexadecimal characters give a value in the [0; 255] range, downcasting to int is safe.

@sjinks sjinks marked this pull request as ready for review November 15, 2024 11:11
@sjinks sjinks requested a review from a team as a code owner November 15, 2024 11:11
Copy link

codecov bot commented Nov 15, 2024

Codecov Report

Attention: Patch coverage is 90.47619% with 2 lines in your changes missing coverage. Please review.

Project coverage is 87.83%. Comparing base (497eaf4) to head (478139d).
Report is 164 commits behind head on main.

Files with missing lines Patch % Lines
...include/opentelemetry/ext/http/common/url_parser.h 90.48% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3146      +/-   ##
==========================================
+ Coverage   87.12%   87.83%   +0.72%     
==========================================
  Files         200      195       -5     
  Lines        6109     6154      +45     
==========================================
+ Hits         5322     5405      +83     
+ Misses        787      749      -38     
Files with missing lines Coverage Δ
...include/opentelemetry/ext/http/common/url_parser.h 92.86% <90.48%> (+0.86%) ⬆️

... and 112 files with indirect coverage changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant