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
9
votes
1 answer

What is the purpose of SAL (Source Annotation Language) and what is the difference between SAL 1 and 2?

As asked in the title: What is the purpose of SAL (Source Annotation Language) and what is the difference between SAL 1 and SAL 2? I understand the basics of the usage, and that is serves to highlight the purpose of each of the variables passed to…
Thomas Russell
  • 5,870
  • 4
  • 33
  • 68
7
votes
1 answer

Quality of Visual Studio Community code analysis with SAL annotations

I hope this question is not out of scope for SO; if it is (sorry in that case), please tell me where it belongs and I'll try to move it there. The concept of SAL annotations for static code analysis in C/C++ seems really useful to me. Take for…
SWdV
  • 1,715
  • 1
  • 15
  • 36
6
votes
1 answer

Warning C6385 in Visual Studio

I seem to get an erroneous warning message from Visual Studio 2019 (16.5 Preview but also in 16.4 and earlier) Code Analysis tool. Is this a bug, or am I really just missing something? The warning generated (exactly) is: warning C6385: Reading…
ChrisMM
  • 8,448
  • 13
  • 29
  • 48
6
votes
2 answers

why _Printf_format_string_ macro doesn't produce any warnings?

In the following snippet the wrong usage of format specifiers inside the MyFormat() call should produce a warning, according to SAL specifications, and if I uncomment the identical call of printf(), I really will receive all these warnings, but my…
George Hazan
  • 170
  • 1
  • 9
4
votes
1 answer

SAL annotations and pointer parameters

I have been reading about SAL and I'm not clear on if annotations on pointer types apply to the reference or the value it points to. For example, if I have: void f(_In_ type* t); _In_ means "The parameter must be valid in pre-state and will not be…
Justin R.
  • 23,435
  • 23
  • 108
  • 157
4
votes
3 answers

Microsoft's Source Annotation Language (SAL) -- any way to take advantage of it?

Is there any way to take advantage of Microsoft's SAL, e.g. through a C parser that preserves this information? Or is it made by Microsoft, for Microsoft's internal use only? It would be immensely useful for a lot of tasks, such as creating C…
user541686
  • 205,094
  • 128
  • 528
  • 886
3
votes
0 answers

why vc++ Code Analyze for may-be-null mark raise C6011 on const member function only?

Here's the minimum example, start code analyze in visual studio 2019 #include class CTest { public: virtual void A() = 0; virtual void B() const = 0; _Check_return_ _Ret_maybenull_ static CTest* GetInstance() { return…
wwc
  • 101
  • 6
3
votes
2 answers

Strange SAL annotation warning

I'm trying to use Micosoft's SAL annotation for my project, however I get the following warning, and I don't know why. As an example, I created a new C++ console application, and have this code: #include class Whatever { public: …
Kevin Doyon
  • 3,464
  • 2
  • 33
  • 38
3
votes
1 answer

Did Microsoft drop source-code annotation language (SAL) and calling convention from their function definition in MSDN

For example, the function definition of SetWindowPos used to be like so: BOOL WINAPI SetWindowPos( _In_ HWND hWnd, _In_opt_ HWND hWndInsertAfter, _In_ int X, _In_ int Y, _In_ int cx, _In_ int cy, _In_ …
user1720897
  • 1,216
  • 3
  • 12
  • 27
3
votes
1 answer

Using Microsoft's Source-Code Annotation Language (SAL) with Doxygen?

I am trying to use Doxygen to document some C++ code that uses Microsoft's Source-Code Annotation Language (SAL). However, Doxygen does not parse certain annotation macros, like _Success_, correctly. In the case of the example function annotation,…
Code Doggo
  • 2,146
  • 6
  • 33
  • 58
3
votes
1 answer

MSVC SAL vs. C++2a Contract

In MSVC, there is SAL feature, which can be used to describe the parameter, result and so on, and it works well, and portable is also good, C++2a Contract feature seems to do the same thing, can somebody give some diffs between them?
ravin.wang
  • 1,122
  • 1
  • 9
  • 26
3
votes
2 answers

sal annotation (prefast) to enforce number of variadic args

I have a variadic function: print_n_integers(7, 1, 2, 3, 4, 5, 6, 7); int print_n_integers( unsigned int count, ... ) { // use va_start etc. } I'd like to use Microsoft's SAL annotations from sal.h so that the Visual Studio compiler notices…
Alex
  • 5,863
  • 2
  • 29
  • 46
3
votes
1 answer

How does the _Pre_defensive_ annotation work?

So I am reasonably conversant with using Microsoft Source Annotation Language (the VS 2012-2013 flavor) to describe function contracts with pointers. One thing I'm curious about, though, is that I expected to get a different result with _In_…
Jay Carlton
  • 1,118
  • 1
  • 11
  • 27
3
votes
1 answer

_Deref_ and _Outptr_ sal annotations

What is the difference between the Deref and Outptr SAL annotations? Also when do you use the different types of Outptr annotation like _Outptr_result_buffer_all_ and _Outptr_result_buffer_?
Mithun
  • 95
  • 1
  • 1
  • 7
2
votes
1 answer

can an "_inout" parameter be "const" "?

My understanding is that if a pointer points to something that is read and written, that is, "inout" then, by definition it cannot be "const" (because of "out") yet, there are prototypes in the C headers that specify parameters as "inout const"…
ScienceAmateur
  • 521
  • 4
  • 11
1
2 3 4