Implicit function declaration -- CodeQL query help documentation CodeQL docs
Implicit function declaration
ID: cpp/implicit-function-declaration Kind: problem Security severity: Severity: warning Precision: high Tags: - quality - reliability - correctness Query suites: - cpp-code-quality.qls - cpp-security-and-quality.qls
Click to see the query in the CodeQL repository
A function is called without a prior function declaration or definition. When this happens, the compiler generates an implicit declaration of the function, specifying an integer return type and no parameters. If the implicit declaration does not match the true signature of the function, the function may behave unpredictably.
This may indicate a misspelled function name, or that the required header containing the function declaration has not been included.
Note: This query is not compatible with build-mode: none databases, and produces no results on those databases.
Recommendation
Provide an explicit declaration of the function before invoking it.
Example
/* '#include <stdlib.h>' was forgotten */
int main(void) {
/* 'int malloc()' assumed */
unsigned char *p = malloc(100);
*p = 'a';
return 0;
}
References
SEI CERT C Coding Standard: DCL31-C. Declare identifiers before using them