C++: Include malloc example in qlhelp

This commit is contained in:
Mathias Vorreiter Pedersen
2020-01-20 13:28:00 +01:00
parent a43131a987
commit 13fc8741d4
2 changed files with 12 additions and 6 deletions

View File

@@ -1,3 +1,8 @@
void calls() {
undeclared_function(1, 2);
}
/* '#include <stdlib.h>' was forgotton */
int main(void) {
/* 'int malloc()' assumed */
unsigned char *p = malloc(100);
*p = 'a';
return 0;
}

View File

@@ -8,14 +8,15 @@
<p>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.
</p>
If the implicit declaration does not match the true signature of the function, the
function may behave unpredictably.</p>
<p>This may indicate a misspelled function name, or that the required header containing
the function declaration has not been included.</p>
</overview>
<recommendation>
<p>Ensure that the called function has been declared previously in the file or an included header file.</p>
<p>Provide an explicit declaration of the function before invoking it.</p>
</recommendation>
<example><sample src="ImplicitFunctionDeclaration.c" />
@@ -25,4 +26,4 @@ the function declaration has not been included.</p>
<references>
<li>SEI CERT C Coding Standard: <a href="https://wiki.sei.cmu.edu/confluence/display/c/DCL31-C.+Declare+identifiers+before+using+them">DCL31-C. Declare identifiers before using them</a></li>
</references>
</qhelp>
</qhelp>