Skip to content

Conversation

@hhvrc
Copy link
Contributor

@hhvrc hhvrc commented Dec 10, 2025

The current impl has a bug with signed integer minimum values

@hhvrc hhvrc self-assigned this Dec 10, 2025
@hhvrc hhvrc added the type: bug Something isn't working label Dec 10, 2025
@github-project-automation github-project-automation bot moved this to Todo in Roadmap Dec 10, 2025
@changeset-bot
Copy link

changeset-bot bot commented Dec 10, 2025

⚠️ No Changeset found

Latest commit: de6f2c5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Digits10Count(T val) previously used `val = -val` to obtain the magnitude for negative signed integers. This causes signed overflow for the most negative representable value (e.g. INT_MIN, LLONG_MIN), resulting in undefined behavior. The fix mirrors the logic used in the string-conversion code: convert the value to its corresponding unsigned type and use a modular negation (`U(0) - U(val)`) to obtain the magnitude safely and portably. This ensures correct digit counting for all integral types without invoking UB. Additional improvements: - Decay T to remove cv/ref qualifiers before applying type traits. - Use std::make_unsigned_t for consistent unsigned magnitude handling.
@github-actions
Copy link
Contributor

Cpp-Linter Report ⚠️

Some files did not pass the configured checks!

clang-format (v18.1.3) reports: 1 file(s) not formatted
  • src/Convert.cpp

Have any feedback or feature suggestions? Share it here.

@hhvrc hhvrc merged commit e3a8a75 into develop Dec 10, 2025
40 checks passed
@hhvrc hhvrc deleted the fix/integer-logic branch December 10, 2025 01:57
@github-project-automation github-project-automation bot moved this from Todo to Done in Roadmap Dec 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug Something isn't working

2 participants