clang-tidy has warning enabled but never throws it - c++

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.

Related

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?

Qt SIGABRT alternative message?

I'm using Qt5.9, a simple check:
assert(pobjNode != NULL);
Will cause the Qt Signal Received error dialog to be displayed which doesn't give any helpful information about where the problem is or what it is.
Is there a way to replace this useless information with something a bit more helpful?
What I'm thinking of is a way to set-up the dialog to display what could be an error in the event of an error.
Q_ASSERT is a custom assert macro which supposedly enhances the standard assert function.
The error message is handled by qFatal(), which can behave slightly better on some platforms than the standard assert macro. For example on Windows it will trigger the Visual Studio debugger at the point where the assertion fails instead of just calling abort().
You can also redirect the output of Qt error message functions such as qFatalto your custom message handler ( with qInstallMessageHandler() ). It can be useful for example if you want to redirect the errors message to a file.
Also note that Q_ASSERT is disabled with the macro QT_NO_DEBUG(while assert is disabled by NDEBUG) : this can be used to separate your asserts between Qt-related code and the rest.
Q_ASSERT_X Prints the message what together with the location where, the source file name and line number if test is false.
Prints the message what together with the location where, the source file name and line number if test is false.
Example:
// File: div.cpp
#include <QtGlobal>
int divide(int a, int b)
{
Q_ASSERT_X(b != 0, "divide", "division by zero");
return a / b;
}
to read more on test and debug.
You might define your own MY_ASSERT macro. On Linux it could even call another function which uses Glibc backtrace functions or Ian Taylor's libbacktrace library (provided your code is compiled with DWARF debug information using g++ -g) and perhaps display such information in a modal dialog, or on stderr. However, it should probably not return. Read also about Qt and Unix signals and signal-safety(7).
But assert detects a bug which you should correct. Try hard to avoid shipping code with such programmer bugs.
On Linux, the usual assert -it is a macro defined in /usr/include/assert.h- will call on failure __assert_fail (in your C library, but you might redefine it yourself) which would indirectly call abort which indirectly makes a core dump which you can inspect post-mortem using the gdb debugger. You only need to enable core dumps (using ulimit -c builtin in your bash terminal).

How to find out the reason of a warning in Python?

I encountered the following warning when it runs scipy.stats.stats.pearsonr() in my program
/usr/local/lib/python2.7/dist-packages/scipy/stats/stats.py:2471: RuntimeWarning: invalid value encountered in double_scalars
I wonder how to find out the reason of the warning, by using print out, or by using a debugger like pdb (I know something about pdb, but I don't know how to use pdb to find out the reason of the warning here).
Here is the line of my program that uses pearsonr():
...
corr = pearsonr(t1, t2)
...
According to the docs, you can change the default warning behavior to raise an exception, which would of course make it much easier to track down and debug.
import warnings
# Cause all warnings to raise exceptions:
warnings.simplefilter("error") # change the hook
# Trigger a warning:
corr = pearsonr(t1, t2) # this will now raise
Replace warnings.showwarning with a function that will print the stack trace.

C++ no 'object' file generated

This is some code to get an environment variable from inside Qt, however, it seems Qt's QProcessEnvironment::systemEnvironment() only reflect a new environment variable change after reboot. So I am thinking about using getenv.
However I got "error C2220: warning treated as error - no 'object' file generated" from this :
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
const QString ENGINE_ROOT = env.value("ENGINE_ROOT", "") != "" ?
env.value("ENGINE_ROOT","") : QString(getenv("ENGINE_ROOT"));
Don't tell me something like disable /WX or lower W4 to W3, I don't want to hear this, I want to know exactly what cause
no 'object' file generated
.
"error C2220: warning treated as error - no 'object' file generated"
The error already answers your question:
A warning was generated.
Because you have told the compiler to treat warnings as errors, an error occurred.
Because an error occurred, the compiler did not generate an object file.
If you want to know what the original warning means, then you need to ask us about that warning.
I just had this problem. The real source of the confusion is that Microsoft Visual Studio lists the
error C2220: warning treated as error - no 'object' file generated
line separately from the warnings--sometimes even before the warnings--so it is not immediately apparent that the error is related to the listed warnings.
Fix all warnings listed to fix this problem.
I'll address the underlying question instead of the compilation problem.
Environment variables for any process are copied from those of its parent process when your new process is started. From that point, the only thing that can modify them is your process yourself.
In practical terms, this means that going to the Windows dialog box to change environment variables does not change those values for any existing processes. Those changes are applied to the explorer.exe process, and then any new processes launched from Explorer.
There is a possible way for a Windows application to get notified of changes made to environment variables made by Explorer. See How to modify the PATH variable definitely through the command line in Windows for details.
in my case, eliminating all useless 'object' will deal this erro

Memory section handling error

I'm getting a link time error:
WARNING: /home/gulevich/development/camac-fedorov/camac/linux/k0607-lsi6/camac-k0607-lsi6.o (.ctors): unexpected non-allocatable section.
Did you forget to use "ax"/"aw" in a .S file?
Note that for example <linux/init.h> contains
section definitions for use in .S files.
The code causing the error (assembly in C source):
# if defined(__ELF__)
# define __SECTION_FLAGS ", \"aw\" , #progbits"
/* writable flag needed for ld ".[cd]tors" sections bug workaround) */
# elif defined(__COFF__)
# define __SECTION_FLAGS ", \"dr\""
/* untested, may be writable flag needed */
# endif
asm
(
".section .ctors" __SECTION_FLAGS "\n"
".globl __ctors_begin__\n"
"__ctors_begin__:\n"
".previous\n"
);
Is there any way to fix this? The idea is to put a varaible __ctors_begin__ at the beginning of a certain memory section. This code is a legacy that worked fine using a different build system and older compiler.
Meaning of this assembly code explained in an answer to my previous question.
very long shot but is the section .ctors is defined like you want in the linker script? ld iirc has a verbose option to show the linker script.
A long shot:
Perhaps your linker is expecting ELF format (instead of COFF), and for some reason __ELF__ is not defined? Have you checked the preprocessor output for this particular build?
I would dobule check the value of __SECTION_FLAGS just to be sure that it indeed contains ax or aw. I'd also be sure that __COFF__ is not defined and that __ELF__ is. Failing that, it might be time to grab (is possible) a previous or future version of the compiler/linker and see if that fixes your problem. Perhaps you could compile your code as C++ and somehow let the compiler/linker/link scritps do what they are supposed to do? Dunno completely, but this is where I would start.
Sections work fine. So I'll ignore this warning.