CodeQL documentation

Call to function with extraneous arguments

ID: cpp/futile-params
Kind: problem
Severity: warning
Precision: very-high
Tags:
   - correctness
   - maintainability
Query suites:
   - cpp-security-and-quality.qls

Click to see the query in the CodeQL repository

A function is called with more arguments than there are parameters of the function.

This may indicate that an incorrect function is being called, or that the signature (parameter list) of the called function is not known to the author.

In C, function calls generally need to provide the same number of arguments as there are arguments to the function. (Variadic functions can accept additional arguments.) Providing more arguments than there are parameters incurs an unneeded computational overhead, both in terms of time and of additional stack space.

Recommendation

Call the function with the correct number of arguments.

Example

void one_argument();

void calls() {
	
	one_argument(1); // GOOD: `one_argument` will accept and use the argument
	
	one_argument(1, 2); // BAD: `one_argument` will use the first argument but ignore the second
}

void one_argument(int x);