lint: fix test for message 324 on i386
i386 is an ILP32 platform (arch/i386/targparam.h). On these platforms, int and long have the same size, and even with the -p option for portability checks, INT_RSIZE in inittyp.c is defined to 4, not 3. Because of this, in check_integer_conversion, psize(nt) was not greater than psize(ot), and the warning was not issued. To make the test behave the same on all platforms, changed the long variables to long long, since long long is 64-bit on all platforms, and int is 32-bit.
This commit is contained in:
parent
5650392b38
commit
1aa2d3570d
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: msg_324.c,v 1.3 2021/01/05 23:20:53 rillig Exp $ */
|
||||
/* $NetBSD: msg_324.c,v 1.4 2021/01/06 09:23:04 rillig Exp $ */
|
||||
# 3 "msg_324.c"
|
||||
|
||||
// Test for message: suggest cast from '%s' to '%s' on op %s to avoid overflow [324]
|
||||
@ -19,34 +19,34 @@
|
||||
void
|
||||
example(char c, int i, unsigned u)
|
||||
{
|
||||
long l;
|
||||
unsigned long ul;
|
||||
long long ll;
|
||||
unsigned long long ull;
|
||||
|
||||
l = c + i;
|
||||
l = i - c;
|
||||
ul = c * u;
|
||||
ul = u + c;
|
||||
ul = i - u;
|
||||
ul = u * i;
|
||||
l = i << c;
|
||||
ll = c + i;
|
||||
ll = i - c;
|
||||
ull = c * u;
|
||||
ull = u + c;
|
||||
ull = i - u;
|
||||
ull = u * i;
|
||||
ll = i << c;
|
||||
|
||||
/*
|
||||
* The operators SHR, DIV and MOD cannot produce an overflow,
|
||||
* therefore no warning is necessary for them.
|
||||
*/
|
||||
l = i >> c;
|
||||
ul = u / c;
|
||||
ul = u % c;
|
||||
ll = i >> c;
|
||||
ull = u / c;
|
||||
ull = u % c;
|
||||
|
||||
/*
|
||||
* Assigning the result of an increment or decrement operator to a
|
||||
* differently-sized type is no unusual that there is no need to warn
|
||||
* about it. It's also more unlikely that there is an actual loss
|
||||
* since this only happens for a single value of the old type, unlike
|
||||
* "ul = u * u", which has many more possibilities for overflowing.
|
||||
* "ull = u * u", which has many more possibilities for overflowing.
|
||||
*/
|
||||
ul = u++;
|
||||
ul = ++u;
|
||||
ul = u--;
|
||||
ul = --u;
|
||||
ull = u++;
|
||||
ull = ++u;
|
||||
ull = u--;
|
||||
ull = --u;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
msg_324.c(25): warning: suggest cast from 'int' to 'long' on op + to avoid overflow [324]
|
||||
msg_324.c(26): warning: suggest cast from 'int' to 'long' on op - to avoid overflow [324]
|
||||
msg_324.c(27): warning: suggest cast from 'unsigned int' to 'unsigned long' on op * to avoid overflow [324]
|
||||
msg_324.c(28): warning: suggest cast from 'unsigned int' to 'unsigned long' on op + to avoid overflow [324]
|
||||
msg_324.c(29): warning: suggest cast from 'unsigned int' to 'unsigned long' on op - to avoid overflow [324]
|
||||
msg_324.c(30): warning: suggest cast from 'unsigned int' to 'unsigned long' on op * to avoid overflow [324]
|
||||
msg_324.c(31): warning: suggest cast from 'int' to 'long' on op << to avoid overflow [324]
|
||||
msg_324.c(25): warning: suggest cast from 'int' to 'long long' on op + to avoid overflow [324]
|
||||
msg_324.c(26): warning: suggest cast from 'int' to 'long long' on op - to avoid overflow [324]
|
||||
msg_324.c(27): warning: suggest cast from 'unsigned int' to 'unsigned long long' on op * to avoid overflow [324]
|
||||
msg_324.c(28): warning: suggest cast from 'unsigned int' to 'unsigned long long' on op + to avoid overflow [324]
|
||||
msg_324.c(29): warning: suggest cast from 'unsigned int' to 'unsigned long long' on op - to avoid overflow [324]
|
||||
msg_324.c(30): warning: suggest cast from 'unsigned int' to 'unsigned long long' on op * to avoid overflow [324]
|
||||
msg_324.c(31): warning: suggest cast from 'int' to 'long long' on op << to avoid overflow [324]
|
||||
|
Loading…
Reference in New Issue
Block a user