cppcheck null指针取消引用:m_buffer-否则,针对null进行检查是多余的
cppcheck null pointer dereference: m_buffer - otherwise it is redundant to check it against null
代码工作正常,但当我在cppcheck上检查它时,我发现了空指针引用错误,我不知道如何解决它。任何想法都将不胜感激
这是我得到错误的代码部分
#ifdef DEBUG_LEVEL_MID
std::clog << "STARTING FUNCTION int ConfigurationType::ExecuteMessageType()" << std::endl;
std::clog << "message with code : " << message_to_execute->code << "will be tried o executed" << std::endl;
#endif
if(!message_to_execute)
{
#ifdef DEBUG_LEVEL_ERROR
std::cerr << "message_to_execute is null at: int ConfigurationType::ExecuteMessageType()" << std::endl;
#endif
#ifdef DEBUG_LEVEL_MID
std::clog << "message_to_execute is NULL at int ConfigurationType::ExecuteMessageType()" << std::endl;
std::clog << "ENDING FUNCTION (0): int ConfigurationType::ExecuteMessageType()" << std::endl;
#endif
return 0;
}
错误为:可能的null指针取消引用:message_to_execute-否则,根据null进行检查是多余的。
您在此处取消引用message_to_execute
:std::clog << "message with code : " << message_to_execute->code
。
这意味着稍后的if (!message_to_execute)
是多余的,因为不允许取消引用null指针,因此编译器可以假设message_to_execute
不是null,并删除测试。
在检查指针是否有效之前,您已经在访问该指针:message_to_execute->code
。将其移动到if语句中,警告将消失。
CPPCheck是对的,如果它是一个nullptr,它将是一个nullptr解引用,如果不是,你将检查它是否是?
相关文章:
- #为""定义宏;静态";针对不同的上下文
- 如果我std::dynamic_pointer_cast并且底层dynamic_cast的结果为null,那么返回的sh
- 如何针对特定情况调试和修复此双自由内存损坏问题
- 如何在 c++ 中'NULL'字符串
- c++使用foreach使数组为null
- 当使用通配符和null指针调用函数时,对输出的说明
- 当字段可以为null时,如何使用C++接口在Avro中写入数据
- 如何在映射中返回null
- 针对遗留库的链接:来自预制makefile的-lgfortranbegin
- 为什么返回 NULL 不会破坏函数?
- 构造函数中的 QQuickItem 父项 null
- Android Studio:如何在build.gradle中定义自定义宏(针对不同的构建变体),并让原生C / C++
- 检查字符串是否"null" C++
- fopen 在 gdb 中返回 NULL
- 在一个解决方案中针对第三方静态库 (Creo) 的不同版本(版本)进行构建
- what(): basic_string::_M_construct null not valid
- 在这个函数中是有缺陷的,因为取消引用 null 是无效的,所以我想更改代码
- 为什么在排序链表上的这种合并实现总是将两个列表都设置为 NULL,而只有一个应该设置一个列表?
- 针对过时的模板显式实例化进行编译
- cppcheck null指针取消引用:m_buffer-否则,针对null进行检查是多余的