Skip to content

logical-op compiler warning in gvalue_from_short

GCC reports the following warning when compiling with -Wlogical-op:

../common/xfconf-types.c: In function ‘gvalue_from_short’:
../common/xfconf-types.c:99:38: warning: logical ‘or’ of collectively exhaustive tests is always true [-Wlogical-op]
   99 |         if (dest > (guint64)SHRT_MAX || dest < (guint64)SHRT_MIN) {
      |                                      ^~

The relevant code:

98    } else if (G_VALUE_TYPE(dest_value) == XFCONF_TYPE_INT16) {
99        if (dest > (guint64)SHRT_MAX || dest < (guint64)SHRT_MIN) {
100            g_warning("Converting type \"%s\" to \"%s\" results in overflow",
101                      G_VALUE_TYPE_NAME(src_value),
102                      G_VALUE_TYPE_NAME(dest_value));
103        }

The warning seems correct because (guint64)SHRT_MIN casts -32768 to 18446744073709518848 (at least on my x86_64 machine).

I don't see any reports of overflow warnings on my machine or on GitLab, so maybe the code is not reached often?