There are required pieces to formulate my problem.
Below are content of MyError.h
header file.
myError.h
###########################
# myError.h
###########################
1 typedef enum
2 {
3 MySuccess = 0x00000000,
4 MyError1 = 0x00000001,
5 MyError2 = 0x00000003,
6 MyForce32 = 0x7FFFFFFF
7 } MyError;
8 #define PROPAGATE_ERROR_FAIL_MY_1(_err) \
9 do { \
10 e = (_err); \
11 if (e != MySuccess) \
12 { \
13 MY_UTILS_LOG_ERROR(e, __FILE__, __FUNCTION__, __LINE__, true, 0); \
14 goto fail; \
15 } \
16 } while (0)
17 #define MY_UTILS_LOG_ERROR(_err, _file, _func, _line, _propagating, _format, ...) \
18 do { \
19 MyUtilsLogError(MY_UTILS_ERROR_TAG, MY_UTILS_ERROR_PATH, \
20 (_err), (_file), (_func), (_line), \
21 (_propagating), (_format), ##__VA_ARGS__); \
22 } \
23 while (0)
24 void MyUtilsLogError(const char* tag, const char* path, MyError e, const char* file, const char* func,
uint32_t line, bool propagating, const char* format, ...)
//Here MyError is passed just to print the String for Error for example if we pass MyError1 then string MyError1 will be printed in logs on console.
Below are required pieces from MyError.c
file, which simply include above header file and calls the PROPAGATE_ERROR_FAIL_MY_1
macro in APIs.
myError.c
#include "myerror.h"
static MyError foo(uint32_t x, uint32_t y) {
if (x==y) {
return MySuccess;
} else {
return MyError1;
}
}
static MyError fooCaller(void) {
MyError e = MySuccess;
uint32_t x = 1U, y = 1U;
PROPAGATE_ERROR_FAIL_MY_1(foo(x,y)); //This is where I get all kind of weird MISRA violation [1][2].
fail:
return e;
}
NOTE: FYI MyUtilsLogError() is just a API which helps in dumping the logs on console.
In myError.c
file I see below MISRA 2012 violations:
[1]: misra_c_2012_rule_10_4_violation: Essential type of the left hand operand "e" (enum) is not the same as that of the right operand "MySuccess"(boolean).
[2]: misra_c_2012_rule_11_9_violation: Literal "0" shall not be used as null pointer constant.
I'm not getting why MISRA is reporting 10.4 violation even though I'm comparing the same enum type at line#11 in myErro.h
file ?
Any clue why 10.9 violation is being reported here ? Is macro not good to use for MISRA ?