cppcheck does not detect resource leak due to include paths - cppcheck

Can anyone plz help?
When I was analysing my source code simply via
"cppcheck file" it out puts analysis results like
Checking ../bst_hal/daemon_rls/src/event_handler.c...
Checking ../bst_hal/daemon_rls/src/event_handler.c: CFG_ARCH_ARM...
Checking ../bst_hal/daemon_rls/src/event_handler.c: CFG_ARCH_ARM;CFG_HANDLE_FAULT_SIG...
Checking ../bst_hal/daemon_rls/src/event_handler.c: CFG_CHECK_DISPLAY_STATE...
**[../bst_hal/daemon_rls/src/event_handler.c:236]: (error) Resource leak: fd_w**
Checking ../bst_hal/daemon_rls/src/event_handler.c: CFG_CHECK_DISPLAY_STATE;CFG_SENSORD_SIMU...
Checking ../bst_hal/daemon_rls/src/event_handler.c: CFG_DISCARD_OLD_CMD...
Checking ../bst_hal/daemon_rls/src/event_handler.c: CFG_HANDLE_FAULT_SIG...
Checking ../bst_hal/daemon_rls/src/event_handler.c: CFG_SENSORD_SIMU...
But after I specified some paths via -I like:
cppcheck --force -I<patha> -I<pathb> ... file.c
my leak error is gone:
Checking ../bst_hal/daemon_rls/src/event_handler.c...
Checking ../bst_hal/daemon_rls/src/event_handler.c: ARRAY_SIZE...
Checking ../bst_hal/daemon_rls/src/event_handler.c: CFG_ARCH_ARM...
Checking ../bst_hal/daemon_rls/src/event_handler.c: CFG_CHECK_DISPLAY_STATE...
Checking ../bst_hal/daemon_rls/src/event_handler.c: CFG_CHECK_DISPLAY_STATE;CFG_SENSORD_SIMU...
Checking ../bst_hal/daemon_rls/src/event_handler.c: CFG_DATA_INPUT_SRC_FILE...
Checking ../bst_hal/daemon_rls/src/event_handler.c: CFG_LOG_TO_LOGCAT...
Checking ../bst_hal/daemon_rls/src/event_handler.c: CFG_LOG_WITH_TIME...
Checking ../bst_hal/daemon_rls/src/event_handler.c: CFG_SENSORD_SIMU...
Checking ../bst_hal/daemon_rls/src/event_handler.c: CFG_SENSOR_G_EMU...
Checking ../bst_hal/daemon_rls/src/event_handler.c: CFG_TARGET_OS_ANDROID...
Checking ../bst_hal/daemon_rls/src/event_handler.c: CFG_TARGET_OS_LINUX...
Checking ../bst_hal/daemon_rls/src/event_handler.c: CONTAINER_OF...
Checking ../bst_hal/daemon_rls/src/event_handler.c: OFFSET_OF...

I am a Cppcheck developer. This looks very interesting. Is the source code open source?

Related

clang-tidy has warning enabled but never throws it

I'm trying to make my clang-tidy to emit errors for unsafe API usage.
My .clang-tidy looks as follows:
---
Checks:
'
*
,-abseil-*
,-altera-*
,-android-*
,-darwin-*
,-fuchsia-*
,-linuxkernel-*
,-llvm-*
,-llvmlibc-*
,-mpi-*
,-objc-*
,-openmp-*
,-zircon-*
,-modernize-use-trailing-return-type
,-readability-identifier-length
'
WarningsAsErrors: '
clang-analyzer-security*
'
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
FormatStyle: none
User: user
CheckOptions:
...
When I invoke clang tidy I see list of enabled checks, which includes
clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling
According to documentation this should make clang-tidy warn me if I'm using unsafe functions like memcpy. The reality is that I don't get it neither as warning, nor as error.
The file and the line gets checked for sure, since clang-tidy emits other warning on those memset calls:
cppcoreguidelines-pro-bounds-array-to-pointer-decay
But whatever I do, I'm unable to get DeprecatedOrUnsafeBufferHandling generated.
Currently I'm observing that behavior on clang-tidy-14.

Filebeat regex for tomcat

I'm having trouble to get the correct regex for filebeat when using tomcat and log4j.
For this log:
21/10/2022 16:04:37 ERROR en Clase: ExceptionLogger - MSN: test
Exception.Class: BUSINESS EXCEPTION
ErrorCode: 0
Usuario: test
StackTrace:
at ar.com.test.conf.Monitor.monitorTest(ImpBusCaja.java:1213)
at ar.com.test.delegators.Monitor.m(Cajas.java:595)
I've configured this pattern: '^[[:space:]]' with negate=false and match=after (as the documentation says) but it doesn't work.
Even if I use the go playground, it should work: https://go.dev/play/p/JGV8ZDPtHwt
Here's what we have for configuration for log4j-based files with a slightly different pattern, but you should be able to adapt it to your situation:
multiline.type: pattern
multiline.pattern: '^\d{4}-\d{2}-'
multiline.negate: true
multiline.match: after
Here's an example standard log4j log line:
2022-10-22 13:55:34,932 [pool-8-thread-1] TRACE fully.qualified.class.Name- Here's the raw message
Here's an example exception message:
2022-10-21 20:14:42,442 [catalina-exec-6] ERROR fully.qualified.class.Name- Main error message
fully.qualified.exception.Type: Exception error message
at stack.trace.class.method(Source.java:103)
at stack.trace.class.method(Source.java:203)
at stack.trace.class.method(Source.java:303)
at stack.trace.class.method(Source.java:403)
So we are just looking for log lines starting with dddd-dd- and assuming that those are always "new log entries". We could certainly confuse things with a log line that was a continuation of something previous which started with that same pattern, but that's very rare.

