swh:1:snp:c7c108084bc0bf3d81436bf980b46e98bd338453
Revision c59e18c31a2135f136392cc199e9bbc8c6a18154 authored by Jean-Sébastien Pédron on 17 April 2015, 18:16:42 UTC, committed by Pascal de Bruijn on 18 April 2015, 15:44:20 UTC
Before this commit, the code did:
    int max = G_MAXINT; /* INT_MAX, 2147483647 */
    float factor = 1.0f;
    max *= factor;

Dimitry Andric helped me understand the problem; here is the
explanation:
    Here, "max * factor" is 2147483648.0, not 2147483647.0: the value is
    rounded up because the float type has a mantissa of 23 bits only.
    However, converting 2147483648.0 to an integer is an undefined
    behaviour.

The resulting value depends on the compiler and the level of
optimization:

    GCC (all versions) with -O0: max = -2147483648
    GCC (all versions) with -O2: max =  2147483647

    Clang up-to 3.5 with -O0:    max = -2147483648
    Clang up-to 3.5 with -O2:    max =  2147483647
    (ie. same behaviour as GCC)

    Clang 3.6+ with -O0:         max = -2147483648
    Clang 3.6+ with -O2:         max =           0

In the context of the preferences dialog, this means that all integers
must be between min=0 and max=0.

The fix, suggested by Dimitry, is to use a double as an intermediate
variable: it is wide enough to store "max * factor" without rounding up
the value. Then, 2147483647.0 can be converted to 2147483647.

(cherry picked from commit 9d77a28e54f8bc19592a170b1e4b9cf083f7b5a3)
1 parent 6bc644e
History
Tip revision: 50d91bdfc94cb9d3aa01634ac0b003d76e799bf1 authored by Tobias Ellinghaus on 04 May 2017, 21:56:48 UTC
Add db locking on Windows
Tip revision: 50d91bd
File Mode Size
cmake
data
doc
packaging
po
src
tools
.clang-format -rw-r--r-- 1.5 KB
.dir-locals.el -rw-r--r-- 94 bytes
.gitignore -rw-r--r-- 125 bytes
CMakeLists.txt -rw-r--r-- 11.3 KB
README.md -rw-r--r-- 2.3 KB
RELEASE_NOTES -rw-r--r-- 7.2 KB
build.sh -rwxr-xr-x 5.1 KB

README.md

back to top