CodeQL documentation

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.

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

  • © GitHub, Inc.
  • Terms
  • Privacy