forked from OSchip/llvm-project
[lldb/Scalar] Fix undefined behavior
Fix UBSan error detected in TestDataFormatterObjCCF.py and TestDataFormatterObjCNSDate.py: Scalar.cpp:698:27: runtime error: -4.96303e+08 is outside the range of representable values of type 'unsigned long long'.
This commit is contained in:
parent
15440191b5
commit
2501e86acd
|
@ -736,7 +736,17 @@ long long Scalar::SLongLong(long long fail_value) const {
|
|||
}
|
||||
|
||||
unsigned long long Scalar::ULongLong(unsigned long long fail_value) const {
|
||||
return GetAsUnsigned<unsigned long long>(fail_value);
|
||||
switch (m_type) {
|
||||
case e_double: {
|
||||
double d_val = m_float.convertToDouble();
|
||||
llvm::APInt rounded_double =
|
||||
llvm::APIntOps::RoundDoubleToAPInt(d_val, sizeof(ulonglong_t) * 8);
|
||||
return static_cast<ulonglong_t>(
|
||||
(rounded_double.zextOrTrunc(sizeof(ulonglong_t) * 8)).getZExtValue());
|
||||
}
|
||||
default:
|
||||
return GetAsUnsigned<unsigned long long>(fail_value);
|
||||
}
|
||||
}
|
||||
|
||||
llvm::APInt Scalar::SInt128(const llvm::APInt &fail_value) const {
|
||||
|
|
Loading…
Reference in New Issue