← 返回首页
Implicit function declaration — CodeQL query help documentation CodeQL docs
CodeQL documentation
CodeQL resources

Implicit function declaration

ID: cpp/implicit-function-declaration Kind: problem Security severity: Severity: warning Precision: high Tags: - correctness - maintainability Query suites: - 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