fix(Foundation): Fix UBSan errors in VarHolder.h#5091
Merged
Conversation
60ef488 to
1738055
Compare
1738055 to
98a77e1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #5090 - UndefinedBehaviorSanitizer errors in VarHolder.h
Fixed issues:
numValDigitsfor signed integers: NegatingINT_MINcaused signed overflow (UB). Now uses safe unsigned arithmetic:U(0) - static_cast<U>(value).numValDigitsfor floating point: Casting large floats (e.g.,1e20) toint64_tcaused UB. Now usesstd::ilogb()to get bit count directly from the exponent.POCO_VAR_RANGE_EXCEPTIONmacro: Casting out-of-range values to target type was UB. AddedrangeExcCastStr()helper that safely casts integral sources tointmax_t/uintmax_t, and returns "?" for floating-point sources.C++17 modernization (while fixing the above):
[[nodiscard]]toclone(),type(),size(), and allis*()query methodsif constexpr:checkUpperLimit/checkLowerLimit: 4 overloads → 2 functionsconvertToSmaller: 3 overloads → 1 functionconvertToSigned/convertToUnsigned: 6 overloads → 2 functionsunpreserveSign()function (inlined safe arithmetic intonumValDigits)Var.hto suppress[[nodiscard]]warning for intentionally ignoredclone()returnTest plan
-fsanitize=undefined -fno-sanitize=vptr)