cn-cbor
cn-cbor copied to clipboard
add overflow checks for MT_UNSIGNED, MT_NEGATIVE and MT_TAG
GCC 4.8.4 was released December 19, 2014.
Oh, and __builtin_add_overflow
is supported since GCC 5.0.1, released April 22, 2015.
GCC 5 is too new for the oldest LTS releases of Debilian and Ubuntu, which both will reach EOL in the middle of 2018 and 2019 respectively.
So how can we do this in a way that leaves a version that conforms to the C standards?
__builtin_add_overflow is not supported by my MSVC compiler. I would not be in favor of this.
@jimsch It would be interesting to know: how do you do overflow checks? Does MSVC have similar builtins? Do they have library functions doing integer overflow checking?
I am not aware of any such function that is part of MSVC. The few times that I have cared about it I have always written specific code for that addition. Usually by adding in a longer int and checking the result. The need to make sure that things run on all the different architectures targeted.