C ++ Code Review level standard
0 preface the record problems are all from common or basic defects in the Normal C ++ coding process.
It is just a standard compiled by an individual. It is used for "mine clearance" in normal code writing and is not authoritative. It is now applied to my development team.
The subsequent Supplementary improvement is still a long process.
Programmers must be good at recording and summarizing so that they can grow and improve.
1 Introduction code review definition: Check the quality assurance process of code defects by reading the code.
Code review content: programming specifications, reconstruction methods, architecture design, performance security, logs, readability, and scalability...
Benefits of code review: early identification of coding defects, analysis of coding defects, improvement of code quality, improvement of coding level, and promotion of team cooperation...
Code Review Form: code reading, code explanation, Pair programming, cross-review, expert review, and review meeting (only identifying problems, not discussing and solving problems at the meeting )...
The level 2 standard is generally divided into three levels:
Severe: system crashes, program crashes, and functions become unavailable, leading to serious consequences.
GENERAL: it may cause some problems of function unavailability, design defects, and running efficiency.
Tip: this may cause poor code readability and violation of programming specifications.
3. Severity Level and problem Example 1)
Problem type: NULL pointer
Example:
CTestClass * p = NULL;
P-> GetName (); // operation NULL pointer 2)
Problem type: Invalid Pointer
Example:
Char * p = new char [100];
Delete p;
Memcpy (p, "hello"); // The operation is invalid. 3)
Problem type: the pointer is not null.
Example:
If (NULL = P); // the pointer must be NULL. 4)
Problem type: Wild pointer
Example:
New and delete should appear in pairs.
Malloc and free should appear in pairs
5)
Problem type: endless loop
Example:
While (...)
{
I ++; // I ++ ensures no endless Loops
}; 6)
Problem type: logical error
Example:
Code logic disorder or correlation 7)
Problem type: resource leakage
Example:
CDialog: Create must have CWnd: DestroyWindow to release
CreateIcon and GetIcon must have DestroyIcon to release
CBitmap LoadImage must have DeleteObject to release 8)
Problem type: array out-of-bounds
Example:
Char szArray [MAX];
Printf ("% c", szArray [MAX]); // array out-of-bounds
9)
Problem type: loop body rewriting Loop Variable
Example:
For (int I = 0; I <MAX; I ++)
{
I = 100; // The loop variable is rewritten in the loop body.
} 10)
Problem type: IO operations and database operation resources are not released
Example:
The open operation must be closed. The open () and close () operations should appear in pairs.
11)
Problem type: Determine whether the number of unsigned characters is smaller than 0
Example:
UInt iLen = MAX;
If (iLen <0) // determines whether the number of unsigned characters is smaller than 0
{
...
} 12)
Problem type: memory copy ignores the ending sign '\ 0'
Example:
Char * s = "aaaa ";
Char a [4];
Memcpy (a, s, 4); // The memory copy ignores the ending sign '\ 0'
13)
Problem type: Modify the parameter inside the Function
Example:
String GetName (int iID)
{
IID = 100; // modify the parameter inside the Function
...
} 14)
Problem type: new array, delete without []
Example:
Char * a = new char [100];
...
Delete a; // new array, delete without []
15)
Problem type: duplicate names of local variables and local variables, function parameters, and global variables
16)
Problem type: the object cannot be initialized using memset.
17)
Problem type: multi-threaded resources are not mutually exclusive
18)
Problem type: the complexity of the Code circle cannot exceed 14
19)
Problem type: Function Code nesting level cannot exceed 6
20)
Problem type: the debugging or log information cannot contain sensitive information. 4. General level and Example 1)
Problem type: the variable is not initialized.
Example:
Char * a; // The variable is not initialized.
Char B [100];
Strcpy (B, );
2)
Problem type: the function input parameter is not verified.
Example:
Void FunTest (CTestClass * p)
{
P-> Get (); // The function input parameter is not verified.
}
3)
Problem type: Boolean value and non-Boolean Value Comparison
Example:
Int I = 0;
Bool flag = true;
If (I = flag) // compare boolean values with non-boolean values
{
...
}
4)
Problem type: Floating Point and 0
Example:
Double dwLen = 0.1;
If (0 = dwLen) // compare floating point with 0
{
...
} 5)
Problem type: Forced comparison or assignment of different data types
Example:
Long lmax= 32768;
Short iLen = 0;
ILen = lMax; // mandatory value assignment for different data types
6)
Problem type: complex expressions without parentheses indicate priority
Example:
If (I = j & I = k | I = l | j = k) // a complex expression uses no brackets to indicate the priority.
{
...
}
7)
Problem type: the function does not return a value or the return value is incorrect.
Example:
Bool Fun ()
{
Int I = 0;
...
Return I; // the return value of the function is incorrect.
}
8)
Problem type: Incorrect pointer judgment
Example:
Bool Fun (char * p)
{
If (p) // Pointer Error
} 9)
Problem type: the variables should be compared to = on the left.
Example:
If (p = NULL) // The variable comparison should be placed on the left 10)
Problem type: repeated code
Example:
Duplicate codes should be extracted or encapsulated, and repeated codes should be added with comments on the rationality of repeated codes. 5. Prompt levels and problem examples
1)
Problem type: Devil's number
Example:
For (int I = 0; I <1000; I ++) // devil's number
{
...
} 2)
Problem type: Incorrect comment
Example:
Incorrect comments with typos or semantic expressions 3)
Problem type: Invalid Comment
Example:
Comments must be reasonable, not redundant, not nonsense 4)
Problem type: no comments or too low comments
Example:
Normal comments should be greater than 30%. 5)
Problem type: Messy layout or indentation
Example:
Empty rows and indentation must be normalized (4 spaces instead of tab) 6)
Problem type: redundant code
Example:
Useless comments or useless code 7)
Problem type: maintenance code not described
Example:
Note the maintenance code
8)
Problem type: if, for, while, switch and other statements should be added {}
Example:
Switch (I)
Case 1:
... // Add {}
Break;
Case 2:
...
Break;
9)
Problem type: the total number of files cannot exceed 2000
10)
Problem type: the total number of function lines cannot exceed 200
11)
Problem type: function parameters cannot exceed 5
12)
Problem type: the name does not comply with programming specifications