Skip to content

Comments

CBOR-to-JSON: fix UB in converting out-of-bounds FP to integer#278

Merged
thiagomacieira merged 1 commit intointel:mainfrom
thiagomacieira:CBOR_to_JSON_fix_UB_in_converting_out_of_bounds_FP_to_integer
Mar 13, 2025
Merged

CBOR-to-JSON: fix UB in converting out-of-bounds FP to integer#278
thiagomacieira merged 1 commit intointel:mainfrom
thiagomacieira:CBOR_to_JSON_fix_UB_in_converting_out_of_bounds_FP_to_integer

Conversation

@thiagomacieira
Copy link
Member

Both the C and C++ standards say it is Undefined Behavior to convert a floating point number to integer if the input is out of bounds of the destination type.

And indeed this started failing in recent builds, with
val = 18446744073709551616 (2^64)
it has probably been producing ival = 18446744073709551615 for a while, but the conversion back to floating point now rounded up and compared equal to the input.

So let's just fix it.

Both the C and C++ standards say it is Undefined Behavior to convert a
floating point number to integer if the input is out of bounds of the
destination type.

And indeed this started failing in recent builds, with
  val = 18446744073709551616  (2^64)
it has probably been producing ival = 18446744073709551615 for a while,
but the conversion back to floating point now rounded up and compared
equal to the input.

So let's just fix it.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
@thiagomacieira thiagomacieira merged commit d0a6def into intel:main Mar 13, 2025
6 checks passed
@thiagomacieira thiagomacieira deleted the CBOR_to_JSON_fix_UB_in_converting_out_of_bounds_FP_to_integer branch March 13, 2025 02:36
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