Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect check in fpm_shm_free() #13797

Merged
merged 1 commit into from
Mar 24, 2024
Merged

Commits on Mar 24, 2024

  1. Fix incorrect check in fpm_shm_free()

    `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.
    nielsdos committed Mar 24, 2024
    Configuration menu
    Copy the full SHA
    dc908e8 View commit details
    Browse the repository at this point in the history