Skip to content

Commit 8760c3c

Browse files
committed
Add change note
1 parent 6c24820 commit 8760c3c

File tree

4 files changed

+239
-0
lines changed

4 files changed

+239
-0
lines changed

change_notes/2024-10-17-suffixes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- `5.13.4` - `UnsignedLiteralsNotAppropriatelySuffixed.ql`:
2+
- Expand detection to binary literals.
3+
- `M2-13-3` - `MissingUSuffix.ql`:
4+
- Expand detection to binary literals.

cpp/common/src/codingstandards/cpp/rules/unsignedintegerliteralsnotappropriatelysuffixed/UnsignedIntegerLiteralsNotAppropriatelySuffixed.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ query predicate problems(Cpp14Literal::NumericLiteral nl, string message) {
1919
nl instanceof Cpp14Literal::OctalLiteral and literalKind = "Octal"
2020
or
2121
nl instanceof Cpp14Literal::HexLiteral and literalKind = "Hex"
22+
or
23+
nl instanceof Cpp14Literal::BinaryLiteral and literalKind = "Binary"
2224
) and
2325
// This either directly has an unsigned integer type, or it is converted to an unsigned integer type
2426
nl.getType().getUnspecifiedType().(IntegralType).isUnsigned() and

cpp/common/test/rules/unsignedintegerliteralsnotappropriatelysuffixed/UnsignedIntegerLiteralsNotAppropriatelySuffixed.expected

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@
1010
| test.cpp:266:3:266:26 | 9223372036854775808 | Octal literal is an unsigned integer but does not include a 'U' suffix. |
1111
| test.cpp:283:3:283:27 | 9223372036854775808 | Octal literal is an unsigned integer but does not include a 'U' suffix. |
1212
| test.cpp:300:3:300:27 | 9223372036854775808 | Octal literal is an unsigned integer but does not include a 'U' suffix. |
13+
| test.cpp:315:3:315:36 | 2147483648 | Binary literal is an unsigned integer but does not include a 'U' suffix. |
14+
| test.cpp:322:3:322:68 | 9223372036854775808 | Binary literal is an unsigned integer but does not include a 'U' suffix. |
15+
| test.cpp:365:3:365:69 | 9223372036854775808 | Binary literal is an unsigned integer but does not include a 'U' suffix. |
16+
| test.cpp:412:3:412:69 | 9223372036854775808 | Binary literal is an unsigned integer but does not include a 'U' suffix. |
17+
| test.cpp:457:3:457:70 | 9223372036854775808 | Binary literal is an unsigned integer but does not include a 'U' suffix. |
18+
| test.cpp:502:3:502:70 | 9223372036854775808 | Binary literal is an unsigned integer but does not include a 'U' suffix. |

cpp/common/test/rules/unsignedintegerliteralsnotappropriatelysuffixed/test.cpp

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,233 @@ void test_octal_constants() {
309309
// correctly
310310
}
311311

