0

I am learning SAL Annotations, I tested this example in Visual Studio 2017.

I thought the compiler will report warning or error when I pass a NULL pointer to InCallee, however, it still can build correctly.so my question is whether SAL is just like code comments and won't validate legality of the data, or it can check the data, just because I made something wrong?

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
}
Community
  • 1
  • 1
Gordon
  • 396
  • 2
  • 15
  • 1
    Did you read https://learn.microsoft.com/en-us/visualstudio/code-quality/understanding-sal?view=vs-2015#using-the-visual-studio-code-analysis-tool-to-find-defects – Ctx Oct 15 '18 at 10:42
  • 1
    The **compiler** doesn't validate SAL annotations, they are just a bunch of empty preprocessor `#define`s as far as the C and C++ languages are concerned. SAL annotations are used by **static analysis tools** instead. – Remy Lebeau Oct 15 '18 at 16:28
  • where can I get the **static analysis tools** ? – Gordon Oct 16 '18 at 00:52

0 Answers0