| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: msg_230_uchar.c,v 1.6 2021/12/16 21:14:59 rillig Exp $ */ | | 1 | /* $NetBSD: msg_230_uchar.c,v 1.7 2022/02/26 11:13:01 rillig Exp $ */ |
2 | # 3 "msg_230_uchar.c" | | 2 | # 3 "msg_230_uchar.c" |
3 | | | 3 | |
4 | // Test for message: nonportable character comparison '%s %d' [230] | | 4 | // Test for message: nonportable character comparison '%s %d' [230] |
5 | | | 5 | |
6 | /* lint1-flags: -S -g -p -w */ | | 6 | /* lint1-flags: -S -g -p -w */ |
7 | /* lint1-only-if: uchar */ | | 7 | /* lint1-only-if: uchar */ |
8 | | | 8 | |
9 | /* | | 9 | /* |
10 | * C11 6.2.5p15 defines that 'char' has the same range, representation, and | | 10 | * C11 6.2.5p15 defines that 'char' has the same range, representation, and |
11 | * behavior as either 'signed char' or 'unsigned char'. | | 11 | * behavior as either 'signed char' or 'unsigned char'. |
12 | * | | 12 | * |
13 | * The portable range of 'char' is from 0 to 127 since all lint platforms | | 13 | * The portable range of 'char' is from 0 to 127 since all lint platforms |
14 | * define CHAR_SIZE to be 8. | | 14 | * define CHAR_SIZE to be 8. |
| @@ -36,52 +36,52 @@ compare_plain_char(char c) | | | @@ -36,52 +36,52 @@ compare_plain_char(char c) |
36 | if (c == 128) | | 36 | if (c == 128) |
37 | return; | | 37 | return; |
38 | /* expect+1: warning: nonportable character comparison '== 255' [230] */ | | 38 | /* expect+1: warning: nonportable character comparison '== 255' [230] */ |
39 | if (c == 255) | | 39 | if (c == 255) |
40 | return; | | 40 | return; |
41 | /* expect+1: warning: nonportable character comparison '== 256' [230] */ | | 41 | /* expect+1: warning: nonportable character comparison '== 256' [230] */ |
42 | if (c == 256) | | 42 | if (c == 256) |
43 | return; | | 43 | return; |
44 | } | | 44 | } |
45 | | | 45 | |
46 | void | | 46 | void |
47 | compare_plain_char_yoda(char c) | | 47 | compare_plain_char_yoda(char c) |
48 | { | | 48 | { |
49 | /* expect+1: warning: nonportable character comparison '== -129' */ | | 49 | /* expect+1: warning: nonportable character comparison '== -129' [230] */ |
50 | if (-129 == c) | | 50 | if (-129 == c) |
51 | return; | | 51 | return; |
52 | /* expect+1: warning: nonportable character comparison '== -128' */ | | 52 | /* expect+1: warning: nonportable character comparison '== -128' [230] */ |
53 | if (-128 == c) | | 53 | if (-128 == c) |
54 | return; | | 54 | return; |
55 | /* expect+1: warning: nonportable character comparison '== -1' */ | | 55 | /* expect+1: warning: nonportable character comparison '== -1' [230] */ |
56 | if (-1 == c) | | 56 | if (-1 == c) |
57 | return; | | 57 | return; |
58 | if (0 == c) | | 58 | if (0 == c) |
59 | return; | | 59 | return; |
60 | if (127 == c) | | 60 | if (127 == c) |
61 | return; | | 61 | return; |
62 | /* expect+1: warning: nonportable character comparison '== 128' */ | | 62 | /* expect+1: warning: nonportable character comparison '== 128' [230] */ |
63 | if (128 == c) | | 63 | if (128 == c) |
64 | return; | | 64 | return; |
65 | /* expect+1: warning: nonportable character comparison '== 255' */ | | 65 | /* expect+1: warning: nonportable character comparison '== 255' [230] */ |
66 | if (255 == c) | | 66 | if (255 == c) |
67 | return; | | 67 | return; |
68 | /* expect+1: warning: nonportable character comparison '== 256' */ | | 68 | /* expect+1: warning: nonportable character comparison '== 256' [230] */ |
69 | if (256 == c) | | 69 | if (256 == c) |
70 | return; | | 70 | return; |
71 | } | | 71 | } |
72 | | | 72 | |
73 | void | | 73 | void |
74 | compare_lt(char c) | | 74 | compare_greater(char c) |
75 | { | | 75 | { |
76 | | | 76 | |
77 | /* expect+1: warning: nonportable character comparison '> -2' [230] */ | | 77 | /* expect+1: warning: nonportable character comparison '> -2' [230] */ |
78 | if (c > -2) | | 78 | if (c > -2) |
79 | return; | | 79 | return; |
80 | /* expect+1: warning: nonportable character comparison '>= -1' [230] */ | | 80 | /* expect+1: warning: nonportable character comparison '>= -1' [230] */ |
81 | if (c >= -1) | | 81 | if (c >= -1) |
82 | return; | | 82 | return; |
83 | | | 83 | |
84 | /* | | 84 | /* |
85 | * XXX: The following two comparisons have the same effect, yet lint | | 85 | * XXX: The following two comparisons have the same effect, yet lint |
86 | * only warns about one of them. | | 86 | * only warns about one of them. |
87 | */ | | 87 | */ |
| @@ -106,13 +106,29 @@ compare_lt(char c) | | | @@ -106,13 +106,29 @@ compare_lt(char c) |
106 | if (c > 127) | | 106 | if (c > 127) |
107 | return; | | 107 | return; |
108 | /* expect+1: warning: nonportable character comparison '>= 128' [230] */ | | 108 | /* expect+1: warning: nonportable character comparison '>= 128' [230] */ |
109 | if (c >= 128) | | 109 | if (c >= 128) |
110 | return; | | 110 | return; |
111 | | | 111 | |
112 | /* expect+1: warning: nonportable character comparison '> 128' [230] */ | | 112 | /* expect+1: warning: nonportable character comparison '> 128' [230] */ |
113 | if (c > 128) | | 113 | if (c > 128) |
114 | return; | | 114 | return; |
115 | /* expect+1: warning: nonportable character comparison '>= 129' [230] */ | | 115 | /* expect+1: warning: nonportable character comparison '>= 129' [230] */ |
116 | if (c >= 129) | | 116 | if (c >= 129) |
117 | return; | | 117 | return; |
118 | } | | 118 | } |
| | | 119 | |
| | | 120 | void |
| | | 121 | compare_with_character_literal(char ch) |
| | | 122 | { |
| | | 123 | /* |
| | | 124 | * These comparisons are portable since the character constant is |
| | | 125 | * interpreted using the type 'char' on the exact same platform as |
| | | 126 | * where the comparison takes place. |
| | | 127 | */ |
| | | 128 | if (ch == '\200') |
| | | 129 | return; |
| | | 130 | if (ch == '\377') |
| | | 131 | return; |
| | | 132 | if (ch == '\000') |
| | | 133 | return; |
| | | 134 | } |