Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

45 lines
1.1 KiB
Plaintext

== Why is this an issue?
``++<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
[source,cpp]
----
int converter (const char * numstr) {
return atoi(numstr); // Noncompliant
}
----
=== Compliant solution
[source,cpp]
----
int converter (const char * numstr) {
return strtol(numstr, NULL, 10);
}
----
== Resources
* MISRA C:2004, 20.10 - The library functions atof, atoi and atol from library <stdlib.h> shall not be used.
* MISRA {cpp}:2008, 18-0-2 - The library functions atof, atoi and atol from library <cstdlib> shall not be used.
* MISRA C:2012, 21.7 - The atof, atoi, atol and atoll functions of <stdlib.h> shall not be used
* https://wiki.sei.cmu.edu/confluence/x/C9cxBQ[CERT, ERR34-C.] - Detect errors when converting a string to a number
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Remove this use of "xxx".
endif::env-github,rspecator-view[]