Skip to content

Commit 061efb7

Browse files
committed
Rule 7.2: Add test for octal literals
1 parent 2a805c0 commit 061efb7

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

c/misra/test/rules/RULE-7-2/UOrUSuffixRepresentedInUnsignedType.expected

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@
44
| test.c:162:3:162:21 | 9223372036854775808 | Unsigned literal 0x8000000000000000L does not explicitly express sign with a 'U' or 'u' suffix. |
55
| test.c:185:3:185:22 | 9223372036854775808 | Unsigned literal 0x8000000000000000ll does not explicitly express sign with a 'U' or 'u' suffix. |
66
| test.c:208:3:208:22 | 9223372036854775808 | Unsigned literal 0x8000000000000000LL does not explicitly express sign with a 'U' or 'u' suffix. |
7+
| test.c:227:3:227:14 | 2147483648 | Unsigned literal 020000000000 does not explicitly express sign with a 'U' or 'u' suffix. |
8+
| test.c:232:3:232:25 | 9223372036854775808 | Unsigned literal 01000000000000000000000 does not explicitly express sign with a 'U' or 'u' suffix. |
9+
| test.c:249:3:249:26 | 9223372036854775808 | Unsigned literal 01000000000000000000000l does not explicitly express sign with a 'U' or 'u' suffix. |
10+
| test.c:266:3:266:26 | 9223372036854775808 | Unsigned literal 01000000000000000000000L does not explicitly express sign with a 'U' or 'u' suffix. |
11+
| test.c:283:3:283:26 | 9223372036854775808 | Unsigned literal 01000000000000000000000l does not explicitly express sign with a 'U' or 'u' suffix. |
12+
| test.c:300:3:300:26 | 9223372036854775808 | Unsigned literal 01000000000000000000000L does not explicitly express sign with a 'U' or 'u' suffix. |

c/misra/test/rules/RULE-7-2/test.c

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,94 @@ void test_hexadecimal_constants() {
221221
0x8000000000000000LLu; // COMPLIANT - unsigned, but uses the suffix correctly
222222
}
223223

224+
void test_octal_constants() {
225+
00; // COMPLIANT - uses signed int
226+
017777777777; // COMPLIANT - max value held by signed int
227+
020000000000; // NON_COMPLIANT - larger than max signed int, so will be
228+
// unsigned int
229+
040000000000; // COMPLIANT - larger than unsigned int, but smaller than long
230+
// int
231+
0777777777777777777777; // COMPLIANT - max long int
232+
01000000000000000000000; // NON_COMPLIANT - larger than long int, so will be
233+
// unsigned long int
234+
00U; // COMPLIANT - unsigned, but uses the suffix correctly
235+
017777777777U; // COMPLIANT - unsigned, but uses the suffix correctly
236+
020000000000U; // COMPLIANT - unsigned, but uses the suffix correctly
237+
040000000000U; // COMPLIANT - unsigned, but uses the suffix correctly
238+
0777777777777777777777U; // COMPLIANT - unsigned, but uses the suffix
239+
// correctly
240+
01000000000000000000000U; // COMPLIANT - unsigned, but uses the suffix
241+
// correctly
242+
243+
// Use of the `l` suffix
244+
00l; // COMPLIANT - uses signed long
245+
017777777777l; // COMPLIANT - uses signed long
246+
020000000000l; // COMPLIANT - uses signed long
247+
040000000000l; // COMPLIANT - uses signed long
248+
0777777777777777777777l; // COMPLIANT - max long int
249+
01000000000000000000000l; // NON_COMPLIANT - larger than long int, so will be
250+
// unsigned long int
251+
00Ul; // COMPLIANT - unsigned, but uses the suffix correctly
252+
017777777777Ul; // COMPLIANT - unsigned, but uses the suffix correctly
253+
020000000000Ul; // COMPLIANT - unsigned, but uses the suffix correctly
254+
040000000000Ul; // COMPLIANT - unsigned, but uses the suffix correctly
255+
0777777777777777777777Ul; // COMPLIANT - unsigned, but uses the suffix
256+
// correctly
257+
01000000000000000000000Ul; // COMPLIANT - unsigned, but uses the suffix
258+
// correctly
259+
260+
// Use of the `L` suffix
261+
00L; // COMPLIANT - uses signed long
262+
017777777777L; // COMPLIANT - uses signed long
263+
020000000000L; // COMPLIANT - uses signed long
264+
040000000000L; // COMPLIANT - uses signed long
265+
0777777777777777777777L; // COMPLIANT - COMPLIANT - uses signed long
266+
01000000000000000000000L; // NON_COMPLIANT - larger than long int, so will be
267+
// unsigned long int
268+
00UL; // COMPLIANT - unsigned, but uses the suffix correctly
269+
017777777777UL; // COMPLIANT - unsigned, but uses the suffix correctly
270+
020000000000UL; // COMPLIANT - unsigned, but uses the suffix correctly
271+
040000000000UL; // COMPLIANT - unsigned, but uses the suffix correctly
272+
0777777777777777777777UL; // COMPLIANT - unsigned, but uses the suffix
273+
// correctly
274+
01000000000000000000000UL; // COMPLIANT - unsigned, but uses the suffix
275+
// correctly
276+
277+
// Use of the `ll` suffix
278+
00ll; // COMPLIANT - uses signed long long
279+
017777777777l; // COMPLIANT - uses signed long long
280+
020000000000l; // COMPLIANT - uses signed long long
281+
040000000000l; // COMPLIANT - uses signed long long
282+
0777777777777777777777l; // COMPLIANT - max long int
283+
01000000000000000000000l; // NON_COMPLIANT - larger than long int, so will be
284+
// unsigned long int
285+
00Ul; // COMPLIANT - unsigned, but uses the suffix correctly
286+
017777777777Ul; // COMPLIANT - unsigned, but uses the suffix correctly
287+
020000000000Ul; // COMPLIANT - unsigned, but uses the suffix correctly
288+
040000000000Ul; // COMPLIANT - unsigned, but uses the suffix correctly
289+
0777777777777777777777Ul; // COMPLIANT - unsigned, but uses the suffix
290+
// correctly
291+
01000000000000000000000Ul; // COMPLIANT - unsigned, but uses the suffix
292+
// correctly
293+
294+
// Use of the `LL` suffix
295+
00L; // COMPLIANT - uses signed long long
296+
017777777777L; // COMPLIANT - uses signed long long
297+
020000000000L; // COMPLIANT - uses signed long long
298+
040000000000L; // COMPLIANT - uses signed long long
299+
0777777777777777777777L; // COMPLIANT - max long int
300+
01000000000000000000000L; // NON_COMPLIANT - larger than long int, so will be
301+
// unsigned long int
302+
00UL; // COMPLIANT - unsigned, but uses the suffix correctly
303+
017777777777UL; // COMPLIANT - unsigned, but uses the suffix correctly
304+
020000000000UL; // COMPLIANT - unsigned, but uses the suffix correctly
305+
040000000000UL; // COMPLIANT - unsigned, but uses the suffix correctly
306+
0777777777777777777777UL; // COMPLIANT - unsigned, but uses the suffix
307+
// correctly
308+
01000000000000000000000UL; // COMPLIANT - unsigned, but uses the suffix
309+
// correctly
310+
}
311+
224312
#define COMPLIANT_VAL 0x80000000U
225313
#define NON_COMPLIANT_VAL 0x80000000
226314

0 commit comments

Comments
 (0)