[php-src] PR #13797: Fix incorrect check in fpm_shm_free()
| From: | nielsdos | Date: | Sun, 24 Mar 2024 01:24:56 +0000 |
| Subject: | [php-src] PR #13797: Fix incorrect check in fpm_shm_free() | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-25532@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/13797
Author: nielsdos
if (fpm_shm_size - size > 0) will be rewritten by the compiler as this: if
(fpm_shm_size == size), which is undesirable. The reason this happens is that both variables
are size_t, so subtracting them cannot be negative. The only way it can be not > 0, is if
they're equal because the result will then be 0. This means that if we have multiple fpm shm
allocations, the shm size will not decrease correctly.
To showcase that the compiler actually does this, take a look at this isolated case: https://godbolt.org/z/azobdWcrY. Here we can see the
usage of the compare instruction + cmove, so the "then" branch is only done if the
variables are equal.