|
|
|
|
|
by geofft
3215 days ago
|
|
A simple fix is using unsigned integers, as unsigned overflow is well-defined. (There isn't a way in C/C++ to request an exception or fault on integer overflow, which is what you'd want here, since you're running inside Python. A better conceptual fix is just doing the addition in Python, which is a more robust language than C/C++ for signed integer addition, but that kind of defeats the point of the example.) |
|
This is incorrect.
See compiler options: -ftrapv, -fsanitize=undefined. See compiler builtins: __builtin_add_overflow and friends.