-
Notifications
You must be signed in to change notification settings - Fork 293
/
c-cpp-rules.json
4417 lines (4413 loc) · 252 KB
/
c-cpp-rules.json
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
"name": "360 安全规则集合",
"version": "1.4.0",
"encoding": "utf-8",
"language": "C,C++",
"url": "https://github.com/Qihoo360/safe-rules/blob/main/c-cpp-rules.md",
"//": [
"下面以 ID_ 开头的键为规则标识符,对应的值为规则内容。",
"规则内容包括:",
" checkPoint:规则的定义",
" comment:对规则的简要说明",
" standard:相关的 ISO/IEC 标准条款",
" reference:参考条目",
" tag:规则的类别",
" level:违反规则的后果严重程度",
" related:有相关性的其他规则",
" config:相关配置项的名称及含义",
"level 分为:",
" error:直接导致错误或形成安全漏洞",
" warning:可导致错误或形成安全隐患",
" suspicious:可疑的代码,需进一步排查",
" suggestion:代码质量降低,应依照建议改进"
],
"ID_sizeof_oddExpression": {
"checkPoint": "sizeof 不应作用于比较或逻辑表达式",
"level": "warning",
"comment": "sizeof 作用于 <、>、<=、>=、==、!=、&&、|| 等表达式为常见笔误,相关运算符往往应该移出 sizeof 表达式。",
"tag": "expression"
},
"ID_sizeof_pointerDivision": {
"checkPoint": "被除数不应是作用于指针的 sizeof 表达式",
"level": "warning",
"comment": "形如 sizeof(p) / n 的表达式往往意在获取数组元素的个数,如果 p 是指针,sizeof(p) 是指针大小而不是数组大小,结果很可能是错误的。",
"tag": "expression",
"related": "ID_sizeof_pointer",
"reference": "CWE-467"
},
"ID_sizeof_void": {
"checkPoint": "sizeof 不可作用于 void",
"level": "error",
"comment": "void 表示不存在的类型,也是不完整的类型,sizeof 作用于 void 是没意义的,属于语言运用错误,也可能是 sizeof(void*) 的笔误。",
"tag": "expression",
"standard": "ISO/IEC 9899:1999 6.2.5(19),ISO/IEC 9899:1999 6.3.2.2(1),ISO/IEC 9899:2011 6.2.5(19),ISO/IEC 9899:2011 6.3.2.2(1)"
},
"ID_differentEnumComparison": {
"checkPoint": "不应比较非同类枚举值",
"level": "warning",
"comment": "比较非同类枚举值相当于比较不同类别的事物,往往是设计缺陷或逻辑错误。",
"tag": "expression",
"reference": "CWE-697,MISRA C 2012 10.4"
},
"ID_ptrIntCast": {
"checkPoint": "指针与整数不应相互转换",
"level": "warning",
"comment": "指针与整数相互转换容易造成地址不完整、寻址错误、降低可移植性等多种问题。",
"config": [
"allowPointerToSizeType: 是否放过指针与 size_t 的转换"
],
"tag": "cast",
"standard": "ISO/IEC 9899:1999 6.3.2.3(5)-implementation,ISO/IEC 9899:1999 7.18.1.4(1),ISO/IEC 9899:2011 6.3.2.3(5)-implementation,ISO/IEC 9899:2011 7.20.1.4(1),ISO/IEC 14882:2003 5.2.10(4 5)-implementation,ISO/IEC 14882:2011 3.7.4.3(1),ISO/IEC 14882:2011 5.2.10(4 5)-implementation",
"related": "ID_fixedAddrToPointer",
"reference": "MISRA C 2004 11.3,MISRA C 2012 11.4,MISRA C++ 2008 5-2-9,SEI CERT INT36-C"
},
"ID_zeroAsPtrValue": {
"checkPoint": "不应使用常量 0 表示空指针",
"level": "suggestion",
"comment": "在 C 代码中应使用 NULL 表示空指针,在 C++ 代码中应使用 nullptr 表示空指针。",
"tag": "pointer",
"related": "ID_oddPtrBoolAssignment,ID_oddPtrCharAssignment,ID_oddPtrBoolComparison,ID_oddPtrCharComparison",
"standard": "ISO/IEC 9899:1999 6.3.2.3(3),ISO/IEC 9899:2011 6.3.2.3(3),ISO/IEC 14882:2003 4.10(1),ISO/IEC 14882:2011 4.10(1)",
"reference": "C++ Core Guidelines ES.47,MISRA C 2012 11.9,MISRA C++ 2008 4-10-2"
},
"ID_charWCharCast": {
"checkPoint": "不同的字符串类型之间不可直接转换",
"level": "warning",
"comment": "char* 和 wchar_t* 直接转换并不进行字符集转换,属于语言运用错误,char*、wchar_t*、char16_t* 以及 char32_t* 之间均不可直接转换。",
"tag": "cast",
"related": "ID_castNoInheritance,ID_plainBinaryChar",
"reference": "CWE-704,SEI CERT STR38-C"
},
"ID_repeatedUnaryOperators": {
"checkPoint": "不应重复使用一元运算符",
"level": "warning",
"comment": "重复的一元运算符没有意义,为常见笔误。",
"tag": "expression"
},
"ID_minusOnUnsigned": {
"checkPoint": "负号不应作用于无符号整数",
"level": "warning",
"comment": "负号作用于 unsigned int、unsigned long、unsigned long long 等无符号整型表达式的结果仍为无符号整数,易产生意料之外的错误。",
"tag": "expression",
"config": [
"allowSmallUnsignedTypes: 是否允许负号作用于 unsigned char、unsigned short 等无符号整型表达式"
],
"standard": "ISO/IEC 9899:1999 6.5.3.3(3),ISO/IEC 9899:2011 6.5.3.3(3)",
"reference": "MISRA C 2004 12.9,MISRA C 2012 10.1,MISRA C++ 2008 5-3-2"
},
"ID_bitwiseOperOnSigned": {
"checkPoint": "位运算符不应作用于有符号整数",
"level": "warning",
"comment": "符号位在位运算方面没有逻辑意义,对负数进行位运算往往意味着逻辑错误。",
"tag": "expression",
"related": "ID_illEnumOperation",
"standard": "ISO/IEC 9899:1999 6.5.7(3)-undefined,ISO/IEC 9899:1999 6.5.7(4)-undefined,ISO/IEC 9899:1999 6.5.7(5)-implementation,ISO/IEC 9899:2011 6.5.7(3)-undefined,ISO/IEC 9899:2011 6.5.7(4)-undefined,ISO/IEC 9899:2011 6.5.7(5)-implementation,ISO/IEC 14882:2003 5.8(2),ISO/IEC 14882:2003 5.8(3)-implementation,ISO/IEC 14882:2011 5.8(2)-undefined,ISO/IEC 14882:2011 5.8(3)-implementation",
"reference": "CWE-682,C++ Core Guidelines ES.101,MISRA C 2004 12.7,MISRA C 2012 10.1,MISRA C++ 2008 5-0-21,SEI CERT INT13-C"
},
"ID_simplifiableTernary": {
"checkPoint": "化简可转换为逻辑表达式的三元表达式",
"level": "suggestion",
"comment": "当三元表达式的分枝是常量 true 或 false 时应化简为逻辑表达式。",
"tag": "expression"
},
"ID_stickyAssignmentOperator": {
"checkPoint": "注意赋值运算符与一元运算符的空格方式",
"level": "warning",
"comment": "如果 = 与 +、-、*、!、&、~ 等一元运算符之间没有空格,而一元运算符与其子表达式之间有空格,是一种非常怪异的格式,也可能是 +=、-=、*=、&= 等复合赋值运算符的笔误。",
"tag": "expression",
"reference": "CWE-480"
},
"ID_redundantParentheses": {
"checkPoint": "避免多余的括号",
"level": "suggestion",
"comment": "重复的或与优先级无关的括号使代码显得繁琐,应去掉。",
"tag": "style",
"reference": "MISRA C++ 2008 5-0-2"
},
"ID_throwNULL": {
"checkPoint": "不应抛出 NULL",
"level": "warning",
"comment": "虽然 NULL 表示空指针,但在相当一部分实现中 throw NULL 相当于 throw 0,无法区分指针与整数。",
"tag": "exception",
"related": "ID_deprecatedNULL,ID_throwNonExceptionType,ID_throwPointer",
"standard": "ISO/IEC 14882:2003 C.2.2.3(1)-implementation,ISO/IEC 14882:2011 C.3.2.4(1)-implementation,ISO/IEC 14882:2017 C.5.2.7(1)-implementation",
"reference": "CWE-351,MISRA C++ 2008 15-1-2"
},
"ID_throwNullptr": {
"checkPoint": "不应抛出 nullptr",
"level": "warning",
"comment": "nullptr 可被所有接受指针的 catch 子句捕获,使异常处理失去针对性。",
"tag": "exception",
"related": "ID_throwPointer",
"reference": "MISRA C++ 2008 15-0-2"
},
"ID_throwNonExceptionType": {
"checkPoint": "不应抛出非异常类型的对象",
"level": "warning",
"comment": "不应将整数、字符串等非异常类的对象当作异常抛出,否则意味着异常相关的设计是不健全的。",
"config": [
"mustInheritStdException: 是否要求异常类必须派生自 std::exception"
],
"tag": "exception",
"related": "ID_catch_nonExceptionType",
"reference": "C++ Core Guidelines E.14,C++ Core Guidelines E.3"
},
"ID_throwGenericException": {
"checkPoint": "不应抛出过于宽泛的异常",
"level": "warning",
"comment": "抛出过于宽泛的异常,如 std::exception、std::logic_error、std::runtime_error 等类型的异常,会使异常处理失去针对性,而且处理这种异常时很可能会将本不应处理的异常一并捕获。",
"tag": "exception",
"related": "ID_catch_generic",
"reference": "CWE-397"
},
"ID_rethrowOutOfCatch": {
"checkPoint": "不应在 catch 子句外使用空 throw 表达式(throw;)",
"level": "warning",
"comment": "空 throw 表达式用于重新抛出当前捕获的异常,用在 catch 子句外是危险的,增大了流程控制的复杂性。",
"tag": "exception",
"standard": "ISO/IEC 14882:2003 15.1(6 8),ISO/IEC 14882:2003 15.3(9)-implementation,ISO/IEC 14882:2011 15.1(8 9),ISO/IEC 14882:2011 15.3(9)-implementation",
"reference": "MISRA C++ 2008 15-1-3"
},
"ID_improperRethrow": {
"checkPoint": "重新抛出异常时应使用空 throw 表达式(throw;)",
"level": "warning",
"comment": "重新抛出异常时应使用空 throw 表达式,避免异常对象的精度损失和不必要的复制开销。",
"tag": "exception",
"standard": "ISO/IEC 14882:2003 15.1(6),ISO/IEC 14882:2011 15.1(8)"
},
"ID_forbidException": {
"checkPoint": "禁用 C++ 异常",
"level": "warning",
"comment": "禁用 try、catch、throw 关键字,并禁用使用异常的库。",
"tag": "exception",
"related": "ID_exceptionUnsafe",
"reference": "C++ Core Guidelines E.6,Google C++ Style Guide.Other C++ Features.Exceptions"
},
"ID_invalidExternSpecifier": {
"checkPoint": "extern 关键字不应作用于类成员的声明或定义",
"level": "warning",
"comment": "extern 关键字作用于类成员的声明或定义是没有意义的,属于语言运用错误。",
"tag": "declaration",
"standard": "ISO/IEC 14882:2003 9.2(6),ISO/IEC 14882:2011 9.2(6),ISO/IEC 14882:2017 12.2(9)"
},
"ID_invalidParamArraySize": {
"checkPoint": "不应将数组作为函数的形式参数",
"level": "warning",
"comment": "被声明为数组的形式参数等同于指针,第一个维度的大小声明对传入的实际参数起不到限制作用。",
"tag": "declaration",
"related": "ID_inconsistentArraySize,ID_forbidCArray,ID_sizeof_arrayParameter",
"standard": "ISO/IEC 9899:1999 6.7.5.3(7),ISO/IEC 9899:2011 6.7.6.3(7),ISO/IEC 14882:2003 13.1(3),ISO/IEC 14882:2011 13.1(3)",
"reference": "C++ Core Guidelines I.13,C++ Core Guidelines R.14,MISRA C++ 2008 5-2-12"
},
"ID_forbidCArray": {
"checkPoint": "在 C++ 代码中用容器代替 C 数组",
"level": "suggestion",
"comment": "相比 C 数组,C++ 的 std::array、std::vector 等容器更安全,且提供成员函数,以及标准库支持。",
"tag": "declaration",
"related": "ID_invalidParamArraySize",
"reference": "C++ Core Guidelines SL.con.1, C++ Core Guidelines R.14"
},
"ID_illMemberCall": {
"checkPoint": "基类对象构造完毕之前不可调用成员函数",
"level": "warning",
"comment": "基类对象未构造完毕时调用成员函数会导致标准未定义的行为。",
"tag": "function",
"standard": "ISO/IEC 14882:2003 12.6.2(8)-undefined,ISO/IEC 14882:2011 12.6.2(13)-undefined"
},
"ID_incompleteVaMacros": {
"checkPoint": "va_start 或 va_copy 应配合 va_end 使用",
"level": "warning",
"comment": "可变参数列表相关的 va_start 或 va_copy 和 va_end 应在同一函数中使用,否则会导致标准未定义的行为。",
"tag": "precompile",
"related": "ID_forbidVariadicFunction",
"standard": "ISO/IEC 9899:1999 7.15.1.3(2)-undefined,ISO/IEC 9899:2011 7.16.1.3(2)-undefined"
},
"ID_functionSpecialization": {
"checkPoint": "函数模板不应被特化",
"level": "warning",
"comment": "特化的函数模板不参与重载函数的选取,易导致意料之外的错误。",
"tag": "function",
"reference": "C++ Core Guidelines T.144,MISRA C++ 2008 14-8-1"
},
"ID_tooManyLines": {
"checkPoint": "函数的行数应在规定范围之内",
"level": "warning",
"comment": "函数体过大违反模块化编程理念,使人难以阅读,更不便于维护,应适当重构。",
"config": [
"maxLineCount: 函数行数上限,超过则报出"
],
"tag": "function",
"reference": "C++ Core Guidelines F.2,C++ Core Guidelines F.3"
},
"ID_unsuitableCapture": {
"checkPoint": "合理设置 lambda 表达式的捕获方式",
"level": "warning",
"comment": "如果 lambda 表达式只在函数内部使用,可采用捕获引用的方式;如果 lambda 表达式可以超出函数作用域,应采用捕获值的方式。",
"tag": "function",
"standard": "ISO/IEC 14882:2011 5.1.2,ISO/IEC 14882:2017 8.1.5.2",
"related": "ID_localAddressFlowOut",
"reference": "C++ Core Guidelines F.52,C++ Core Guidelines F.53,C++ Core Guidelines F.54,SEI CERT EXP61-CPP"
},
"ID_tooManyLambdaLines": {
"checkPoint": "lambda 表达式的行数应在规定范围之内",
"level": "warning",
"comment": "复杂的 lambda 表达式与调用者的代码混在一起是难以阅读的,引入 lambda 表达式的目的应该是“化简”,否则应使用普通函数。",
"config": [
"maxLambdaLineCount: lambda 表达式行数上限,超过则报出"
],
"tag": "function"
},
"ID_tooManyLabels": {
"checkPoint": "函数的标签数量应在规定范围之内",
"level": "warning",
"comment": "标签过多意味着函数内部的跳转逻辑过于复杂,违反结构化设计理念,应适当重构。",
"config": [
"maxLabelCount: 标签数量上限,超过则报出"
],
"tag": "function",
"reference": "CWE-1119"
},
"ID_memoryLeak": {
"checkPoint": "避免内存泄露",
"level": "warning",
"comment": "动态分配的内存地址不可被遗失,否则相关内存无法被访问也无法被回收,这种问题称为“内存泄漏(memory leak)”,会导致可用内存被耗尽,使程序无法正常运行。",
"tag": "resource",
"related": "ID_resourceLeak,ID_ownerlessResource,ID_throwInConstructor,ID_memberDeallocation,ID_multiAllocation,ID_exceptionUnsafe",
"standard": "ISO/IEC 9899:1999 7.20.3(1),ISO/IEC 9899:2011 7.22.3(1),ISO/IEC 14882:2003 3.7.3.1(2),ISO/IEC 14882:2003 3.7.4.1(2)",
"reference": "CWE-401,C++ Core Guidelines P.8,C++ Core Guidelines E.13"
},
"ID_resourceLeak": {
"checkPoint": "避免资源泄露",
"level": "warning",
"comment": "对于动态分配的资源,其地址、句柄或描述符等标志性信息不可被遗失,否则资源无法被访问也无法被回收,这种问题称为“资源泄漏”,会导致资源耗尽或死锁等问题,使程序无法正常运行。",
"tag": "resource",
"related": "ID_memoryLeak,ID_memberDeallocation,ID_ownerlessResource,ID_throwInConstructor,ID_multiAllocation,ID_unnecessaryAllocation,ID_asynchronousTermination,ID_exceptionUnsafe",
"reference": "CWE-772,C++ Core Guidelines P.8"
},
"ID_insufficientDelete": {
"checkPoint": "用 delete 释放数组不可漏写中括号",
"level": "error",
"comment": "用 new[] 分配的数组应该用 delete[] 释放,不可漏写中括号,否则会导致标准未定义的行为。",
"tag": "resource",
"related": "ID_excessiveDelete",
"standard": "ISO/IEC 14882:2003 5.3.5(2)-undefined,ISO/IEC 14882:2011 5.3.5(2)-undefined,ISO/IEC 14882:2017 8.3.5(2)-undefined",
"reference": "C++ Core Guidelines ES.61"
},
"ID_excessiveDelete": {
"checkPoint": "用 delete 释放对象不可多写中括号",
"level": "error",
"comment": "用 new 分配的对象应该用 delete 释放,不可用 delete[] 释放,否则会导致标准未定义的行为。",
"tag": "resource",
"related": "ID_insufficientDelete",
"standard": "ISO/IEC 14882:2003 5.3.5(2)-undefined,ISO/IEC 14882:2011 5.3.5(2)-undefined,ISO/IEC 14882:2017 8.3.5(2)-undefined",
"reference": "C++ Core Guidelines ES.61"
},
"ID_incompatibleDealloc": {
"checkPoint": "资源的分配与回收方法应配套使用",
"level": "error",
"comment": "使用了某种分配方法,就应使用与其配套的回收方法,否则会引发严重错误。",
"tag": "resource",
"standard": "ISO/IEC 9899:1999 7.20.3.2(2)-undefined,ISO/IEC 9899:2011 7.22.3.3(2)-undefined,ISO/IEC 14882:2003 3.7.3.2(3),ISO/IEC 14882:2011 3.7.4.2(3)-undefined",
"related": "ID_incompleteNewDeletePair",
"reference": "SEI CERT MEM51-CPP"
},
"ID_illAccess": {
"checkPoint": "不可访问未初始化或已释放的资源",
"level": "error",
"comment": "访问未初始化或已释放的资源属于逻辑错误,会导致标准未定义的行为。",
"tag": "resource",
"standard": "ISO/IEC 9899:1999 7.19.3(4),ISO/IEC 9899:2011 7.21.3(4)",
"related": "ID_wildPtrDeref,ID_danglingDeref,ID_localInitialization,ID_dynamicInitialization",
"reference": "CWE-672,CWE-908,SEI CERT FIO46-C,SEI CERT MEM30-C,SEI CERT MEM50-CPP,SEI CERT EXP33-C,SEI CERT EXP53-CPP"
},
"ID_illDealloc": {
"checkPoint": "不可释放非动态分配的内存",
"level": "error",
"comment": "释放非动态分配的内存会导致标准未定义的行为。",
"tag": "resource",
"related": "ID_incompatibleDealloc",
"standard": "ISO/IEC 9899:1999 7.20.3.2(2)-undefined,ISO/IEC 9899:2011 7.22.3.3(2)-undefined,ISO/IEC 14882:2003 5.3.5(2)-undefined,ISO/IEC 14882:2011 5.3.5(2)-undefined",
"reference": "MISRA C 2012 22.2,SEI CERT MEM34-C"
},
"ID_doubleFree": {
"checkPoint": "不可重复释放资源",
"level": "error",
"comment": "重复释放资源会导致标准未定义的行为。",
"tag": "resource",
"standard": "ISO/IEC 9899:1999 7.20.3.2(2)-undefined,ISO/IEC 9899:2011 7.22.3.3(2)-undefined,ISO/IEC 14882:2003 3.7.3.2(4)-undefined,ISO/IEC 14882:2011 3.7.4.2(4)-undefined",
"related": "ID_missingResetNull,ID_ownerlessResource,ID_missingCopyConstructor,ID_missingCopyAssignOperator,ID_violateRuleOfFive",
"reference": "CWE-415,SEI CERT MEM00-C"
},
"ID_invalidNullCheck": {
"checkPoint": "避免无效的空指针检查",
"level": "warning",
"comment": "当指针的值一定不为空时,再对其进行检查是没有意义的,往往意味着逻辑错误。",
"tag": "pointer",
"related": "ID_repeatedNullCheck",
"standard": "ISO/IEC 14882:2003 18.4,ISO/IEC 14882:2011 18.6"
},
"ID_repeatedNullCheck": {
"checkPoint": "不应重复检查指针是否为空",
"level": "warning",
"comment": "重复的空指针检查是不必要的,使代码显得繁琐,且干扰编译器优化。",
"tag": "pointer",
"related": "ID_invalidNullCheck"
},
"ID_copiedStream": {
"checkPoint": "流式资源对象不应被复制",
"level": "warning",
"comment": "FILE 等流式对象不应被复制,如果存在多个副本会造成数据不一致的问题。",
"tag": "resource",
"standard": "ISO/IEC 9899:1999 7.19.3(6),ISO/IEC 9899:2011 7.21.3(6)",
"reference": "MISRA C 2012 22.5"
},
"ID_arrayIndexOverflow": {
"checkPoint": "避免指针运算的结果溢出",
"level": "error",
"comment": "指针运算的结果溢出会导致标准未定义的行为。",
"tag": "pointer",
"related": "ID_bufferOverflow",
"standard": "ISO/IEC 9899:1999 6.5.3.2(3),ISO/IEC 9899:1999 6.5.6(8)-undefined,ISO/IEC 9899:2011 6.5.3.2(3),ISO/IEC 9899:2011 6.5.6(8)-undefined,ISO/IEC 14882:2003 5.7(5)-undefined,ISO/IEC 14882:2011 5.7(5)-undefined",
"reference": "MISRA C 2004 17.1,MISRA C 2012 18.1,MISRA C++ 2008 5-0-16,SEI CERT ARR30-C"
},
"ID_oddSubscripting": {
"checkPoint": "数组下标应为整型表达式",
"level": "warning",
"comment": "C/C++ 语言规定,数组下标可以在中括号的右侧也可以在左侧,然而这只是一种理论上的设计,在实际代码中应采用约定俗成的方式,即数组的名称在中括号的左侧,下标在中括号的右侧。",
"tag": "expression",
"standard": "ISO/IEC 9899:1999 6.5.2.1(2),ISO/IEC 9899:2011 6.5.2.1(2),ISO/IEC 14882:2003 8.3.4(6),ISO/IEC 14882:2011 8.3.4(6)"
},
"ID_plainSensitiveInfo": {
"checkPoint": "敏感数据不可写入代码",
"level": "warning",
"comment": "代码中的敏感数据极易泄露,产品及相关运维、测试工具的代码均不可记录任何敏感数据。",
"tag": "security",
"related": "ID_secretLeak",
"reference": "CWE-259,CWE-798,SEI CERT MSC41-C"
},
"ID_throwPointer": {
"checkPoint": "不应抛出指针",
"level": "suggestion",
"comment": "抛出指针会增加不必要的内存管理成本,也容易造成意料之外的错误。",
"tag": "exception",
"reference": "MISRA C++ 2008 15-0-2"
},
"ID_if_tooManyElseIf": {
"checkPoint": "if...else-if 分枝数量应在规定范围之内",
"level": "warning",
"comment": "if...else-if 分枝过多不利于阅读和维护,而且执行时需逐一判断各分枝的条件,效率较低,建议改为遵循某种算法的索引结构。",
"config": [
"maxElseIfCount: 分枝数量上限,超过则报出"
],
"tag": "control",
"related": "ID_switch_tooManyCases",
"reference": "CWE-1121"
},
"ID_for_floatCounter": {
"checkPoint": "for 循环变量不应为浮点型",
"level": "warning",
"comment": "用于控制循环次数的变量称为“循环变量”,这种变量不应采用浮点类型,否则循环的次数难以控制。",
"tag": "control",
"related": "ID_illFloatComparison,ID_for_invalidCounter",
"reference": "MISRA C 2004 13.4,MISRA C 2012 14.1,MISRA C++ 2008 6-5-1,SEI CERT FLP30-C"
},
"ID_for_invalidCounter": {
"checkPoint": "for 循环变量应在循环条件范围内有效增减",
"level": "error",
"comment": "用于控制循环次数的变量称为“循环变量”,这种变量应在循环条件范围内有效增减,确保循环过程得以正确执行并退出。",
"tag": "control",
"related": "ID_for_floatCounter",
"reference": "CWE-835"
},
"ID_for_counterChangedInBody": {
"checkPoint": "for 循环变量不应在循环体内被改变",
"level": "warning",
"comment": "用于控制循环次数的变量称为“循环变量”,为了使代码具有清晰的静态结构,循环变量只应在 for 语句的第 3 个表达式中被改变。",
"tag": "control",
"reference": "CWE-1095,C++ Core Guidelines ES.86,MISRA C 2004 13.6,MISRA C++ 2008 6-5-3"
},
"ID_for_counterNested": {
"checkPoint": "嵌套的 for 语句不应使用相同的循环变量",
"level": "warning",
"comment": "同一个循环变量在内外层 for 循环中均被修改,使循环次数难以控制,是过于复杂的循环逻辑,也可能是某种错误。",
"tag": "control",
"related": "ID_for_counterChangedInBody"
},
"ID_for_emptyBlock": {
"checkPoint": "for 循环体不应为空",
"level": "warning",
"comment": "空的 for 循环结构不清晰,可读性较差。",
"tag": "control",
"reference": "C++ Core Guidelines ES.85"
},
"ID_switch_caseOutOfRange": {
"checkPoint": "case 标签的值不可超出 switch 条件表达式的取值范围",
"level": "warning",
"comment": "如果 case 标签的值超出了 switch 条件表达式的取值范围,会导致相应分枝永远不会被执行。",
"tag": "control",
"related": "ID_illComparison",
"reference": "CWE-561"
},
"ID_switch_uselessFallThrough": {
"checkPoint": "不应存在紧邻 default 标签的空 case 标签",
"level": "warning",
"comment": "紧邻 default 标签的空 case 标签是没有意义的,应当去除。",
"tag": "control"
},
"ID_switch_onlyDefault": {
"checkPoint": "switch 语句不应只包含 default 标签",
"level": "warning",
"comment": "只有 default 标签的 switch 语句是没有意义的,起不到分枝选择的作用,往往是残留代码或功能未实现。",
"tag": "control",
"reference": "MISRA C 2012 16.6,MISRA C++ 2008 6-4-8"
},
"ID_switch_onlyOneCase": {
"checkPoint": "switch 语句不应只包含一个 case 标签",
"level": "warning",
"comment": "只有一个 case 标签的 switch 语句与 if 语句语义相同,但形式上更为复杂,应改为 if 语句。",
"tag": "control",
"reference": "MISRA C 2012 16.6"
},
"ID_switch_tooManyCases": {
"checkPoint": "switch 语句分枝数量应在规定范围之内",
"level": "warning",
"comment": "switch 语句分枝过多不利于阅读和维护,这种情况下建议将分枝抽取成函数,再按遵循某种算法的索引结构组织在一起。",
"config": [
"maxCasesCount: 分枝数量上限,超过则报出"
],
"tag": "control",
"related": "ID_if_tooManyElseIf",
"reference": "CWE-1121"
},
"ID_switch_brace": {
"checkPoint": "switch 语句应该用大括号括起来",
"level": "suggestion",
"comment": "switch 语句应为包含多条语句的复合语句,且用大括号括起来,否则不应选用 switch 语句。",
"tag": "control",
"related": "ID_if_brace,ID_switch_onlyDefault,ID_switch_onlyOneCase",
"reference": "MISRA C 2004 14.8,MISRA C 2012 15.6,MISRA C++ 2008 6-3-1"
},
"ID_switch_forbidNest": {
"checkPoint": "switch 语句不应嵌套",
"level": "suggestion",
"comment": "嵌套的 switch 语句使代码显得复杂,不利于阅读和维护。",
"tag": "control"
},
"ID_try_disorderedHandlers": {
"checkPoint": "面向派生类的 catch 子句应排在面向基类的 catch 子句之前",
"level": "error",
"comment": "以派生类对象为参数的 catch 子句应排在以基类对象为参数的 catch 子句之前,否则后面的 catch 子句会失去作用。",
"tag": "control",
"related": "ID_unreachableCode",
"standard": "ISO/IEC 14882:2003 15.3,ISO/IEC 14882:2011 15.3,ISO/IEC 14882:2011 18.3",
"reference": "CWE-561,C++ Core Guidelines E.31,MISRA C++ 2008 15-3-6,SEI CERT ERR54-CPP"
},
"ID_try_disorderedEllipsis": {
"checkPoint": "捕获所有异常的 catch(...) 子句应位于最后",
"level": "error",
"comment": "如果 catch(...) 子句排在前面,其后面的 catch 子句会失去作用。",
"tag": "control",
"related": "ID_unreachableCode",
"standard": "ISO/IEC 14882:2003 15.3(6),ISO/IEC 14882:2011 15.3(5),ISO/IEC 14882:2011 18.3(5)",
"reference": "CWE-561,C++ Core Guidelines E.31,MISRA C++ 2008 15-3-7"
},
"ID_try_forbidNest": {
"checkPoint": "不应嵌套 try-catch 语句",
"level": "suggestion",
"comment": "嵌套的 try-catch 语句使代码显得复杂,不利于阅读和维护。",
"tag": "control",
"reference": "C++ Core Guidelines E.17"
},
"ID_catch_value": {
"checkPoint": "通过引用捕获异常",
"level": "warning",
"comment": "通过值捕获异常可能会导致“对象切片”,通过指针捕获异常会增加内存管理成本,通过引用捕获异常才是最合理的方式。",
"tag": "exception",
"related": "ID_catch_slicing,ID_throwPointer",
"reference": "C++ Core Guidelines E.15,C++ Core Guidelines ES.63,MISRA C++ 2008 15-3-5,SEI CERT ERR61-CPP"
},
"ID_catch_slicing": {
"checkPoint": "捕获异常时不应产生对象切片问题",
"level": "warning",
"comment": "通过值捕获多态类的异常对象会使其多态性失效,使异常被错误处理。",
"tag": "exception",
"related": "ID_catch_value,ID_objectSlicing",
"reference": "C++ Core Guidelines C.145,C++ Core Guidelines ES.63"
},
"ID_catch_generic": {
"checkPoint": "不应捕获过于宽泛的异常",
"level": "warning",
"comment": "捕获过于宽泛的异常,如捕获 std::exception、std::logic_error、std::runtime_error 等类型的异常,或使用 catch(...) 子句捕获所有异常,会使异常处理失去针对性,而且很可能会将本不应处理的异常一并捕获。",
"tag": "exception",
"related": "ID_throwGenericException",
"reference": "CWE-396"
},
"ID_catch_nonExceptionType": {
"checkPoint": "不应捕获非异常类型的对象",
"level": "warning",
"comment": "整数、字符串等非异常类的对象不应被当作异常捕获,否则意味着异常相关的设计是不健全的。",
"tag": "exception",
"related": "ID_throwNonExceptionType",
"reference": "C++ Core Guidelines E.14"
},
"ID_catch_justRethrow": {
"checkPoint": "捕获异常后不应直接再次抛出异常",
"level": "warning",
"comment": "捕获异常后将其直接再次抛出是没有意义的,还会造成不必要的开销。",
"tag": "exception"
},
"ID_missingDestructor": {
"checkPoint": "存在拷贝构造函数或拷贝赋值运算符时,不应缺少析构函数",
"level": "warning",
"comment": "存在拷贝构造函数或拷贝赋值运算符时,不应缺少析构函数。",
"tag": "type",
"related": "ID_missingCopyConstructor,ID_missingCopyAssignOperator,ID_violateRuleOfFive",
"reference": "C++ Core Guidelines C.21,C++ Core Guidelines C.30,C++ Core Guidelines C.33"
},
"ID_missingCopyConstructor": {
"checkPoint": "存在析构函数或拷贝赋值运算符时,不应缺少拷贝构造函数",
"level": "warning",
"comment": "存在析构函数或拷贝赋值运算符时,不应缺少拷贝构造函数。",
"tag": "type",
"related": "ID_missingDestructor,ID_missingCopyAssignOperator,ID_violateRuleOfFive",
"reference": "C++ Core Guidelines C.21"
},
"ID_violateRuleOfZero": {
"checkPoint": "避免重复实现由默认拷贝、移动、析构函数完成的功能",
"level": "warning",
"comment": "当类只负责成员对象的组合而没有特殊的复制、移动、析构需求时,不应定义相关函数。",
"tag": "type",
"related": "ID_violateRuleOfFive",
"reference": "C++ Core Guidelines C.21"
},
"ID_missingCopyAssignOperator": {
"checkPoint": "存在拷贝构造函数或析构函数时,不应缺少拷贝赋值运算符",
"level": "warning",
"comment": "存在拷贝构造函数或析构函数时,不应缺少拷贝赋值运算符。",
"tag": "type",
"related": "ID_missingDestructor,ID_missingCopyConstructor,ID_violateRuleOfFive",
"reference": "C++ Core Guidelines C.21"
},
"ID_violateRuleOfFive": {
"checkPoint": "存在任一拷贝、移动、析构相关的函数时,应定义所有相关函数",
"level": "warning",
"comment": "存在任一拷贝、移动、析构相关的函数时,应定义所有相关函数。",
"tag": "type",
"related": "ID_missingCopyConstructor,ID_missingCopyAssignOperator,ID_missingDestructor,ID_violateRuleOfZero",
"reference": "C++ Core Guidelines C.21"
},
"ID_missingExplicitConstructor": {
"checkPoint": "可接受一个参数的构造函数需用 explicit 关键字限定",
"level": "suggestion",
"comment": "为了避免意料之外的类型转换,可接受一个参数的构造函数应该用 explicit 关键字限定。",
"tag": "type",
"related": "ID_missingExplicitConvertor",
"reference": "C++ Core Guidelines C.46,MISRA C++ 2008 12-1-3"
},
"ID_missingExplicitConvertor": {
"checkPoint": "重载的类型转换运算符需用 explicit 关键字限定",
"level": "suggestion",
"comment": "为了避免意料之外的类型转换,重载的类型转换运算符需用 explicit 关键字限定。",
"tag": "type",
"related": "ID_missingExplicitConstructor",
"reference": "C++ Core Guidelines C.164"
},
"ID_unsuitableAssignOperator": {
"checkPoint": "抽象类禁用拷贝和移动赋值运算符",
"level": "warning",
"comment": "抽象类只能作为基类,没有独立的对象,调用拷贝或移动赋值运算符会造成数据不完整。",
"tag": "type",
"reference": "C++ Core Guidelines C.67,MISRA C++ 2008 12-8-2"
},
"ID_excessiveExplicit": {
"checkPoint": "不应过度使用 explicit 关键字",
"level": "warning",
"comment": "对类的拷贝、移动以及不接受 1 个参数的构造函数一般不用 explicit 限定,否则有损代码的易用性和可扩展性。",
"tag": "type",
"reference": "C++ Core Guidelines C.46"
},
"ID_tooManyFields": {
"checkPoint": "数据成员的数量应在规定范围之内",
"level": "warning",
"comment": "类或联合体的数据成员过多意味着一个逻辑或功能单位承担了过多的职责,违反了模块化设计理念,是难以维护的。",
"config": [
"maxClassFieldsCount: 类数据成员的数量上限,超过则报出",
"maxUnionFieldsCount: 联合体数据成员的数量上限,超过则报出"
],
"tag": "type",
"reference": "CWE-1093"
},
"ID_plainNumericChar": {
"checkPoint": "参与数值运算的 char 对象应显式声明 signed 或 unsigned",
"level": "warning",
"comment": "char 类型是否有符号由实现定义,未显式声明 signed、unsigned 的 char 对象不应被当作整数使用。",
"tag": "expression",
"related": "ID_excessiveCharSign",
"standard": "ISO/IEC 9899:1999 6.2.5(3 15)-implementation,ISO/IEC 9899:2011 6.2.5(3 15)-implementation,ISO/IEC 14882:2003 3.9.1(1)-implementation,ISO/IEC 14882:2011 3.9.1(1)-implementation",
"reference": "MISRA C++ 2008 5-0-11,SEI CERT INT07-C"
},
"ID_plainBinaryChar": {
"checkPoint": "字节的类型应为 std::byte 或 unsigned char",
"level": "warning",
"comment": "字节等二进制概念不应受对齐方式或符号位的干扰,字节的类型应为 std::byte 或 unsigned char。",
"tag": "declaration",
"related": "ID_plainNumericChar,ID_bitwiseOperOnSigned",
"standard": "ISO/IEC 9899:1999 6.2.5(3 15)-implementation,ISO/IEC 9899:2011 6.2.5(3 15)-implementation,ISO/IEC 14882:2003 3.9.1(1)-implementation,ISO/IEC 14882:2011 3.9.1(1)-implementation,ISO/IEC 14882:2017 21.2.1,ISO/IEC 14882:2017 21.2.5"
},
"ID_uselessQualifier": {
"checkPoint": "声明枚举类型的底层类型时不应使用 const 或 volatile",
"level": "warning",
"comment": "在 C++ 语言中,将 enum 或 enum class 的底层类型(underlying type)设为 const 或 volatile 是没有意义的,会被编译器忽略。",
"tag": "declaration",
"standard": "ISO/IEC 14882:2011 7.2(2),ISO/IEC 14882:2011 10.2(2)"
},
"ID_duplicateEnumerator": {
"checkPoint": "同类枚举项的值不应相同",
"level": "warning",
"comment": "枚举项用于标记不同的事物,在同一枚举类型中,名称不同但值相同的枚举项往往意味着错误。",
"tag": "type",
"reference": "C++ Core Guidelines Enum.8,MISRA C 2012 8.12"
},
"ID_casualInitialization": {
"checkPoint": "合理初始化各枚举项",
"level": "suggestion",
"comment": "合理初始化各枚举项。",
"tag": "type",
"related": "ID_duplicateEnumerator",
"reference": "MISRA C 2004 9.3,MISRA C++ 2008 8-5-3,SEI CERT INT09-C"
},
"ID_forbidUnscopedEnum": {
"checkPoint": "用 enum class 取代 enum",
"level": "suggestion",
"comment": "enum 受到的限制较为宽松,易造成混淆或冲突等问题,在 C++ 代码中应改用 enum class。",
"tag": "type",
"standard": "ISO/IEC 14882:2011 7.2(2),ISO/IEC 14882:2017 10.2(2)",
"reference": "C++ Core Guidelines Enum.3"
},
"ID_forbidUnnamedEnum": {
"checkPoint": "不应使用匿名枚举声明",
"level": "suggestion",
"comment": "匿名枚举声明相当于在当前作用域定义常量,但类型不够明确。",
"tag": "type",
"reference": "C++ Core Guidelines Enum.6"
},
"ID_forbidNonBasicField": {
"checkPoint": "联合体内禁用非基本类型的对象",
"level": "warning",
"comment": "因为联合体成员之间共享内存地址,所以成员具有构造或析构函数时会导致混乱。",
"tag": "type",
"standard": "ISO/IEC 14882:1998 9.5(1),ISO/IEC 14882:2003 9.5(1),ISO/IEC 14882:2011 9.5(2 3 4)"
},
"ID_forbidNakedUnion": {
"checkPoint": "禁用在类之外定义的联合体",
"level": "suggestion",
"comment": "联合体各成员共享存储地址,易引发意料之外的错误。如果一定要使用联合体,需对其进行一定的封装,避免对成员的错误访问。",
"tag": "type",
"related": "ID_forbidUnion",
"reference": "C++ Core Guidelines C.181,MISRA C 2004 18.4,MISRA C 2012 19.2,MISRA C++ 2008 9-5-1"
},
"ID_forbidUnion": {
"checkPoint": "禁用联合体",
"level": "suggestion",
"comment": "联合体各成员共享存储地址,是一种对类型理念的破坏。",
"tag": "type",
"related": "ID_forbidNakedUnion",
"reference": "MISRA C 2004 18.4,MISRA C 2012 19.2,MISRA C++ 2008 9-5-1"
},
"ID_deprecatedDefaultArgument": {
"checkPoint": "不建议虚函数的参数有默认值",
"level": "suggestion",
"comment": "虚函数参数的默认值不受多态规则控制,通过基类指针或引用调用派生类重写的虚函数时,默认值仍采用基类中的定义,易造成混淆,故不建议虚函数的参数有默认值。",
"tag": "declaration",
"related": "ID_inconsistentDefaultArgument",
"standard": "ISO/IEC 14882:2003 8.3.6(10),ISO/IEC 14882:2011 8.3.6(10),ISO/IEC 14882:2017 11.3.6(10)",
"reference": "CWE-628,C++ Core Guidelines C.140,MISRA C++ 2008 8-3-1"
},
"ID_inconsistentDefaultArgument": {
"checkPoint": "虚函数参数的默认值应与基类中声明的一致",
"level": "error",
"comment": "虚函数参数的默认值不受多态规则控制,通过基类指针或引用调用派生类重写的虚函数时,默认值仍采用基类中的定义。",
"tag": "declaration",
"related": "ID_deprecatedDefaultArgument",
"standard": "ISO/IEC 14882:2003 8.3.6(10),ISO/IEC 14882:2011 8.3.6(10),ISO/IEC 14882:2017 11.3.6(10)",
"reference": "CWE-628,C++ Core Guidelines C.140,MISRA C++ 2008 8-3-1"
},
"ID_complexDeclaration": {
"checkPoint": "不应采用复杂的声明",
"level": "suggestion",
"comment": "复杂的声明可读性较差,容易造成理解上的偏差。",
"tag": "declaration"
},
"ID_tooManyPtrLevel": {
"checkPoint": "声明中不应包含过多的指针嵌套",
"level": "suggestion",
"comment": "指针嵌套层级过多意味着指针的解引用逻辑过于复杂,相关代码将难以理解,指针嵌套不宜超过 2 级。",
"config": [
"maxPtrLevel: 指针嵌套的最大层数,超过则报出"
],
"tag": "declaration",
"related": "ID_complexDeclaration",
"reference": "MISRA C 2004 17.5,MISRA C 2012 18.5"
},
"ID_staticNotUsed": {
"checkPoint": "不应存在没有被用到的静态声明",
"level": "warning",
"comment": "没有被用到的静态声明往往是没有意义的,应删除或修正引用关系。",
"tag": "declaration",
"related": "ID_unreachableCode",
"reference": "MISRA C++ 2008 0-1-10"
},
"ID_privateNotUsed": {
"checkPoint": "不应存在没有被用到的 private 成员",
"level": "warning",
"comment": "没有被用到的 private 成员是没有意义的,应删除或修正引用关系。",
"tag": "declaration",
"related": "ID_unreachableCode",
"reference": "MISRA C++ 2008 0-1-10"
},
"ID_missingParamName": {
"checkPoint": "函数原型声明中的参数应具有合理的名称",
"level": "suggestion",
"comment": "参数的名称是其用途的直接说明,合理的名称可显著提高可读性。",
"tag": "declaration",
"reference": "MISRA C 2004 16.3,MISRA C 2012 8.2"
},
"ID_obsoleteStdFunction": {
"checkPoint": "避免使用已过时的标准库组件",
"level": "warning",
"comment": "已过时的标准库组件会被语言标准弃用,应改用更完善的替代方法。",
"tag": "declaration",
"related": "ID_obsoleteFunction",
"standard": "ISO/IEC 14882:2011 D.6-deprecated,ISO/IEC 14882:2011 D.7-deprecated,ISO/IEC 14882:2011 D.8-deprecated,ISO/IEC 14882:2011 D.9-deprecated,ISO/IEC 14882:2011 D.10-deprecated,ISO/IEC 14882:2011 D.11-deprecated,ISO/IEC 14882:2017 20.5.4.3.1(1)"
},
"ID_mixedDeclarations": {
"checkPoint": "不应将不同类别的声明写在一个语句中",
"level": "suggestion",
"comment": "将对象、指针、引用、数组、函数等不同类别的声明写入一个语句可读性较差,易引起误解。",
"tag": "declaration",
"related": "ID_tooManyDeclarators",
"reference": "C++ Core Guidelines ES.10"
},
"ID_mixedTypeObjDefinition": {
"checkPoint": "不应将类型定义和对象声明写在一个语句中",
"level": "suggestion",
"comment": "将类型定义和对象声明写在一个语句中可读性较差,应分开书写。",
"tag": "declaration",
"reference": "C++ Core Guidelines C.7"
},
"ID_tooManyDeclarators": {
"checkPoint": "在一个语句中不应声明多个对象或函数",
"level": "suggestion",
"comment": "在一个语句中声明多个对象或函数不利于阅读和维护,建议在一个语句中只声明一个对象或函数。",
"config": [
"maxLocalDeclaratorCount: 局部作用域中一个语句能声明的对象个数上限,超过则报出",
"maxMemberDeclaratorCount: 类或结构体中一个语句能声明的对象个数上限,超过则报出",
"maxGlobalDeclaratorCount: 全局及命名空间作用域中一个语句能声明的对象个数上限,超过则报出",
"simpleDeclaratorLengthThreshold: 声明字符数量阈值,超过此值则判其应在单独的语句中声明"
],
"tag": "declaration",
"related": "ID_mixedDeclarations",
"reference": "C++ Core Guidelines ES.10,MISRA C++ 2008 8-0-1"
},
"ID_sandwichedModifier": {
"checkPoint": "const、volatile 等关键字不应出现在基本类型名称的中间",
"level": "warning",
"comment": "某些基本类型名称可由多个符号组成,const、volatile 等关键字不应出现在类型名称的中间,否则可读性较差。",
"tag": "declaration",
"standard":"ISO/IEC 9899:1999 6.7(1),ISO/IEC 9899:1999 6.7.2(1),ISO/IEC 9899:2011 6.7(1),ISO/IEC 9899:2011 6.7.2(1),ISO/IEC 14882:2003 A.6,ISO/IEC 14882:2011 A.6",
"related": "ID_badQualifierPosition,ID_badSpecifierPosition",
"reference": "C++ Core Guidelines NL.26"
},
"ID_badQualifierPosition": {
"checkPoint": "const、volatile 限定类型时的位置应统一",
"level": "suggestion",
"comment": "语言允许 const、volatile 等关键字出现在类型名称的左侧,也可以出现在其右侧,甚至可以出现在基本类型名称的中间,应对其位置进行统一规范以提高可读性。",
"tag": "declaration",
"config": [
"positionScheme: const、volatile 的位置方案,对应说明中的 1、2、3 号方案",
"volatileInFront: volatile 是否应写在 const 的前面,如果值为 false 则应写在后面,不设此项则不考虑相关顺序"
],
"standard":"ISO/IEC 9899:1999 6.7(1),ISO/IEC 9899:1999 6.7.2(1),ISO/IEC 9899:2011 6.7(1),ISO/IEC 9899:2011 6.7.2(1),ISO/IEC 14882:2003 A.6,ISO/IEC 14882:2011 A.6",
"related": "ID_sandwichedModifier,ID_badSpecifierPosition",
"reference": "C++ Core Guidelines NL.26"
},
"ID_badSpecifierPosition": {
"checkPoint": "inline、virtual、static、typedef 等关键字的位置应统一",
"level": "suggestion",
"comment": "语言允许 inline、virtual、static、typedef 等关键字出现在类型名称的左侧,也可以出现在其右侧,甚至可以出现在基本类型名称的中间,应对其位置进行统一规范以提高可读性。",
"tag": "declaration",
"standard":"ISO/IEC 9899:1999 6.7(1),ISO/IEC 9899:1999 6.7.2(1),ISO/IEC 9899:2011 6.7(1),ISO/IEC 9899:2011 6.7.2(1),ISO/IEC 14882:2003 A.6,ISO/IEC 14882:2011 A.6",
"related": "ID_sandwichedModifier,ID_badQualifierPosition"
},
"ID_hideLocal": {
"checkPoint": "局部名称不应被覆盖",
"level": "warning",
"comment": "不应在嵌套的作用域中声明相同的名称,否则干扰阅读,极易引起误解。",
"tag": "declaration",
"reference": "CWE-1109,C++ Core Guidelines ES.12,MISRA C 2004 5.2,MISRA C 2012 5.3,MISRA C++ 2008 2-10-2"
},
"ID_hideMember": {
"checkPoint": "成员名称不应被覆盖",
"level": "warning",
"comment": "成员函数内的局部名称与成员名称相同会干扰阅读,易引起误解。",
"tag": "declaration",
"reference": "CWE-1109,MISRA C 2004 5.2,MISRA C 2012 5.3,MISRA C++ 2008 2-10-2"
},
"ID_hideGlobal": {
"checkPoint": "全局名称不应被覆盖",
"level": "warning",
"comment": "局部、成员名称不应与全局或命名空间内的名称相同,否则干扰阅读,易引起误解。",
"tag": "declaration",
"reference": "CWE-1109,MISRA C 2004 5.2,MISRA C 2012 5.3,MISRA C++ 2008 2-10-2"
},
"ID_constStrToNonConstPtr": {
"checkPoint": "指向常量字符串的指针应使用 const 声明",
"level": "warning",
"comment": "常量字符串与非常量字符串指针的隐式转换是不安全的,一旦相关内存被修改会导致标准未定义的行为,这种转换在 C++ 标准中是过时的,在 C 代码中也不应出现。",
"tag": "declaration",
"standard": "ISO/IEC 9899:1999 6.4.5(6)-undefined,ISO/IEC 9899:2011 6.4.5(7)-undefined,ISO/IEC 14882:1998 D.4(1)-deprecated,ISO/IEC 14882:2003 2.13.4(2)-undefined,ISO/IEC 14882:2003 D.4(1)-deprecated,ISO/IEC 14882:2011 2.14.5(12)-undefined,ISO/IEC 14882:2017 5.13.5(16)-undefined",
"related": "ID_nonConstUnmodified",
"reference": "MISRA C 2012 7.4,SEI CERT STR30-C"
},
"ID_virtualComparison": {
"checkPoint": "比较运算符不应为虚函数",
"level": "warning",
"comment": "重载的比较运算符很难正确触发 C++ 的多态机制,将其设为虚函数很可能引发意料之外的错误。",
"tag": "declaration",
"reference": "C++ Core Guidelines C.87"
},
"ID_virtualAssignment": {
"checkPoint": "拷贝和移动赋值运算符不应为虚函数",
"level": "warning",
"comment": "拷贝和移动赋值运算符的参数应分别为所属类的左值和右值引用,这类运算符即使是虚函数也不便于被重写。",
"tag": "declaration",
"related": "ID_nonStdAssignmentRetType",
"standard": "ISO/IEC 14882:2003 12.8(9),ISO/IEC 14882:2011 12.8(17),ISO/IEC 14882:2011 12.8(19)",
"reference": "C++ Core Guidelines C.60,C++ Core Guidelines C.63"
},
"ID_illCopyConstructorParam": {
"checkPoint": "拷贝构造函数的参数应为同类对象的 const 左值引用",
"level": "warning",
"comment": "如果构造函数的参数不是同类对象的左值引用,则不构成拷贝构造函数,拷贝构造函数不应具备复制之外的功能,故其参数不应被修改,应受 const 关键字限制。",
"tag": "declaration",
"related": "ID_sideEffectCopyConstructor,ID_nonStdCopyAssignmentParam,ID_nonConstUnmodified"
},
"ID_nonStdCopyAssignmentParam": {
"checkPoint": "拷贝赋值运算符的参数应为同类对象的 const 左值引用",
"level": "warning",
"comment": "拷贝赋值运算符应专注于复制参数的数据,且参数不应按值传递,否则会产生不必要的复制开销以及“对象切片”等问题。",
"tag": "declaration",
"standard": "ISO/IEC 14882:2003 12.8(9),ISO/IEC 14882:2011 12.8(17)",
"related": "ID_illCopyConstructorParam,ID_nonConstUnmodified",
"reference": "C++ Core Guidelines C.60"
},
"ID_illMoveConstructorParam": {
"checkPoint": "移动构造函数的参数应为同类对象的非 const 右值引用",
"level": "warning",
"comment": "移动构造意在将参数的数据转移到当前对象中,故参数应为右值引用,且不应受 const 关键字限制。",
"tag": "declaration",
"related": "ID_nonStdMoveAssignmentParam"
},
"ID_nonStdMoveAssignmentParam": {
"checkPoint": "移动赋值运算符的参数应为同类对象的非 const 右值引用",
"level": "warning",
"comment": "移动赋值意在将参数的数据转移到当前对象中,故参数应为右值引用,且不应受 const 关键字限制。",
"tag": "declaration",
"standard": "ISO/IEC 14882:2011 12.8(19),ISO/IEC 14882:2017 15.8.2(3)",
"reference": "C++ Core Guidelines C.63"
},
"ID_illOperatorRetType": {
"checkPoint": "重载运算符的返回类型应与内置运算符相符",
"level": "warning",
"comment": "为了便于调用者使用,并满足泛型编程的要求,重载运算符的返回类型应与内置运算符相符。",
"tag": "declaration",
"related": "ID_nonStdAssignmentRetType"
},
"ID_nonStdAssignmentRetType": {
"checkPoint": "赋值运算符应返回所属类的非 const 左值引用",
"level": "warning",
"comment": "赋值运算符应返回所属类不受 const 关键字限定的左值引用,以便调用者使用并满足泛型编程的要求。",
"tag": "declaration",
"related": "ID_illOperatorRetType",
"standard": "ISO/IEC 14882:2003 12.8(10),ISO/IEC 14882:2011 12.8(22)",
"reference": "C++ Core Guidelines F.47,C++ Core Guidelines C.60,C++ Core Guidelines C.63"
},
"ID_mainReturnsNonInt": {
"checkPoint": "main 函数的返回类型只应为 int",
"level": "warning",
"comment": "main 函数的返回值可作为整个进程执行情况的总结,按惯例返回 0 或 EXIT_SUCCESS 表示执行成功,非 0 或 EXIT_FAILURE 表示执行失败,main 函数的返回值会作为标准 exit 函数的参数。",
"tag": "function",
"standard": "ISO/IEC 9899:1999 5.1.2.2.1(1)-implementation,ISO/IEC 9899:1999 5.1.2.2.3(1)-unspecified,ISO/IEC 9899:2011 5.1.2.2.1(1)-implementation,ISO/IEC 9899:2011 5.1.2.2.3(1)-unspecified,ISO/IEC 14882:2003 3.6.1(2)-implementation,ISO/IEC 14882:2011 3.6.1(2)-implementation",
"reference": "C++ Core Guidelines F.46"
},
"ID_missingNamespace": {
"checkPoint": "为代码设定合理的命名空间",
"level": "warning",
"comment": "命名空间是 C++ 项目的必要组成结构,可有效规避名称冲突等问题。",
"tag": "global",
"related": "ID_usingNamespaceInHeader,ID_forbidUsingDirectives",
"reference": "MISRA C++ 2008 7-3-1"
},
"ID_nonGlobalMain": {
"checkPoint": "main 函数只应位于全局作用域中",
"level": "warning",
"comment": "main 函数作为程序的入口,链接器需对其特殊处理,不应受命名空间等作用域的限制。",
"tag": "global",
"standard": "ISO/IEC 14882:2003 3.6.1(1),ISO/IEC 14882:2011 3.6.1(1)",
"reference": "MISRA C++ 2008 7-3-2"
},
"ID_illFormedMain": {
"checkPoint": "main 函数不应被调用、重载或被 inline、static 等关键字限定",
"level": "warning",
"comment": "main 函数作为程序的入口是一种特殊的函数,其链接性由实现定义,不应被调用、重载或被任何函数限定符修饰。",
"tag": "function",
"standard": "ISO/IEC 9899:1999 6.7.4(4),ISO/IEC 9899:2011 6.7.4(4),ISO/IEC 14882:2003 3.6.1(2 3)-implementation,ISO/IEC 14882:2011 3.6.1(2 3)-implementation,ISO/IEC 14882:2017 6.6.1(2 3)-implementation"
},
"ID_constLiteralReference": {
"checkPoint": "对常量的定义不应为引用",
"level": "warning",
"comment": "虽然 C++ 语言十分灵活,可以通过多种方式达到同一种目的,但应该选择最简洁且通俗易懂的方式实现。",
"tag": "declaration"
},
"ID_forbidEnumBitfield": {
"checkPoint": "不应对枚举对象声明位域",
"level": "warning",
"comment": "枚举类型的底层整数类型以及是否存在符号位由实现定义,与位域结合易导致意料之外的错误。",
"tag": "declaration",
"related": "ID_improperBitfieldType,ID_singleSignedBitfield",
"standard": "ISO/IEC 9899:1999 6.7.2.2(4)-implementation,ISO/IEC 9899:2011 6.7.2.2(4)-implementation,ISO/IEC 14882:2011 7.2(6)-implementation,ISO/IEC 14882:2017 10.2(7)-implementation",
"reference": "MISRA C++ 2008 9-6-3"
},
"ID_forbidFlexibleArray": {
"checkPoint": "禁用柔性数组",
"level": "suggestion",
"comment": "柔性数组(flexible array)指结构体最后不完整定义的数组成员,表示不占用空间的指针,这种数组由 C99 标准提出,不在 C++ 标准之内,在 C++ 代码中不应使用。",
"tag": "declaration",
"standard": "ISO/IEC 9899:1999 6.7.2.1(16),ISO/IEC 9899:2011 6.7.2.1(18)",
"reference": "MISRA C 2012 18.7"
},
"ID_improperBitfieldType": {
"checkPoint": "对位域声明合理的类型",
"level": "warning",
"comment": "为了提高可移植性和可维护性,应对位域声明合理的类型。",
"config": [
"bitfieldMustBeUnsigned: 位域类型是否必须为无符号整型",
"bitfieldMustBeStdInt: 位域类型是否必须为 stdint.h 或 cstdint 中定义的类型"
],