MISRAC2012-Dir-4.7_c
In this section:
Synopsis
(Required) If a function returns error information, then that error information shall be tested.
Enabled by default
Yes
Severity/Certainty
Low/Medium

Full description
Returned error information should be tested.
Coding standards
- CWE 252
Unchecked Return Value
- MISRA C:2012 Dir-4.7
(Required) If a function returns error information, then that error information shall be tested
Code examples
The following code example fails the check and will give a warning:
#include<errno.h>
#include<stdio.h>
void no_test() {
FILE * f;
fpos_t * p;
int x = fgetpos(f, p);
}
void test_after_overwritten() {
FILE * f;
fpos_t * p;
int x = fgetpos(f, p);
int y = fgetpos(f, p);
switch(errno) {
case 1:
/* ... */
break;
}
}
The following code example passes the check and will not give a warning about this issue:
#include<errno.h>
#include<stdio.h>
void test() {
FILE * f;
fpos_t * p;
int x = fgetpos(f, p);
switch(errno) {
case 1:
/* ... */
break;
}
}
void test_again() {
FILE * f;
fpos_t * p;
int x = fgetpos(f, p);
switch(errno) {
case 1:
/* ... */
break;
}
x = fgetpos(f, p);
switch(errno) {
case 1:
/* ... */
break;
}
}