I am trying to add SALto my code... i worked according msdn and found bug in msdn examples, don't know how to deal with it.
Here litle changed example "Output of pointer to caller (Example: The Outptr Annotation)" from Understanding SAL
Outptr is used to annotate a parameter that's intended to return a pointer. The parameter itself should not be NULL, and the called function returns a non-NULL pointer in it and that pointer points to initialized data.
My code:
#include "stdafx.h"
#include "assert.h"
void GoodOutPtrCallee(_Outptr_ int **pInt)
{
int *pInt2 = new int;
if (*pInt != NULL)
{
*pInt2 = 1;
}
else
{
*pInt2 = 2;
}
*pInt = pInt2;
}
int _tmain(int argc, _TCHAR* argv[])
{
int* nullValue = NULL;
GoodOutPtrCallee(&nullValue);
assert(*nullValue == 2);
int someValue = 22;
int* someValuePtr = &someValue;
GoodOutPtrCallee(&someValuePtr);
assert(*someValuePtr == 1);
return 0;
}
If i compile it in VS2013 with code alalysys enabled i got C6001: using uninitialized memory
for
if (*pInt != NULL)
row.
What is worng here in my annotation and how can i fix it?