Standard function call with incorrect arguments
Argument to a standard function does not meet requirements for use in the function
Description
This defect occurs when the arguments to certain standard functions do not meet the requirements for their use in the functions.
For instance, the arguments to these functions can be invalid in the following ways.
| Function Type | Situation | Risk | Fix |
|---|---|---|---|
String manipulation functions such as strlen and strcpy | The pointer arguments do not point to a NULL-terminated string. | The behavior of the function is undefined. | Pass a NULL-terminated string to string manipulation functions. |
File handling functions in stdio.h such as fputc and fread | The FILE* pointer argument can have the value NULL. | The behavior of the function is undefined. | Test the FILE* pointer for NULL before using it as function argument. |
File handling functions in unistd.h such as lseek and read | The file descriptor argument can be -1. | The behavior of the function is undefined. Most implementations of the | Test the return value of the If the return value is -1, check the value of |
| The file descriptor argument represents a closed file descriptor. | The behavior of the function is undefined. | Close the file descriptor only after you have completely finished using it. Alternatively, reopen the file descriptor before using it as function argument. | |
Directory name generation functions such as mkdtemp and mkstemps | The last six characters of the string template are not XXXXXX. | The function replaces the last six characters with a string that makes the file name unique. If the last six characters are not XXXXXX, the function cannot generate a unique enough directory name. | Test if the last six characters of a string are XXXXXX before using the string as function argument. |
Functions related to environment variables such as getenv and setenv | The string argument is "". | The behavior is implementation-defined. | Test the string argument for "" before using it as getenv or setenv argument. |
The string argument terminates with an equal sign, =. For instance, "C=" instead of "C". | The behavior is implementation-defined. | Do not terminate the string argument with =. | |
String handling functions such as strtok and strstr |
| Some implementations do not handle these edge cases. | Test the string for "" before using it as function argument. |
Fix
The fix depends on the root cause of the defect. See fixes in the table above and code examples with fixes below.
If you do not want to fix the issue, add comments to your result or code to avoid another review. See:
Address Polyspace Results Through Bug Fixes or Justifications if you review results in the Polyspace user interface.
Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access) if you review results in a web browser.
Annotate Code and Hide Known or Acceptable Results if you review results in an IDE.
Examples
Result Information
| Group: Programming |
| Language: C | C++ |
| Default: On for handwritten code, off for generated code |
Command-Line Syntax:
STD_FUNC_ARG_MISMATCH
|
| Impact: Medium |
PQL Name:
std.defects.STD_FUNC_ARG_MISMATCH
|
Version History
Introduced in R2015b
See Also
Topics
- Interpret Polyspace Bug Finder Results in Polyspace Platform User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Address Polyspace Results Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)