2.1. function
68. The function of the function should be within the range of the file (R)
void myfunc(void) {
extern int call(void); /* Violation of rules68 */
}
69. Functions cannot use the style of variable parameter format (R)
also means that the format of the function parameter should be fixed. This is targetedCLanguage supports variable parameters functions. For example:
extern int myfunc(int *a, …); /* and rules69conflict*/
70. The function does not allow direct or indirect calling yourself (R)
This regulation is prohibited from the use of recursive functions in security -related software, mainly because recursive recursion will cause the overflow of stack space.
71. The function should have a function prototype declaration.R)
It should have obvious statements before the function call, especially for functions for cross -file.
72. The parameters passed to the function should be consistent with the corresponding parameter of the function, and the return value should be consistent (R)
73. In the prototype statement of the function, either all functional parameter names are given, or they are free (R)
For example:
extern int myfunc(int a, int); /* conflict with the rules73 */
74. If the parameter name of the function is given, then in the function and definition of the function, the identifier should be consistent (R)
75. Each function should have an explicit return type (R)
If no data is returned, it will be returnedvoidtype type.
twenty three# . Functions without a parameter declaration should be used where the parameters declare parameters
76voidType (R)
For example, a function declaration method without returning data and no parameters is given below.
void myfunc(void);
77. The parameters of the infinite type passed to the function should be compatible with the unlimited type defined in the function prototype (R)
78. The number of function parameters should be matched with the number in the function prototype (R)
79. Depend onvoidThe value returned by the function cannot be used (R)
void myVoid();
int myReturn();
void myFunc() {
int a = 0, b = 0;
a = myVoid(); /* conflict with the rules */
myVoid(); /* OK */
b = myReturn(); /* OK */
}
80.voidexpression cannot be passed to the function as a parameter (R)
void foo();
void moo1(int);
void moo2(int,int);
int goo();
void bar () {
void *p;
int a=0;
moo1(a); /* OK */
moo1(foo()); /* conflict with the rules */
moo2(a,foo()); /* conflict with the rules */
moo2(a,a); /* OK */
moo1(*p); /* conflict with the rules */
moo1((void)goo()); /* conflict with the rules */
}
81. When the function cannot modify the variable,constRestrictions should be used to declare parameters of the function (A)
82. One function should have a singleexitpoint (A) In other words, the function should have at the end of the function
Pointexit.
int foo1(int a) {
/* and rules82Conflict */
if (a>0) {
return 1;
} else {
return 0;
}
}
int foo2(int a) {
// Ok
int l;
if (a>0) {
l=1;
} else {
l=0;
}
return l;
}
83. Isn’t it returningvoidType function: (R)
i. For each oneexitbranch (including the end of the program), should have onereturnstatement;
ii. every onereturnhave a expression;
The expression of
iii. returnshould be matched with the return type.
84. Returnvoidtype function,returnstatement should not include expression (R)
For example:
void myfunc(void) {
return 0; /* and rules84Conflict */
}
85. The function that calls the no parameter should have a vacuum bracket (A)
For example:
int myfunc(void) {
return 0;
}
int main(int argc, char *argvs[])
{
int a = 0;
a = myfunc; /* and rules85conflict */
}
86. If the function returns the error message, the error information should be checked (A)
int foo1();
void foo2();
int foo3();
void moo() {
int i;
i=foo1(); /* OK */
foo1(); /* conflict with the rules*/
(void)foo1(); /* OK */
foo2(); /* OK */
if (foo1()!=0) {} /* OK */
if (1) {
foo1(); /*conflict with the rules*/
}
if (foo1()) {
foo3(); /*conflict with the rules*/
}
}