19-09-2018, 05:30 PM
Hello,
I have the following piece of code for which I get a MISRA Rule 2.1 error. I am considering a deviation for this - All possible error status from a function call can be checked even if the function does not return all possible error statuses. Can you please provide feedback on if this is a reasonable deviation?
(Btw, this is my first post - please feel free to let me know if this is outside the scope here)
Example:
I have the following piece of code for which I get a MISRA Rule 2.1 error. I am considering a deviation for this - All possible error status from a function call can be checked even if the function does not return all possible error statuses. Can you please provide feedback on if this is a reasonable deviation?
(Btw, this is my first post - please feel free to let me know if this is outside the scope here)
Example:
Code:
#include "stdafx.h"
typedef enum ErrStatus {
Success = 0,
Err_1,
Err_2
} ErrStatus;
ErrStatus f(int x) {
if (x < 0) {
return Err_1;
}
else
{
return Success;
}
}
int main()
{
ErrStatus x = f(5);
switch (x)
{
case Err_1:
printf("err 1"); break;
case Err_2:
printf("err 2 "); break; /* Is this dead code ? */
default:
printf("Success"); break;
}
}
<t></t>