Skip to content

[CODE HEALTH] Prevent std::out_of_range escaping noexcept substr callers - #4562

Draft
denizariyan wants to merge 1 commit into
open-telemetry:mainfrom
denizariyan:fix/no-except-std-oor
Draft

denizariyan wants to merge 1 commit into
open-telemetry:mainfrom
denizariyan:fix/no-except-std-oor

Conversation

@denizariyan

Copy link
Copy Markdown
Contributor

Fixes # (issue)

Changes

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

static std::string default_str = "";
return default_str;
}
static nostd::string_view GetDefaultKeyOrValue() noexcept { return ""; }

@denizariyan denizariyan Sep 13, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tried looking for context on why this was implemented like this in the git/pr history and it was added as part of a commit mentioning buffer overflow but this is not related to any buffer overflow. c9cbb1a

As far as I see there is no benefit of having a static string here, hence replaced with a str literal to prevent an additional bad_alloc potential on the same noexcept caller that was reported after fixing the other issue

@denizariyan denizariyan Sep 13, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I also chose not to mark this function noexcept (was marked initially in this PR). Since C++17 the exception specification is part of the function type, so adding it would change the type of a pre-existing public function without any benefits in this case

@codecov

codecov Bot commented Sep 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.25000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.48%. Comparing base (e0e0458) to head (3271383).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
ext/src/http/client/curl/http_operation_curl.cc 0.00% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4562      +/-   ##
==========================================
+ Coverage   86.45%   86.48%   +0.03%     
==========================================
  Files         525      525              
  Lines       20450    20455       +5     
==========================================
+ Hits        17679    17689      +10     
+ Misses       2771     2766       -5     
Files with missing lines Coverage Δ
api/include/opentelemetry/baggage/baggage.h 98.28% <100.00%> (ø)
api/include/opentelemetry/common/kv_properties.h 98.84% <100.00%> (-0.02%) ⬇️
api/include/opentelemetry/common/string_util.h 90.00% <100.00%> (+2.50%) ⬆️
...de/opentelemetry/trace/propagation/detail/string.h 93.34% <100.00%> (ø)
ext/src/http/client/curl/http_operation_curl.cc 61.16% <0.00%> (ø)

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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