调用函数时存在多余的参数¶
ID: cpp/futile-params
Kind: problem
Security severity:
Severity: warning
Precision: very-high
Tags:
- correctness
- maintainability
Query suites:
- cpp-security-and-quality.qls
函数调用时提供的参数数量多于函数参数的数量。
这可能表明调用了错误的函数,或者调用函数的签名(参数列表)对作者来说是未知的。
在 C 语言中,函数调用通常需要提供与函数参数数量相同的参数。 (可变参数函数可以接受额外的参数。)提供比参数数量更多的参数会造成不必要的计算开销,包括时间开销和额外的堆栈空间。
建议¶
使用正确数量的参数调用函数。
示例¶
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);