"If too few arguments are sent to a function , the function is implicitly declared, and it is not given enough arguments it will still pop the expected number of arguments from the stack. Potentially, a variable number of arguments could be exhausted in a function as well."-http://cwe.mitre.org/. This could cause the program to crash.
The function could also be given too many arguments can cause a buffer overflow.
Non compliant code
Code Block |
---|
|
function(1, 2);
...
void function(int one, int two, int three){
printf("args %d %d $d, one, two, three);
}
|
solution: "Implementation: Forward declare all functions. This is the recommended solution. Properly forward declaration of all used functions will result in a compiler error if too few arguments are sent to a function." -http://cwe.mitre.org/Use function prototypes at the top of .c file or in a .h file so that a compiler error will occur if an incorrect number of arguments are used.
Compliant code
Code Block |
---|
|
void function(int one, int two, int three); //at top of file or in .h file
...
function(1,2) //compiler error
|
...