Skip to content

[API] fix sign-conversion warnings in span & trace id#3761

Merged
marcalff merged 1 commit intoopen-telemetry:mainfrom
sjanel:chore/fix-unsigned-int-conversion-warnings
Nov 24, 2025
Merged

[API] fix sign-conversion warnings in span & trace id#3761
marcalff merged 1 commit intoopen-telemetry:mainfrom
sjanel:chore/fix-unsigned-int-conversion-warnings

Conversation

@sjanel
Copy link
Copy Markdown
Contributor

@sjanel sjanel commented Nov 22, 2025

Changes

Fix some warnings appearing with -Wsign-conversion:

opentelemetry_cpp-src/api/include/opentelemetry/trace/span_id.h:34:20: warning: conversion to ‘size_t’ {aka ‘long unsigned int’} from ‘int’ may change the sign of the result [-Wsign-conversion]
   34 |       buffer[i * 2 + 0] = kHex[(rep_[i] >> 4) & 0xF];
      |              ~~~~~~^~~
opentelemetry_cpp-src/api/include/opentelemetry/trace/span_id.h:35:20: warning: conversion to ‘size_t’ {aka ‘long unsigned int’} from ‘int’ may change the sign of the result [-Wsign-conversion]
   35 |       buffer[i * 2 + 1] = kHex[(rep_[i] >> 0) & 0xF];
      |              ~~~~~~^~~

api/include/opentelemetry/trace/trace_id.h:40:20: warning: conversion to ‘size_t’ {aka ‘long unsigned int’} from ‘int’ may change the sign of the result [-Wsign-conversion]
   40 |       buffer[i * 2 + 0] = kHex[(rep_[i] >> 4) & 0xF];
      |              ~~~~~~^~~
api/include/opentelemetry/trace/trace_id.h:41:20: warning: conversion to ‘size_t’ {aka ‘long unsigned int’} from ‘int’ may change the sign of the result [-Wsign-conversion]
   41 |       buffer[i * 2 + 1] = kHex[(rep_[i] >> 0) & 0xF];
      |              ~~~~~~^~~
opentelemetry_cpp-src/api/include/opentelemetry/nostd/string_view.h:127:21: warning: conversion to ‘opentelemetry::v1::nostd::string_view::size_type’ {aka ‘long unsigned int’} from ‘long int’ may change the sign of the result [-Wsign-conversion]
  127 |         res = found - data();
      |               ~~~~~~^~~~~~~~
opentelemetry_cpp-src/api/include/opentelemetry/nostd/internal/absl/types/../types/internal/variant.h:48:56: warning: unsigned conversion from ‘int’ to ‘absl::otel_v1::internal::identity_t<long unsigned int>’ {aka ‘long unsigned int’} changes value from ‘-1’ to ‘18446744073709551615’ [-Wsign-conversion]
   48 | OTABSL_INTERNAL_INLINE_CONSTEXPR(size_t, variant_npos, -1);
      |                                                        ^~

@sjanel sjanel requested a review from a team as a code owner November 22, 2025 15:45
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla bot commented Nov 22, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: sjanel / name: Stephane Janel (f723523)

@sjanel sjanel force-pushed the chore/fix-unsigned-int-conversion-warnings branch from 9d4aa88 to fb36519 Compare November 22, 2025 15:48
@codecov
Copy link
Copy Markdown

codecov bot commented Nov 22, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.95%. Comparing base (bed305f) to head (f723523).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #3761   +/-   ##
=======================================
  Coverage   89.95%   89.95%           
=======================================
  Files         225      225           
  Lines        7158     7158           
=======================================
  Hits         6438     6438           
  Misses        720      720           
Files with missing lines Coverage Δ
...metry/nostd/internal/absl/types/internal/variant.h 77.36% <ø> (ø)
api/include/opentelemetry/nostd/string_view.h 98.15% <100.00%> (ø)
api/include/opentelemetry/trace/span_id.h 100.00% <100.00%> (ø)
api/include/opentelemetry/trace/trace_id.h 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Member

@marcalff marcalff left a comment

Choose a reason for hiding this comment

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

Thanks for the fix, see comments.

{
buffer[i * 2 + 0] = kHex[(rep_[i] >> 4) & 0xF];
buffer[i * 2 + 1] = kHex[(rep_[i] >> 0) & 0xF];
buffer[static_cast<size_t>(i) * 2U + 0] = kHex[(rep_[i] >> 4) & 0xF];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since the original issue is about sign, how about changing variable i to unsigned in the for loop ?

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.

Done, plus two other similar warnings.

@sjanel sjanel force-pushed the chore/fix-unsigned-int-conversion-warnings branch from fb36519 to f723523 Compare November 22, 2025 17:09
Copy link
Copy Markdown
Member

@marcalff marcalff left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the fix.

@marcalff marcalff changed the title chore: fix sign-conversion warnings in span & trace id [API] fix sign-conversion warnings in span & trace id Nov 22, 2025
@marcalff marcalff merged commit 16c7067 into open-telemetry:main Nov 24, 2025
67 checks passed
malkia added a commit to malkia/opentelemetry-cpp that referenced this pull request Nov 24, 2025
[API] fix sign-conversion warnings in span & trace id (open-telemetry#3761)
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.

3 participants