Rule Definition
These functions have undefined behavior associated with them when the string cannot be converted.
Remediation
Use one of the C Standard Library strto*() functions to parse an integer or floating-point number from a string. These functions provide more robust error handling than alternative solutions.
Violation Code Sample
if (buff) {
si = atoi(buff); //Non-compliant
} else {
/* Handle error */
}
Reference
MISRA C 2012, 21.7: The atof, atoi, atol and atoll functions of shall not be used
Related Technologies
Technical Criterion
CWE-758 - Reliance on Undefined, Unspecified, or Implementation-Defined Behavior
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.