I encoutered the following issue on my project. I have a file which is cheking which defines are currently set at library level. If a define is missing, during the library building, I need to raise an error. After some investigation, I figure out what was the cause of the problem with the following code:
// #defineLITTLE_ENDIAN// #defineBIG_ENDIAN//Checkdefines
#if!defined(LITTLE_ENDIAN)&&!defined(BIG_ENDIAN)
#error"One endianness format must be defined."
#endif
#ifdefined(LITTLE_ENDIAN)&&defined(BIG_ENDIAN)
#error"Both endianness format cannot be defined."
#endif//Mainfunctionintmain(intargc, char*argv[])
{
return0;
}
I expected from the user, in order to build the library, to define one endianness format.
When I used Cppcheck on that file, I get this error:
Checkingtest.c...Defines:Undefines:Includes:Platform:Nativetest.c:0:0:information:Thisfileisnotanalyzed.Cppcheckfailedtoextractavalidconfiguration.Thetestedconfigurationshavethesepreprocessorerrors:'':[test.c:6]#error"One endianness format must be defined."BIG_ENDIAN;LITTLE_ENDIAN:[test.c:10]#error"Not both endianness format can be defined."[noValidConfiguration]
I would have expected from Cppcheck to analyse the code two times:
First with LITTLE_ENDIAN
Then with BIG_ENDIAN
But maybe I'm doing something wrong.
Regards,
Jérémy
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
But well a fix for 9427 would be better of course :-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2019-10-19
Well, updating the code is not really possible. In fact, I show you an extract of the code. But there are other conditions like this one. And some of them imply more than two defines.
I look at the code you point me, if I get time and if I understand well the code of Cppcheck I could try.
Anyway, thank you to have reported this issue :)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2019-10-27
In the meantime, is it possible to ignore this reported error through command line arguments ?
I'm using Cppcheck in a CI process, and since these errors arose, this has become less usable in my daily development.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Try to manually specify the defines. Use -D and -U.
integrate your build system in cppcheck somehow. Do you use some project files that can be imported with --project directly? Is it possible for you to generate a compile database? If your build system allows output of compile database directly that is easiest (cmake, etc). Otherwise you could try some compile database generator, I can't recommend any but something like bear or https://github.com/nickdiego/compiledb ..
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2019-10-28
I'm not sure if both of these options can be used on my side. My project is a library, and not a software. This library has a configuration file where the user can enable or disable features. Such as the configuration file "config.h" of MbedTLS.
I'm using Cppcheck to check every define of the library (there are more than 50 possible defines). Of course, some defines cannot be set when others are already set, that's why I also have a file checking the combination of user defines.
Cppcheck is used here to check the code with all the defines. And thus, I can't set a preset of defines.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2019-11-06
In the meantime, I find a way to remove the check of the rule "noValidConfiguration" !
I tried "--suppress=noValidConfiguration" and it worked.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I encoutered the following issue on my project. I have a file which is cheking which defines are currently set at library level. If a define is missing, during the library building, I need to raise an error. After some investigation, I figure out what was the cause of the problem with the following code:
I expected from the user, in order to build the library, to define one endianness format.
When I used Cppcheck on that file, I get this error:
I would have expected from Cppcheck to analyse the code two times:
But maybe I'm doing something wrong.
Regards,
Jérémy
You did not do anything wrong. It seems this is too complex :-(
I created this ticket: https://trac.cppcheck.net/ticket/9427
You can fix the Cppcheck code if you want and ensure that Cppcheck can handle this better. See
https://github.com/danmar/cppcheck/blob/master/lib/preprocessor.cpp#L425
It's ~100-200 lines of code so it's not a huge algorithm.
I guess you could update your code ...
But well a fix for 9427 would be better of course :-)
Well, updating the code is not really possible. In fact, I show you an extract of the code. But there are other conditions like this one. And some of them imply more than two defines.
I look at the code you point me, if I get time and if I understand well the code of Cppcheck I could try.
Anyway, thank you to have reported this issue :)
In the meantime, is it possible to ignore this reported error through command line arguments ?
I'm using Cppcheck in a CI process, and since these errors arose, this has become less usable in my daily development.
yes of course.
I think you have two options;
Try to manually specify the defines. Use -D and -U.
integrate your build system in cppcheck somehow. Do you use some project files that can be imported with
--project
directly? Is it possible for you to generate a compile database? If your build system allows output of compile database directly that is easiest (cmake, etc). Otherwise you could try some compile database generator, I can't recommend any but something like bear or https://github.com/nickdiego/compiledb ..I'm not sure if both of these options can be used on my side. My project is a library, and not a software. This library has a configuration file where the user can enable or disable features. Such as the configuration file "config.h" of MbedTLS.
I'm using Cppcheck to check every define of the library (there are more than 50 possible defines). Of course, some defines cannot be set when others are already set, that's why I also have a file checking the combination of user defines.
Cppcheck is used here to check the code with all the defines. And thus, I can't set a preset of defines.
In the meantime, I find a way to remove the check of the rule "noValidConfiguration" !
I tried "--suppress=noValidConfiguration" and it worked.