3 ms·
I'm not sure there is a reliable, generic approach for detecting overflow in conformant C; you probably have to come up with the appropriate proof for the speci
by 0xcde4c3db 8y ago
I'm not sure there is a reliable, generic approach for detecting overflow in conformant C; you probably have to come up with the appropriate proof for the specific operation that you're about to do. OpenBSD does it for multiplication in reallocarray() [1], which was introduced because it was easy to code an integer overflow when doing something like malloc(sizeof(member) * nmembers).
[1] https://github.com/openbsd/src/blob/master/lib/libc/stdlib/reallocarray.c https://github.com/openbsd/src/blob/master/lib/libc/stdlib/r...