c++ - 静态分析给出“取消引用, 已知为 nullptr"
问题描述
我在一个项目上使用 Coverity 运行静态分析,而我遇到了该工具报告的这个错误:
Dereferencing <storage from new>, which is known to be nullptr
代码片段是:
typedef struct envelope
{
char *message;
void *context;
bool response;
}envelopeRef;
int main()
{
/* here coverity tells that
1. returned_null: operator new returns nullptr (checked 46 out of 52 times)
2. var_assigned: Assigning: <storage from new> = nullptr return value from operator new
3. dereference: Dereferencing <storage from new>, which is known to be nullptr.
*/
envelopeRef *h = new (std::nothrow)envelopeRef();
if(nullptr != h)
{
//do something
delete h;
}
}
我在这里做错了什么?
解决方案
推荐阅读
- pine-script - Getting time of day of bar close
- reactjs - How to remove the opacity of the slides that are behind in react-spring-3d-carousel?
- flutter-web - how to get variable's value from custom Js and use it in Flutter web/dart
- r - trying to avoid the "no non-missing arguments to min; returning Inf" warning with if_else condition does not work
- javascript - How can I push objects from an API with a forEach function into a state?
- javascript - Windows 10 Unable to access xxx.local domain via nodeJS
- node.js - Sequelize Query take all values in where condition
- opencl - 带有 OpenCL 1.2 的 NVIDIA Ampere 代 GPU 支持或不支持半精度浮点
- android - Stripe 支付是否支持阿联酋的三星支付?
- server - N/sftp 模块 - FTP_CANNOT_ESTABLISH_CONNECTION