Skip to content

core: fix undefined behavior in Time::SetResolution().

std::pow (10, std::fabs (shift)) * quotient can be bigger than the biggest int64, resulting in undefined behavior. This MR makes variable factor INT64_MAX in this case.

I ran my simulation with undefined behavior sanitized (https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html), and got this.

external/ns3/ns3/core/model/time.cc:260:46: runtime error: 3.1536e+19 is outside the range of representable values of type 'long'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior external/ns3/ns3/core/model/time.cc:260:46 in 
external/ns3/ns3/core/model/int64x64-128.h:133:8: runtime error: left shift of negative value -9223372036854775808
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior external/ns3/ns3/core/model/int64x64-128.h:133:8 in 
external/ns3/ns3/core/model/int64x64-128.h:165:23: runtime error: left shift of negative value -9223372036854775808
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior external/ns3/ns3/core/model/int64x64-128.h:165:23 in 
external/ns3/ns3/core/model/int64x64-128.cc:200:29: runtime error: negation of 0x80000000000000000000000000000000 cannot be represented in type 'int128_t' (aka '__int128'); cast to an unsigned type to negate this value to itself
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior external/ns3/ns3/core/model/int64x64-128.cc:200:29 in 
external/ns3/ns3/core/model/int64x64-128.h:133:8: runtime error: left shift of negative value -831630385
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior external/ns3/ns3/core/model/int64x64-128.h:133:8 in

Merge request reports

Loading