fix: unify and correct RectArea implementations
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 12 Dec 2020 16:45:19 +0000 (08:45 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 23 Jan 2021 23:17:21 +0000 (15:17 -0800)
commit0a4a329d3fb5128cc358729d06d9387547c92ce2
treede5df368bc1c49660fb95604d8cfa3b9d0d3be75
parent3089d8a66625856aaf8a7d9042111e4ad54fa7ab
fix: unify and correct RectArea implementations

Two implementations of RectArea were provided that implemented the overflow
check based on whether there was a larger type than unsigned int available. It
is unnecessary to maintain multiple implementations of this as the overflow
check can be written in a width-independent way.

Moreover the `LLONG_MAX > UINT_MAX` alternative was incorrect. E.g. on x86-64
where this alternative is used, if `r->boundary[i + NUMDIMS] - r->boundary[i]`
is `UINT_MAX` and the accumulated value in `a_test` is `(long long)UINT_MAX`,
the multiplication (which is done on operands promoted to long long) overflows
causing undefined behavior. In practice, you would likely get a negative value,
that then erroneously passes the overflow check.

Related to #1898. Fixes #1906.
CHANGELOG.md
lib/label/rectangle.c
rtest/test_regression.py