As discussed in https://github.com/protocolbuffers/upb/issues/439, the LUA binding tests were failing on some compilers (e.g. s390x) since conversion of out-of-range integers values (e.g. 2^64 or 18446744073709551616) to a double can lead to undefined behavior. On some compilers, this conversion can return 0, but it can also return the max value. To make this check work across platforms, we do the following: 1. Break the double into its integral and fractional components. 2. If there any fractional components, return an error. 3. Compare the min and max values in an intelligent way. We can't simply compare against UINT64_MAX since that value will get implicitly converted to a double in an undefined way, and 18446744073709551616 > UINT64_MAX can return false. Instead, we can use the largest power of two and use ldexp to generate the max value. Closes https://github.com/protocolbuffers/upb/issues/439pull/13171/head
parent
dee1238cac
commit
9836087dd1
1 changed files with 10 additions and 10 deletions
Loading…
Reference in new issue