<stdlib.h>
's atof
, atoi
, and atol
functions, which convert strings to numbers, have
undefined behavior when the strings cannot be converted, and should therefore be avoided.
Noncompliant code example
int converter (const char * numstr) {
return atoi(numstr); // Noncompliant
}
Compliant solution
int converter (const char * numstr) {
return strtol(numstr, NULL, 10);
}