【发布时间】:2015-04-20 12:39:35
【问题描述】:
代码工作正常,但是当我在 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;
}
错误是:可能的空指针取消引用:message_to_execute - 否则检查它是否为空是多余的。
【问题讨论】:
-
你已经有一个正确的answer,但是这个 DEBUG_LEVEL 东西似乎过于复杂并且容易出错。