Grib_api options in f90

As we know if I want to get the levelType of each message in a grib file.
I could use this below in f90:
grib_get(igrib(i), 'levelType', ltype)
But when fail it will cause a eccodes error and can't gei the value. As the document of grib_api on the site of ECMWF. I found an option 'f' to force the execution not to fail on error and write 'not_found' string to ltype paramters. My quastion is how can i usethis force option in f90?

How to validate whether a c++ program is well documented using Doxygen format or not?

Is there a way for Doxygen to report whether source code is documented or not? Is there any way to identify the set of files which are not well documented in a set of C++ source files?
Coding Language: C++
Documentation Tool : Doxygen (This can be changed with some other open tool if it has an option for validation)
/// \brief Main function
/// \param argc An integer argument count of the command line arguments
/// \param argv An argument vector of the command line arguments
/// \return an integer 0 upon exit success
int main(int argc, char** argv)
{
/// Comments I would like to be documented in as well
return 0;
}
The command which I have used is as follows
$> doxygen Doxyfile && echo "success" || echo "failed"
Doxygen already provides some useful configuration options:
WARN_IF_UNDOCUMENTED
If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag will automatically be disabled.
WARN_IF_DOC_ERROR
If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for potential errors in the documentation, such as not documenting some parameters in a documented function, or documenting parameters that don't exist or using markup commands wrongly.
WARN_NO_PARAMDOC
This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that are documented, but have no documentation for their parameters or return value. If set to NO, doxygen will only warn about wrong or incomplete parameter documentation, but not about the absence of documentation. If EXTRACT_ALL is set to YES then this flag will automatically be disabled.
And finally:
WARN_AS_ERROR
If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when a warning is encountered. If the WARN_AS_ERROR tag is set to FAIL_ON_WARNINGS then doxygen will continue running as if WARN_AS_ERROR tag is set to NO, but at the end of the doxygen process doxygen will return with a non-zero status.
Possible values are: NO, YES and FAIL_ON_WARNINGS.
So let's put all this together. The Doxyfile needs to contain the following settings:
# EXTRACT_ALL = NO is needed, or otherwise some of the
# other flags are disabled automatically.
EXTRACT_ALL = NO
WARN_IF_UNDOCUMENTED = YES
WARN_IF_DOC_ERROR = YES
WARN_NO_PARAMDOC = YES
# WARN_AS_ERROR could also be NO, but then
# it stops after the first documentation error.
WARN_AS_ERROR = YES
That way doxygen will show all undocumented code and it will exit with a non-zero, if there is undocumented code.

Getting rid of FFmpeg non-existng PPS error

I am using ffmpeg to decode videos. I am aware that the error I am getting is due to the frame/sliceHeader is decoded and the Picture Parameter Set information is not there. I am just curious if anyone knows a way to get rid of this error? My video is successfully decoding but in the debugger this error makes the metadata hard to read.
The error is :
non existing PPS 0 referenced
decode_slice_header error
no frame!
******** My code is in C ******
Check the FFmpeg logging facilities - you can use av_log_set_callback to provide your own logging callback and either just ignore everything, or filter by log level, it is up to you.
In my case of use, i was able to still receive critical errors, but no longer decoder errors with following parameters:
ffmpeg -loglevel panic
Here is a snippet of documentation of available loglevels:
-loglevel [repeat+]loglevel | -v [repeat+]loglevel
Set the logging level used by the library. Adding "repeat+" indicates that repeated log output should not be compressed to the first line and the "Last message repeated n times" line will be omitted. "repeat" can also be used alone. If "repeat" is used alone, and with no prior loglevel set, the default loglevel will be used. If multiple loglevel parameters are given, using ’repeat’ will not change the loglevel. loglevel is a string or a number containing one of the following values:
‘quiet, -8’
Show nothing at all; be silent.
‘panic, 0’
Only show fatal errors which could lead the process to crash, such as and assert failure. This is not currently used for anything.
‘fatal, 8’
Only show fatal errors. These are errors after which the process absolutely cannot continue after.
‘error, 16’
Show all errors, including ones which can be recovered from.
‘warning, 24’
Show all warnings and errors. Any message related to possibly incorrect or unexpected events will be shown.
‘info, 32’
Show informative messages during processing. This is in addition to warnings and errors. This is the default value.
‘verbose, 40’
Same as info, except more verbose.
‘debug, 48’
Show everything, including debugging information.
‘trace, 56’
For me, my solution turned out to be :
Hope it helps anyone using ffmpeg in c!
av_log_set_level(AV_LOG_QUIET);