MISRAC2012-Dir-4.14_g
In this section:
Synopsis
(Required) The validity of values received from external sources shall be checked.
Enabled by default
Yes
Severity/Certainty
Medium/Medium

Full description
User input is used as a divisor without validation.
Coding standards
- MISRA C:2012 Dir-4.14
(Required) The validity of values received from external sources shall be checked
Code examples
The following code example fails the check and will give a warning:
int main(int argc, char **argv) {
return 10 / argc;
}
The following code example passes the check and will not give a warning about this issue:
int main(int argc, char **argv) {
if (argc > 0 && argc < 10)
return 10 / argc;
else
return 1;
}