blob: 6bd8f797f4a082673fe8603cc7316bea7d198bb4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
/* $NetBSD: msg_230_uchar.c,v 1.13 2023/07/08 11:03:00 rillig Exp $ */
# 3 "msg_230_uchar.c"
// Test for message: nonportable character comparison '%s' [230]
/* lint1-flags: -S -g -p -w -X 351 */
/* lint1-only-if: uchar */
/*
* C11 6.2.5p15 defines that 'char' has the same range, representation, and
* behavior as either 'signed char' or 'unsigned char'.
*
* The portable range of 'char' is from 0 to 127 since all lint platforms
* define CHAR_SIZE to be 8.
*
* See msg_162.c, which covers 'signed char' and 'unsigned char'.
*/
void
compare_plain_char(char c)
{
/* expect+1: warning: nonportable character comparison '== -129' [230] */
if (c == -129)
return;
/* expect+1: warning: nonportable character comparison '== -128' [230] */
if (c == -128)
return;
/* expect+1: warning: nonportable character comparison '== -1' [230] */
if (c == -1)
return;
if (c == 0)
return;
if (c == 127)
return;
/* expect+1: warning: nonportable character comparison '== 128' [230] */
if (c == 128)
return;
/* expect+1: warning: nonportable character comparison '== 255' [230] */
if (c == 255)
return;
/* expect+1: warning: nonportable character comparison '== 256' [230] */
if (c == 256)
return;
}
void
compare_plain_char_yoda(char c)
{
/* expect+1: warning: nonportable character comparison '-129 == ?' [230] */
if (-129 == c)
return;
/* expect+1: warning: nonportable character comparison '-128 == ?' [230] */
if (-128 == c)
return;
/* expect+1: warning: nonportable character comparison '-1 == ?' [230] */
if (-1 == c)
return;
if (0 == c)
return;
if (127 == c)
return;
/* expect+1: warning: nonportable character comparison '128 == ?' [230] */
if (128 == c)
return;
/* expect+1: warning: nonportable character comparison '255 == ?' [230] */
if (255 == c)
return;
/* expect+1: warning: nonportable character comparison '256 == ?' [230] */
if (256 == c)
return;
}
void
compare_greater(char c)
{
/* expect+1: warning: nonportable character comparison '> -2' [230] */
if (c > -2)
return;
/* expect+1: warning: nonportable character comparison '>= -1' [230] */
if (c >= -1)
return;
/*
* XXX: The following two comparisons have the same effect, yet lint
* only warns about one of them.
*/
/* expect+1: warning: nonportable character comparison '> -1' [230] */
if (c > -1)
return;
/*
* This warning only occurs on uchar platforms since on these
* platforms it is always true. Code that needs this ordered
* comparison on values of type plain char is questionable since it
* behaves differently depending on the platform. Such a comparison
* should never be needed.
*/
/* expect+1: warning: operator '>=' compares 'char' with '0' [162] */
if (c >= 0)
return;
/*
* XXX: The following two comparisons have the same effect, yet lint
* only warns about one of them.
*/
if (c > 127)
return;
/* expect+1: warning: nonportable character comparison '>= 128' [230] */
if (c >= 128)
return;
/* expect+1: warning: nonportable character comparison '> 128' [230] */
if (c > 128)
return;
/* expect+1: warning: nonportable character comparison '>= 129' [230] */
if (c >= 129)
return;
}
/* Comparing a char expression with a character constant is always valid. */
void
compare_with_character_literal(char ch)
{
if (ch == '\200')
return;
if (ch == '\377')
return;
if (ch == '\000')
return;
}
|