我使用的是GCC 11.1,并且我已经使用-fanalyzer选项启用了静态分析器。现在,在这行代码中:
std::pair<NodeIterator, bool> result = idNodeMap.emplace(id,
new Node(id, point));我得到以下警告:
..\src\Mesh\Mesh.cpp: In member function 'void Ct::Geometry::Mesh::addNode(int, const gp_Pnt&)':
..\src\Mesh\Mesh.cpp:30:43: warning: use of possibly-NULL 'operator new(32)' where non-null expected [CWE-690] [-Wanalyzer-possible-null-argument]
30 | new Node(id, point));
| ^
'void Ct::Geometry::Mesh::addNode(int, const gp_Pnt&)': events 1-2
|
|
In file included from ..\src\Mesh\Mesh.h:12,
from ..\src\Mesh\Mesh.cpp:9:
..\src\Mesh\Node.h:31:9: note: argument 'this' of 'Ct::Geometry::Node::Node(int, const gp_Pnt&)' must be non-null
31 | Node(int id, const gp_Pnt& point);
| ^~~~我没理解错警告吧,就是GCC要我检查一下new是否返回null?根据这篇文章:Will new return NULL in any case?目前的编译器和完善的编译选项从来都不是这样的。那么,这是对罕见特殊情况的警告吗?我应该禁用它吗?
或者是我忽略了什么,我的代码中存在真正的危险?
https://stackoverflow.com/questions/68082513
复制相似问题