If anybody is interested. The workaround is to add -Dpthread_mutex_t=int to get around this issue. I cannot find a better way to get around this.
It seems to me anysizeof(typedef_of_a_struct_t)always fails in macro expansions. i.e.
#MY_MACRO sizeof(typedef_of_a_struct_t)
will always result in error: Variable 'typedef_of_a_struct_t' is unknown [misra-config]
The cppcheck with misra addon seems to make these errors more and more troublesome in which they needs to be bypassed. In my view, this is creating vulnerabilities by bypassing these errors as code structure might/probably change in future. I have same issues in other cases where my own declared structures are showing the same errors.
Anyone shares my concern?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
A code example that reproduce the misra-config would be nice. It's not reported below however I did expect such warning.
daniel@dator:~/cppchecksolutions/addon$catm1.c//typedefintpthread_mutex_t;#defineQ_HDR_INT_SZ4#defineQ_HDR_SZ(sizeof(pthread_mutex_t)+Q_HDR_INT_SZ)uint32_tfoo(void){returnQ_HDR_SZ;}daniel@dator:~/cppchecksolutions/addon$../cppcheck/cppcheck--addon=misra --enable=all m1.cCheckingm1.c...m1.c:7:10:style:misraviolation(use--rule-texts=<file> to get proper output) [misra-c2012-8.4]uint32_tfoo(void){^m1.c:8:12:style:misraviolation(use--rule-texts=<file> to get proper output) [misra-c2012-10.4]returnQ_HDR_SZ;^m1.c:7:10:style:Thefunction'foo'isneverused.[unusedFunction]uint32_tfoo(void){^
Last edit: Daniel Marjamäki 2 days ago
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi.
I don't seem to be able to get out of this problem.
In my file queue.h I have declared:
When using the macro, I get:
Anyone can guide me to why this error is being generated and to fix it?
Is the output really generated by cppcheck? I can't reproduce this with the code above.
Sorry CHR. I realised was say too brief in the description. Here is a more detailed output:
cppcheck version: 2.13.0
$ cppcheck --addon=test/pipeline/coding_stds/misra.json --error-exitcode=255 -I/home/user/devel/repos/project/common/src/utils /home/user/devel/common/src/comp/comp_queue.c
And the result:
And queue.h is in the
/home/user/devel/repos/project/common/src/utils
directoryIf anybody is interested. The workaround is to add -Dpthread_mutex_t=int to get around this issue. I cannot find a better way to get around this.
It seems to me any
sizeof(typedef_of_a_struct_t)
always fails in macro expansions. i.e.#MY_MACRO sizeof(typedef_of_a_struct_t)
will always result in error: Variable 'typedef_of_a_struct_t' is unknown [misra-config]
The cppcheck with misra addon seems to make these errors more and more troublesome in which they needs to be bypassed. In my view, this is creating vulnerabilities by bypassing these errors as code structure might/probably change in future. I have same issues in other cases where my own declared structures are showing the same errors.
Anyone shares my concern?
you can solve it in some different ways.
how does it work if you provide the include path to pthread.h ?
A code example that reproduce the misra-config would be nice. It's not reported below however I did expect such warning.
Last edit: Daniel Marjamäki 2 days ago