312+
void test_binary_constants() {
313+
0b0; // COMPLIANT - uses signed int
314+
0b1111111111111111111111111111111; // COMPLIANT - max value held by signed int
315+
0b10000000000000000000000000000000; // NON_COMPLIANT - larger than max signed
316+
// int, so will be unsigned int
317+
0b100000000000000000000000000000000; // COMPLIANT - larger than unsigned int,
318+
// but smaller than long int
319+
0b111111111111111111111111111111111111111111111111111111111111111; // COMPLIANT
320+
// - max
321+
// long int
322+
0b1000000000000000000000000000000000000000000000000000000000000000; // NON_COMPLIANT
323+
// -
324+
// larger
325+
// than
326+
// long
327+
// int, so
328+
// will be
329+
// unsigned
330+
// long
331+
// int
332+
0b0U; // COMPLIANT - unsigned, but uses the suffix correctly
333+
0b1111111111111111111111111111111U; // COMPLIANT - unsigned, but uses the
334+
// suffix correctly
335+
0b10000000000000000000000000000000U; // COMPLIANT - unsigned, but uses the
336+
// suffix correctly
337+
0b100000000000000000000000000000000U; // COMPLIANT - unsigned, but uses the
338+
// suffix correctly
339+
0b111111111111111111111111111111111111111111111111111111111111111U; // COMPLIANT
340+
// -
341+
// unsigned,
342+
// but
343+
// uses
344+
// the
345+
// suffix
346+
// correctly
347+
0b1000000000000000000000000000000000000000000000000000000000000000U; // COMPLIANT
348+
// -
349+
// unsigned,
350+
// but
351+
// uses
352+
// the
353+
// suffix
354+
// correctly
355+
356+
// Use of the `l` suffix
357+
0b0l; // COMPLIANT - uses signed long
358+
0b1111111111111111111111111111111l; // COMPLIANT - uses signed long
359+
0b10000000000000000000000000000000l; // COMPLIANT - uses signed long
360+
0b100000000000000000000000000000000l; // COMPLIANT - uses signed long
361+
0b111111111111111111111111111111111111111111111111111111111111111l; // COMPLIANT
362+
// - max
363+
// long
364+
// int
365+
0b1000000000000000000000000000000000000000000000000000000000000000l; // NON_COMPLIANT
366+
// -
367+
// larger
368+
// than
369+
// long
370+
// int,
371+
// so
372+
// will
373+
// be
374+
// unsigned
375+
// long
376+
// int
377+
0b0Ul; // COMPLIANT - unsigned, but uses the suffix correctly
378+
0b1111111111111111111111111111111Ul; // COMPLIANT - unsigned, but uses the
379+
// suffix correctly
380+
0b10000000000000000000000000000000Ul; // COMPLIANT - unsigned, but uses the
381+
// suffix correctly
382+
0b100000000000000000000000000000000Ul; // COMPLIANT - unsigned, but uses the
383+
// suffix correctly
384+
0b111111111111111111111111111111111111111111111111111111111111111Ul; // COMPLIANT
385+
// -
386+
// unsigned,
387+
// but
388+
// uses
389+
// the
390+
// suffix
391+
// correctly
392+
0b1000000000000000000000000000000000000000000000000000000000000000Ul; // COMPLIANT
393+
// -
394+
// unsigned,
395+
// but
396+
// uses
397+
// the
398+
// suffix
399+
// correctly
400+
401+
// Use of the `L` suffix
402+
0b0L; // COMPLIANT - uses signed long
403+
0b1111111111111111111111111111111L; // COMPLIANT - uses signed long
404+
0b10000000000000000000000000000000L; // COMPLIANT - uses signed long
405+
0b100000000000000000000000000000000L; // COMPLIANT - uses signed long
406+
0b111111111111111111111111111111111111111111111111111111111111111L; // COMPLIANT
407+
// -
408+
// COMPLIANT
409+
// - uses
410+
// signed
411+
// long
412+
0b1000000000000000000000000000000000000000000000000000000000000000L; // NON_COMPLIANT
413+
// -
414+
// larger
415+
// than
416+
// long
417+
// int,
418+
// so
419+
// will
420+
// be
421+
// unsigned
422+
// long
423+
// int
424+
0b0UL; // COMPLIANT - unsigned, but uses the suffix correctly
425+
0b1111111111111111111111111111111UL; // COMPLIANT - unsigned, but uses the
426+
// suffix correctly
427+
0b10000000000000000000000000000000UL; // COMPLIANT - unsigned, but uses the
428+
// suffix correctly
429+
0b100000000000000000000000000000000UL; // COMPLIANT - unsigned, but uses the
430+
// suffix correctly
431+
0b111111111111111111111111111111111111111111111111111111111111111UL; // COMPLIANT
432+
// -
433+
// unsigned,
434+
// but
435+
// uses
436+
// the
437+
// suffix
438+
// correctly
439+
0b1000000000000000000000000000000000000000000000000000000000000000UL; // COMPLIANT
440+
// -
441+
// unsigned,
442+
// but
443+
// uses
444+
// the
445+
// suffix
446+
// correctly
447+
448+
// Use of the `ll` suffix
449+
0b0ll; // COMPLIANT - uses signed long long
450+
0b1111111111111111111111111111111ll; // COMPLIANT - uses signed long long
451+
0b10000000000000000000000000000000ll; // COMPLIANT - uses signed long long
452+
0b100000000000000000000000000000000ll; // COMPLIANT - uses signed long long
453+
0b111111111111111111111111111111111111111111111111111111111111111ll; // COMPLIANT
454+
// - max
455+
// long
456+
// int
457+
0b1000000000000000000000000000000000000000000000000000000000000000ll; // NON_COMPLIANT
458+
// -
459+
// larger
460+
// than
461+
// long
462+
// int,
463+
// so
464+
// will
465+
// be
466+
// unsigned
467+
// long
468+
// int
469+
0b0Ull; // COMPLIANT - unsigned, but uses the suffix correctly
470+
0b1111111111111111111111111111111Ull; // COMPLIANT - unsigned, but uses the
471+
// suffix correctly
472+
0b10000000000000000000000000000000Ull; // COMPLIANT - unsigned, but uses the
473+
// suffix correctly
474+
0b100000000000000000000000000000000Ull; // COMPLIANT - unsigned, but uses the
475+
// suffix correctly
476+
0b111111111111111111111111111111111111111111111111111111111111111Ull; // COMPLIANT
477+
// -
478+
// unsigned,
479+
// but
480+
// uses
481+
// the
482+
// suffix
483+
// correctly
484+
0b1000000000000000000000000000000000000000000000000000000000000000Ull; // COMPLIANT
485+
// -
486+
// unsigned,
487+
// but
488+
// uses
489+
// the
490+
// suffix
491+
// correctly
492+
493+
// Use of the `LL` suffix
494+
00LL; // COMPLIANT - uses signed long long
495+
0b1111111111111111111111111111111LL; // COMPLIANT - uses signed long long
496+
0b10000000000000000000000000000000LL; // COMPLIANT - uses signed long long
497+
0b100000000000000000000000000000000LL; // COMPLIANT - uses signed long long
498+
0b111111111111111111111111111111111111111111111111111111111111111LL; // COMPLIANT
499+
// - max
500+
// long
501+
// int
502+
0b1000000000000000000000000000000000000000000000000000000000000000LL; // NON_COMPLIANT
503+
// -
504+
// larger
505+
// than
506+
// long
507+
// int,
508+
// so
509+
// will
510+
// be
511+
// unsigned
512+
// long
513+
// int
514+
00ULL; // COMPLIANT - unsigned, but uses the suffix correctly
515+
0b1111111111111111111111111111111ULL; // COMPLIANT - unsigned, but uses the
516+
// suffix correctly
517+
0b10000000000000000000000000000000ULL; // COMPLIANT - unsigned, but uses the
518+
// suffix correctly
519+
0b100000000000000000000000000000000ULL; // COMPLIANT - unsigned, but uses the
520+
// suffix correctly
521+
0b111111111111111111111111111111111111111111111111111111111111111ULL; // COMPLIANT
522+
// -
523+
// unsigned,
524+
// but
525+
// uses
526+
// the
527+
// suffix
528+
// correctly
529+
0b1000000000000000000000000000000000000000000000000000000000000000ULL; // COMPLIANT
530+
// -
531+
// unsigned,
532+
// but
533+
// uses
534+
// the
535+
// suffix
536+
// correctly
537+
}
538+
312539
#define COMPLIANT_VAL 0x80000000U
313540
#define NON_COMPLIANT_VAL 0x80000000
314541

0 commit comments

Comments
 (0)