Open Jaaaky opened 1 year ago
Here are some compiler flags to enable to show dozen of possible problems:
-Wall -Wextra -Werror=overflow -Wtype-limits -Woverflow -Wunused-value -Wmaybe-uninitialized -Werror=type-limits -Werror=maybe-uninitialized -Wfloat-equal -Wmissing-declarations -Werror=deprecated-declarations -Wincompatible-pointer-types -Wint-conversion
Solving those can help avoid dozen of bugs and undefined behaviors
Some more warning that could be fixed, but needs logic checking that I could not do
ccsa_quadratic.c: In function 'ccsa_quadratic_minimize':
ccsa_quadratic.c:365:4: warning: floating constant exceeds range of 'float' [-Woverflow]
365 | for (i = 0; i < m; ++i) dual_ub[i] = 1e40;
| ^~~
plip.c: In function 'plip_':
plip.c:204:5: warning: floating constant exceeds range of 'float' [-Woverflow]
204 | eta9 = 1e120;
| ^~~~
pnet.c: In function 'pnet_':
pnet.c:224:5: warning: floating constant exceeds range of 'float' [-Woverflow]
224 | eta9 = 1e120;
| ^~~~
mma.c: In function 'mma_minimize':
mma.c:241:4: warning: floating constant exceeds range of 'float' [-Woverflow]
241 | for (i = 0; i < m; ++i) dual_ub[i] = 1e40;
| ^~~
DIRsubrout.c: In function 'direct_dirheader_':
DIRsubrout.c:1490:2: warning: floating constant exceeds range of 'float' [-Woverflow]
1490 | *epsfix = 1e100;
| ^
DIRsubrout.c: In function 'direct_dirsummary_':
DIRsubrout.c:1586:3: warning: floating constant exceeds range of 'float' [-Woverflow]
1586 | if (*fglobal > -1e99)
| ^~
plis.c: In function 'plis_':
plis.c:189:5: warning: floating constant exceeds range of 'float' [-Woverflow]
189 | eta9 = 1e120;
| ^~~~
This looks like serious one too:
nldrmd.c:205:11: warning: ‘memset’ specified bound between 18446744056529682432 and 18446744073709551608 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]
205 | memset(xcur, 0, sizeof(double)*n);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Another interesting one
bobyqa.c:1037:19: error: 'adelt' may be used uninitialized in this function [-Werror=maybe-uninitialized]
1037 | temp = *adelt * *adelt - wfixsq;
| ~~~~~~~^~~~~~~~
compilation terminated due to -Wfatal-errors.
cc1: some warnings being treated as errors
Are you compiling on a platform where float
is the same as double
? The floating constant exceeds range of 'float'
make no sense otherwise, since the indicated constants are within the range of double precision.
warning: ‘memset’ specified bound between 18446744056529682432 and 18446744073709551608 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]
205 | memset(xcur, 0, sizeof(double)*n);
The code looks correct to me. I have no idea what this warning means — if n
is the size of the array, as it is in this code, then this is setting the correct number of bytes to zero.
I'm trying to port your library, enabling compiler warnings produces many that could be fixed and actually I think fixed them would enhance the quality of the lib too much.
Here are most of them