Questions tagged [sal]

SAL is the Microsoft language for static analysis of C++ source code.

More details on SAL can be found at https://learn.microsoft.com/en-us/visualstudio/code-quality/using-sal-annotations-to-reduce-c-cpp-code-defects.

52 questions
0
votes
0 answers

How to annotate functions to aid code analysis

Consider the following functions: constexpr bool IsNull(const int* arg) { return arg == nullptr; } void Test() { int x{ 42 }; int* p = &x; // C26429 : Symbol 'p' is never tested for nullness if (!IsNull(p)) *p =…
Frank Heimes
  • 100
  • 6
0
votes
0 answers

Enforce function isolation at compile time

I am working on a project in C Visual Studio, and I have two sets of functions, let’s call them SET_1 and SET_2. I wonder if there is a way to ensure that a function from SET_1 calls only functions from SET_1 and not functions from SET_2. The…
CCrisan
  • 64
  • 5
0
votes
1 answer

When to use _Notnull_ in C++?

Can someone provide insight when to use _Notnull_? I'm using Visual Studio 2019 and here is my code: #include #include void WriteIt(_Notnull_ CONST WCHAR* sMsg, _Notnull_ CONST WCHAR* sFileName) { FILE* stream; errno_t…
JeffR
  • 765
  • 2
  • 8
  • 23
0
votes
1 answer

Locking SAL with Visual Studio

I'm trying to add locking SAL statements to find/prevent incorrect locking in my application. Like missing locking calls and mismatched locking calls. I'm getting warnings I don't understand. I've put them as comments in the example below. I turned…
Daniel Knueven
  • 222
  • 1
  • 11
0
votes
1 answer

Visual studio "Dereferencing NULL pointer" warning

I have a function that creates an address, stores values at the address contiguously, and then returns the address: double* quadratic(double a, double b, double c) { double* solAddr = malloc((size_t)(2 * sizeof(double))); *(solAddr) = (-b +…
Scene
  • 489
  • 4
  • 16
0
votes
0 answers

SAL Annotations will trigger compiler to report error?

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…
Gordon
  • 396
  • 2
  • 15
0
votes
0 answers

Why does this simple annotation example is not rejected in Static Code Analysis?

I'm using SAL to make sure that all code paths that create an object X should call X::work() before destroying it. #include class X { bool worked = false; public: _Post_satisfies_(!worked) X() : worked(false) {} …
nedsociety
  • 88
  • 8
1 2 3
4