Open Bug 1384827 Opened 4 years ago Updated 4 years ago

tautological comparison in pqg.c triggering on clang/32-bits


(NSS :: Libraries, defect, P3)



(Not tracked)


(Reporter: gaston, Unassigned)


Due to -Werror,-Wtautological-constant-out-of-range-compare, nss build on OpenBSD/i386 fails with clang:

cc -o OpenBSD6.1_OPT.OBJ/OpenBSD_SINGLE_SHLIB/pqg.o -c -O -fPIC -DPIC -Di386 -Wall -Wno-switch -pipe -DOPENBSD -Wall -Qunused-arguments -Wno-parentheses-equality -W    no-array-bounds -Wno-unevaluated-expression -Werror -DXP_UNIX -DSHLIB_SUFFIX=\"so.48.0\" -DSHLIB_PREFIX=\"lib\" -DSHLIB_VERSION=\"3\" -DSOFTOKEN_SHLIB_VERSION=\"3\" -DRIJNDAEL_INCLUDE_TABLES -UDEBUG -DNDEBUG -pthread -DNSS_NO_INIT_SUPPORT -DUSE_UTIL_DIRECTLY -DNO_NSPR_10_SUPPORT -DSSL_DISABLE_DEPRECATED_CIPHER_SUITE_NAMES -DNSS_X8    6_OR_X64 -DNSS_X86 -DMP_API_COMPATIBLE -I/usr/local/include/nspr -I../../../dist/OpenBSD6.1_OPT.OBJ/include -I../../../dist/public/nss -I../../../dist/private/nss -Im    pi -Iecl -I/usr/local/include -O2 -pipe   pqg.c
pqg.c:345:16: error: comparison of constant 18446744073709551615 with expression of type 'unsigned long' is always true [-Werror,-Wtautological-constant-out-of-rang    e-compare]
    if (addend < MP_DIGIT_MAX) {
        ~~~~~~ ^ ~~~~~~~~~~~~
1 error generated.
gmake[3]: *** [../../coreconf/ OpenBSD6.1_OPT.OBJ/OpenBSD_SINGLE_SHLIB/pqg.o] Error 1 maybe the limit isnt the right one ?
Ew, that code is here since 17 years...
Giving a quick look at the code, comparing an unsigned long with a macro that is defined depending on the various typedefs size is a sure way to fail. I see that addend is casted all around to mp_digit, so either addend should be an mp_digit, or it should be compared to ULONG_MAX. Which is the best, i have no idea.
I went for the latter and fixed it with ULONG_MAX within our portstree:

If that solution is acceptable i'll do a proper patch for commit here.
Priority: -- → P3
You need to log in before you can comment on or make changes to this bug.