4 ms·
There's SIZE_MAX constant, I don't know why they didn't use it. I'd rewrite it as `if (n != 0 && m > SIZE_MAX / n)`. Seems legit to me.
by vbezhenar 4y ago
There's SIZE_MAX constant, I don't know why they didn't use it.
I'd rewrite it as `if (n != 0 && m > SIZE_MAX / n)`. Seems legit to me.
- pjmlp 4y agoMost likely to get around clever UB optimizations when checking for values beyond max sizes.
- caf 4y agoNo. (size_t)-1 and SIZE_MAX are identical, there is no difference in the two ways of writing that. Furthermore, optimisation can't bite you if you test the values before you perform the potentially UB operation (and unsigned operations can never overflow anyway, they are always well-defined).
- pjmlp 4y agoThat was just an assumption, far from me to know all UB cases, I leave that for tooling.
- mafuy 4y agoBut there is no such check here, is there? SIZE_MAX / SIZE_MAX is legally 1.