使用MinGW-w64的Clang 8:如何使用地址和UB消毒器?
clang 8版本8发行注释有希望的线: 允许在mingw上使用地址消毒剂和未定义的行为消毒剂. 但是,我无法弄清楚如何正确使用它们. 我正在使用clang 8.0.0与msys2 mingw gcc.确切的细节在问题的底部. 我正在尝试按照最小的代码进行编译: 1.cpp #include int main() { // Testing ubsan int x = 0x7fffffff; x++; std::cout
22 2023-03-28
编程技术问答社区
在gcc上由lambda包装器对variadic模板函数调用引起的分段故障
我今天已经花了几个小时我将问题缩短为问题这是瑞银报告: prog.cc: In function 'int main()': prog.cc:61:49: warning: 'ns#0' is used uninitialized in this function [-Wuninitialized] ([&] { ([&] { n.execute(ns...); })(); })(); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~ prog.cc:28:10: note: 'ns#0' was declared here auto execute(TNode& n, TNodes&... ns) ^~~~~~~ prog.cc:30:9: runtime error: member call on null pointer of type 'struct node_then'
20 2023-03-02
编程技术问答社区
抑制来自外部库的UndefinedBehaviorSanitizer警告
我有一个不确定的behaviorsanitizer构建(-fsanitize=undefined),我试图在无法控制的外部库中抑制UB的警告. clang/gcc文档提及 __attribute__((no_sanitize("undefined"))) 看来此属性不会抑制子例程的警告. 简单示例: //__attribute__((no_sanitize("shift"))) // this correctly suppresses the warning int bar() { return 1
22 2023-03-02
编程技术问答社区
通过指向不正确的函数类型的指针调用函数(未知)。
我有一个可以动态链接库的程序. 该程序将功能指针传递给该库,执行. 但是,瑞银(未定义的行为消毒剂)指定指针在不正确的函数类型上.这仅发生 如果回调函数的类别为参数 如果回调函数的类别为参数,但仅向前声明 如果我指定汇编标志:-fvisibility = hidden. 我使用clang编译我的项目. 是clang不确定的行为消毒剂中的错误? 以下代码简化为简单的测试用例.检查评论以查看我们可以在哪里采取的删除一些警告 应用程序的代码: main.cxx #include "Caller.h" #include "Param.h" static void FctVoid() { } static void FctInt(int _param) { static_cast(&_param); } static void FctCaller(Caller &_caller) { static_cast(
16 2023-03-01
编程技术问答社区
C++ UBSAN对派生对象产生假阳性反应
我想使用瑞银(未定义的行为消毒剂),但发现它完全毫无价值,因为它向许多误报报告. 例如.一个简单的std::make_shared(42);足以触发警告 地址内的会员访问0x00000236DE70,该访问未指向类型的对象'_sp_counted_base' 将此示例简化为MWE表明,基本类和继承的问题更为笼统: 示例: struct Foo{ int f(){ return g(); } virtual int g() = 0; }; struct Bar: Foo{ int g(){ return 42; } }; int main(){ auto f = new Bar(); return f->g(); } 用-fsanitize=undefined编译和观看 示例.cpp:15:16:运行时错误:地址上的会员调用0x000000726e70,该 不指向类型的对象 0x00000
18 2023-02-27
编程技术问答社区
如何抑制UBsan的一些无符号整数溢出错误?
我的大多数-fsanitize=unsigned-integer-overflow错误是错误,但有时我会按预期明确使用它,从而导致瑞银产生误报. 有没有办法将瑞银unsigned-integer-overflow签到特定表达式? 编辑响应Shafik评论,这是一个示例: unsigned a = 0; unsigned b = a - 1; // error: unsigned integer overflow 大多数时候是一个错误,有时不是.有了乌班,人们可以找到每次发生的事情,请修复错误,但是我还没有找到一种使误报沉默的方法. 编辑2:要启用检查,需要通过-fsanitize=integer(启用所有整数检查)或fsanitize=unsigned-integer-overflow.从下面的评论看来,该检查仅在Clang中可用,而不是在GCC中. 解决方案 如果要将操作包裹在功能中,则可以使用__attribute__((no_sanitize("
18 2023-02-27
编程技术问答社区
使用GCC未定义行为净化器
今天,我已经阅读了一篇文章关于 GCC不确定的行为消毒剂(UBSAN).但是,当我遵循其中的步骤(在我的代码中添加-fsanitize=undefined)时,编译器(Ubuntu 15.04上的GCC 4.9.2)表示未定义一些参考: ||=== Build: Debug in Project (compiler: GNU GCC Compiler) ===| obj/Debug/App.o||In function `App::OnInit()':| /home/ilya/Project/App.cpp|31|undefined reference to `__ubsan_handle_type_mismatch'| /home/ilya/Project/App.cpp|31|undefined reference to `__ubsan_handle_load_invalid_value'| ... obj/Debug/App.o||In function `wxObject
32 2023-02-24
编程技术问答社区
我怎样才能在gdb中打破UBSan报告并继续?
GCC和Clang的最新版本不确定的行为消毒剂(UBSAN),它是添加运行时仪器代码的编译标志(-fsanitize=undefined).在错误上,显示了这样的警告: packet-ber.c:1917:23:运行时错误:54645397829836991乘8个位置的左移,在类型的'long int' 中不能表示 现在,我想调试此问题,并在上​​述线上进行调试.对于地址消毒剂(ASAN),有ASAN_OPTIONS=abort_on_error=1导致致命错误可捕获.唯一可用的ubsan选项是 UBSAN_OPTIONS=print_stacktrace=1 导致报告的呼叫跟踪转储.但是,这不允许我检查本地变量,然后继续该程序.因此无法使用-fsanitize-undefined-trap-on-error. 我应该如何在瑞银报告中打破GDB? break __sanitizer::SharedPrintfCode似乎有效,但名称看​​起来很内部. 解决方案 在
18 2023-02-03
编程技术问答社区
未定义对`__ubsan_handle_nonnull_arg'的引用。
我一直在处理最后几天的问题拼写器,到目前为止,这就是我所拥有的.不幸的是,它没有编译,我有点迷路了.如果有人能帮助我并告诉我,我做错了什么,我真的很感激. // Implements a dictionary's functionality #include #include #include #include #include #include "dictionary.h" #define HASHTABLE_SIZE 65536 // A struct for a node typedef struct node { // Length is up to 45 + 1 for the Null char word[LENGTH + 1]; // A pointer to the next node struct node *ne
228 2022-08-22
编程技术问答社区
未定义行为消毒器。如何抑制一些无符号|整数|溢出错误?
我的 -fsanitize = unsigned-integer-overflow 错误大多是错误,但有时我明确地使用它的预期,这导致UBSan产生假阳性。 p> 有没有办法可以为特定表达式关闭UBSan无符号整数溢出检查? 到Shafik的注释,这里是一个例子: unsigned a = 0; unsigned b = a - 1; //错误:无符号整数溢出 大多数时间是一个错误,有时不是。对于UBSan,可以找到每一次发生的问题,修复错误,但是我没有找到一种方法来消除假阳性。 编辑2:启用检查需要传递 -fsanitize = integer (以启用所有整数检查)或 fsanitize = unsigned-integer-overflow 。 解决方案 如果你想包装在一个函数中的操作你可以使用 __ attribute __((no_sanitize(“integer”)))这样( 查看活动 ): __a
8488 2022-07-17
编程技术问答社区