Rule Definition
Variadic functions are functions that accept a variable number of arguments, such as 'printf()' and 'format()'. They are declared with an ellipsis ('...'):
Ex: int printf ( const char * format, ... );
These functions can be only used with scalar data types C-style structs. Using them with other data types will lead to unexpected behavior.
Remediation
Review the parameters used to call these functions and try to replace them with native types. One alternative is to use non variadic functions that can allow for more data types.
Violation Code Sample
void showError(std::string const &errorMsg)
{
printf("Error: %s", errorMsg);
}
Fixed Code Sample
You can correct this code by accessing a 0-terminated 'char*' from the string:
void showError(std::string const &errorMsg)
{
printf("Error: %s", errorMsg.c_str());
}
Or by using another display function:
void showError(std::string const &errorMsg)
{
cout << "Error: " << errorMsg;
}
Related Technologies
C++
Technical Criterion
CWE-1120 - Excessive Code Complexity [Class]
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.