[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: -Wtype-limits warning in info/infokey.c
From: |
Eli Zaretskii |
Subject: |
Re: -Wtype-limits warning in info/infokey.c |
Date: |
Thu, 10 Oct 2024 14:22:52 +0300 |
> Date: Thu, 10 Oct 2024 12:33:45 +0200
> From: Patrice Dumas <pertusus@free.fr>
>
> Hello,
>
> I get this warning:
> In file included from ../../info/doc.h:59,
> from ../../info/infokey.c:21:
> ../../info/infokey.c: In function ‘compile’:
> ../../info/infomap.h:105:29: warning: comparison is always true due to
> limited range of data type [-Wtype-limits]
> 105 | #define KEYMAP_META(k) ((k) < KEYMAP_META_BASE ? (k) +
> KEYMAP_META_BASE : (k))
> | ^
> ../../info/infokey.c:223:44: note: in expansion of macro ‘KEYMAP_META’
> 223 | seq[slen++] = meta ? KEYMAP_META(c) : (c); \
> | ^~~~~~~~~~~
> ../../info/infokey.c:380:21: note: in expansion of macro ‘To_seq’
> 380 | To_seq (oval);
> | ^~~~~~
This is because 'oval' is declared as 'char':
char oval = 0;
So therefore this part in KEYMAP_META:
#define KEYMAP_META(k) ((k) < KEYMAP_META_BASE ? (k) + KEYMAP_META_BASE : (k))
^^^^^^^^^^^^^^^^^^^^^^
is always true, because KEYMAP_META_BASE is 271, and a 'char' variable
cannot be more than 255 (if it's unsigned; otherwise it cannot be more
than 127).
I think we should declare 'oval' as 'int' instead.