我正在学习 SAL 注释,我在 Visual Studio 2017 中测试了这个示例。
我认为当我将 NULL 指针传递给时编译器会报告警告或错误InCallee
,但是,它仍然可以正确构建。所以我的问题是 SAL 是否就像代码注释一样并且不会验证数据的合法性,或者它可以检查数据,只是因为我做错了什么?
void InCallee(_In_ int *pInt) //_In_ is allowed to be NULL
{
int i = *pInt;
}
void GoodInCaller()
{
int *pInt = new int;
*pInt = 5;
InCallee(pInt);
delete pInt;
}
void BadInCaller()
{
int *pInt = NULL;
InCallee(pInt); // pInt should not be NULL
}