4 ms·
> And never do arithmetic on boundaries definitions like INT_MAX, they are boundaries I'd argue something stronger: if you care about boundaries like INT_MAX,
by Sirened 4y ago
> And never do arithmetic on boundaries definitions like INT_MAX, they are boundaries
I'd argue something stronger: if you care about boundaries like INT_MAX, you should never be comparing them using your regular comparison tools. I.e., even though there are correct ways to compute whether x + 1 will overflow, don't bother trying to do that and instead always use __builtin_add_overflow since you can't fuck it up. Trying to do these sorts of edge checks are incredibly hard and it has lead to numerous security vulnerabilities due to checks being optimized out. The builtins do exactly what they say and you don't have to worry about UB blowing your foot off.