Skip to content

Commit 2747640

Browse files
Enable code analysis and fix NULL usage.
1 parent 870eec2 commit 2747640

39 files changed

+748
-706
lines changed

src/Servers/IIS/AspNetCoreModuleV2/AspNetCore/applicationinfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ APPLICATION_INFO::HandleShadowCopy(const ShimOptions& options, IHttpContext& pHt
301301
auto shadowCopyBaseDirectory = std::filesystem::directory_entry(shadowCopyPath);
302302
if (!shadowCopyBaseDirectory.exists())
303303
{
304-
CreateDirectory(shadowCopyBaseDirectory.path().wstring().c_str(), NULL);
304+
CreateDirectory(shadowCopyBaseDirectory.path().wstring().c_str(), nullptr);
305305
}
306306

307307
for (auto& entry : std::filesystem::directory_iterator(shadowCopyPath))

src/Servers/IIS/AspNetCoreModuleV2/CommonLib/CommonLib.vcxproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\..\build\Build.Lib.Settings" />
34
<PropertyGroup Label="Globals">
45
<ProjectGuid>{55494E58-E061-4C4C-A0A8-837008E72F85}</ProjectGuid>
56
<RootNamespace>NewCommon</RootNamespace>
7+
<RunCodeAnalysis>false</RunCodeAnalysis>
68
</PropertyGroup>
7-
<Import Project="..\..\build\Build.Lib.Settings" />
89
<ItemDefinitionGroup>
910
<ClCompile>
1011
<AdditionalIncludeDirectories>..\iislib;$(LibNetHostPath)</AdditionalIncludeDirectories>

src/Servers/IIS/AspNetCoreModuleV2/CommonLib/sttimer.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class STTIMER
1313
public:
1414

1515
STTIMER()
16-
: _pTimer( NULL )
16+
: _pTimer( nullptr )
1717
{
1818
fInCanel = FALSE;
1919
}
@@ -25,7 +25,7 @@ class STTIMER
2525
{
2626
CancelTimer();
2727
CloseThreadpoolTimer( _pTimer );
28-
_pTimer = NULL;
28+
_pTimer = nullptr;
2929
}
3030
}
3131

@@ -39,7 +39,7 @@ class STTIMER
3939
{
4040
_pTimer = CreateThreadpoolTimer( pfnCallback,
4141
pContext,
42-
NULL );
42+
nullptr );
4343

4444
if ( !_pTimer )
4545
{
@@ -74,9 +74,9 @@ class STTIMER
7474
// re-enabled by setting non-zero initial wait or
7575
// period values.
7676
//
77-
if (_pTimer != NULL)
77+
if (_pTimer != nullptr)
7878
{
79-
SetThreadpoolTimer(_pTimer, NULL, 0, 0);
79+
SetThreadpoolTimer(_pTimer, nullptr, 0, 0);
8080
}
8181

8282
return;
@@ -106,7 +106,7 @@ class STTIMER
106106
// Wait until any callbacks queued prior to disabling
107107
// have completed.
108108
//
109-
if (_pTimer != NULL)
109+
if (_pTimer != nullptr)
110110
{
111111
WaitForThreadpoolTimerCallbacks(_pTimer, TRUE);
112112
}
@@ -124,21 +124,21 @@ class STTIMER
124124
)
125125
{
126126
STRU* pstruLogFilePath = (STRU*)Context;
127-
HANDLE hStdoutHandle = NULL;
127+
HANDLE hStdoutHandle = nullptr;
128128
SECURITY_ATTRIBUTES saAttr = { 0 };
129129
HRESULT hr = S_OK;
130130

131131
saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
132132
saAttr.bInheritHandle = TRUE;
133-
saAttr.lpSecurityDescriptor = NULL;
133+
saAttr.lpSecurityDescriptor = nullptr;
134134

135135
hStdoutHandle = CreateFileW(pstruLogFilePath->QueryStr(),
136136
FILE_READ_DATA,
137137
FILE_SHARE_WRITE,
138138
&saAttr,
139139
OPEN_ALWAYS,
140140
FILE_ATTRIBUTE_NORMAL,
141-
NULL);
141+
nullptr);
142142
if (hStdoutHandle == INVALID_HANDLE_VALUE)
143143
{
144144
hr = HRESULT_FROM_WIN32(GetLastError());

src/Servers/IIS/AspNetCoreModuleV2/CommonLibTests/CommonLibTests.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<ProjectGuid>{1eac8125-1765-4e2d-8cbe-56dc98a1c8c1}</ProjectGuid>
1010
<Keyword>Win32Proj</Keyword>
1111
<ConfigurationType>Application</ConfigurationType>
12-
<PlatformToolset>$(PlatformToolsetVersion)</PlatformToolset>
12+
<PlatformToolset>v$(PlatformToolsetVersion)</PlatformToolset>
1313
<CharacterSet>Unicode</CharacterSet>
1414
<IsTestProject>true</IsTestProject>
1515
<DisableArcadeTestFramework>true</DisableArcadeTestFramework>

src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset

Lines changed: 70 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<RuleSet Name="DefaultRules" ToolsVersion="15.0">
2+
<RuleSet Name="DefaultRules" ToolsVersion="17.0">
33
<Include Path="allrules.ruleset" Action="Default" />
44
<Rules AnalyzerId="Microsoft.Analyzers.NativeCodeAnalysis" RuleNamespace="Microsoft.Rules.Native">
55
<Rule Id="C26100" Action="Error" />
@@ -12,88 +12,97 @@
1212
<Rule Id="C26116" Action="Error" />
1313
<Rule Id="C26117" Action="Error" />
1414
<Rule Id="C26130" Action="Error" />
15-
<Rule Id="C26135" Action="Error" />
15+
<Rule Id="C26135" Action="None" /> <!-- Missing annotation <annotation> at function '<func>' -->
1616
<Rule Id="C26140" Action="Error" />
17-
<Rule Id="C26160" Action="Error" />
17+
<Rule Id="C26160" Action="None" /> <!-- Caller possibly failing to hold lock '<lock>' before calling function '<func>'. -->
1818
<Rule Id="C26165" Action="Error" />
1919
<Rule Id="C26166" Action="Error" />
2020
<Rule Id="C26167" Action="Error" />
21-
<Rule Id="C26400" Action="Error" />
22-
<Rule Id="C26401" Action="Error" />
21+
<Rule Id="C26400" Action="None" /> <!-- Do not assign the result of an allocation or a function call with an owner<T> return value to a raw pointer -->
22+
<Rule Id="C26401" Action="None" /> <!-- Do not delete a raw pointer that is not an owner<T> -->
2323
<Rule Id="C26402" Action="Error" />
2424
<Rule Id="C26403" Action="Error" />
2525
<Rule Id="C26404" Action="Error" />
2626
<Rule Id="C26405" Action="Error" />
2727
<Rule Id="C26406" Action="Error" />
2828
<Rule Id="C26407" Action="Error" />
2929
<Rule Id="C26408" Action="Error" />
30-
<Rule Id="C26409" Action="Error" />
30+
<Rule Id="C26409" Action="None" /> <!-- Avoid calling new and delete explicitly, use std::make_unique<T> instead -->
3131
<Rule Id="C26410" Action="Error" />
3232
<Rule Id="C26411" Action="Error" />
33-
<Rule Id="C26414" Action="Error" />
34-
<Rule Id="C26415" Action="Error" />
33+
<Rule Id="C26414" Action="None" /> <!-- Move, copy, reassign or reset a local smart pointer. -->
34+
<Rule Id="C26415" Action="None" /> <!-- Smart pointer parameter is used only to access contained pointer. Use T* or T& instead. -->
3535
<Rule Id="C26416" Action="Error" />
3636
<Rule Id="C26417" Action="Error" />
37-
<Rule Id="C26418" Action="Error" />
37+
<Rule Id="C26418" Action="None" /> <!-- Shared pointer parameter is not copied or moved. Use T* or T& instead. -->
3838
<Rule Id="C26426" Action="Error" />
3939
<Rule Id="C26427" Action="Error" />
40-
<Rule Id="C26429" Action="None" />
41-
<Rule Id="C26430" Action="Error" />
40+
<Rule Id="C26429" Action="None" /> <!-- Symbol is never tested for nullness, it can be marked as gsl::not_null. -->
41+
<Rule Id="C26430" Action="None" /> <!-- Symbol '<var>' is not tested for nullness on all paths -->
4242
<Rule Id="C26431" Action="Error" />
43-
<Rule Id="C26432" Action="None" />
44-
<Rule Id="C26433" Action="Error" />
45-
<Rule Id="C26434" Action="Error" />
43+
<Rule Id="C26432" Action="None" /> <!-- If you define or delete any default operation in the type 'type-name', define or delete them all -->
44+
<Rule Id="C26433" Action="None" /> <!-- Function should be marked with override -->
45+
<Rule Id="C26434" Action="None" /> <!-- Function 'derived::function' hides a non-virtual function 'base::function' -->
4646
<Rule Id="C26435" Action="Error" />
47-
<Rule Id="C26436" Action="Error" />
47+
<Rule Id="C26436" Action="None" /> <!-- The type 'symbol' with a virtual function needs either public virtual or protected non-virtual destructor -->
4848
<Rule Id="C26437" Action="Error" />
49-
<Rule Id="C26438" Action="Error" />
49+
<Rule Id="C26438" Action="None" /> <!-- Avoid goto -->
5050
<Rule Id="C26439" Action="Error" />
51-
<Rule Id="C26440" Action="Error" />
51+
<Rule Id="C26440" Action="None" /> <!-- Function can be declared 'noexcept'. -->
5252
<Rule Id="C26441" Action="Error" />
5353
<Rule Id="C26443" Action="Error" />
5454
<Rule Id="C26444" Action="Error" />
5555
<Rule Id="C26445" Action="Error" />
56-
<Rule Id="C26446" Action="None" />
57-
<Rule Id="C26447" Action="Error" />
58-
<Rule Id="C26448" Action="None" />
56+
<Rule Id="C26446" Action="None" /> <!-- Prefer to use gsl::at() instead of unchecked subscript operator -->
57+
<Rule Id="C26447" Action="None" /> <!-- The function is declared noexcept but calls function function_name that may throw exceptions -->
58+
<Rule Id="C26448" Action="None" /> <!-- Consider using gsl::finally if final action is intended -->
5959
<Rule Id="C26449" Action="Error" />
6060
<Rule Id="C26450" Action="Error" />
61-
<Rule Id="C26451" Action="Error" />
61+
<Rule Id="C26451" Action="None" /> <!-- Arithmetic overflow: Using operator '+' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator '+' to avoid overflow -->
6262
<Rule Id="C26452" Action="Error" />
6363
<Rule Id="C26453" Action="Error" />
6464
<Rule Id="C26454" Action="Error" />
65+
<Rule Id="C26455" Action="None" /> <!-- Default constructor should not throw. Declare it 'noexcept' -->
66+
<Rule Id="C26457" Action="None" /> <!-- (void) should not be used to ignore return values, use 'std::ignore =' instead -->
6567
<Rule Id="C26459" Action="Error" />
66-
<Rule Id="C26460" Action="Error" />
67-
<Rule Id="C26461" Action="Error" />
68-
<Rule Id="C26462" Action="Error" />
68+
<Rule Id="C26460" Action="None" /> <!-- The reference argument 'argument' for function 'function' can be marked as const -->
69+
<Rule Id="C26461" Action="None" /> <!-- The pointer argument 'argument' for function 'function' can be marked as a pointer to const -->
70+
<Rule Id="C26462" Action="None" /> <!-- The value pointed to by '<var>' is assigned only once, mark it as a pointer to const -->
6971
<Rule Id="C26463" Action="Error" />
7072
<Rule Id="C26464" Action="Error" />
7173
<Rule Id="C26465" Action="Error" />
7274
<Rule Id="C26466" Action="Error" />
73-
<Rule Id="C26471" Action="Error" />
74-
<Rule Id="C26472" Action="None" />
75-
<Rule Id="C26473" Action="Error" />
76-
<Rule Id="C26474" Action="Error" />
75+
<Rule Id="C26467" Action="None" /> <!-- Converting from floating point to unsigned integral types results in non-portable code if the double/float has a negative value. -->
76+
<Rule Id="C26471" Action="None" /> <!-- Don't use reinterpret_cast. A cast from void* can use static_cast -->
77+
<Rule Id="C26472" Action="None" /> <!-- Don't use a static_cast for arithmetic conversions. Use brace initialization, gsl::narrow_cast, or gsl::narrow. -->
78+
<Rule Id="C26473" Action="None" /> <!-- Don't cast between pointer types where the source type and the target type are the same -->
79+
<Rule Id="C26474" Action="None" /> <!-- Use implicit conversion -->
7780
<Rule Id="C26475" Action="Error" />
78-
<Rule Id="C26476" Action="Error" />
81+
<Rule Id="C26476" Action="None" /> <!-- Expression/symbol 'name' uses a naked union 'union' with multiple type pointers: Use variant instead -->
7982
<Rule Id="C26477" Action="Error" />
80-
<Rule Id="C26481" Action="Error" />
81-
<Rule Id="C26482" Action="Error" />
83+
<Rule Id="C26478" Action="None" /> <!-- Don't use std::move on constant variables. -->
84+
<Rule Id="C26481" Action="None" /> <!-- Don't use pointer arithmetic. Use span instead -->
85+
<Rule Id="C26482" Action="None" /> <!-- Only index into arrays using constant expressions. -->
8286
<Rule Id="C26483" Action="Error" />
83-
<Rule Id="C26485" Action="Error" />
84-
<Rule Id="C26486" Action="None" />
85-
<Rule Id="C26487" Action="Error" />
86-
<Rule Id="C26489" Action="None" />
87-
<Rule Id="C26490" Action="Error" />
87+
<Rule Id="C26485" Action="None" /> <!-- Expression 'array-name': No array to pointer decay -->
88+
<Rule Id="C26486" Action="None" /> <!-- Don't pass a pointer that may be invalid (dangling) as a parameter to a function. -->
89+
<Rule Id="C26487" Action="None" /> <!-- Don't allow a function to return an invalid pointer, either through a formal return statement or through output parameters. -->
90+
<Rule Id="C26489" Action="None" /> <!-- Don't dereference a pointer that may be invalid. -->
91+
<Rule Id="C26490" Action="None" /> <!-- Don't use reinterpret_cast. -->
8892
<Rule Id="C26491" Action="Error" />
89-
<Rule Id="C26492" Action="Error" />
90-
<Rule Id="C26493" Action="Error" />
91-
<Rule Id="C26494" Action="Error" />
92-
<Rule Id="C26495" Action="Error" />
93-
<Rule Id="C26496" Action="Error" />
94-
<Rule Id="C26497" Action="Error" />
93+
<Rule Id="C26492" Action="None" /> <!-- Don't use const_cast to cast away const. -->
94+
<Rule Id="C26493" Action="None" /> <!-- Don't use C-style casts. -->
95+
<Rule Id="C26494" Action="None" /> <!-- Variable 'variable' is uninitialized. Always initialize an object. -->
96+
<Rule Id="C26495" Action="None" /> <!-- Variable 'variable' is uninitialized. Always initialize a member variable -->
97+
<Rule Id="C26496" Action="None" /> <!-- The variable 'variable' is assigned only once, mark it as const. -->
98+
<Rule Id="C26497" Action="None" /> <!-- Attempt to make this constexpr -->
9599
<Rule Id="C26498" Action="Error" />
96-
<Rule Id="C28020" Action="Error" />
100+
<Rule Id="C26814" Action="None" /> <!-- The const variable 'variable' can be computed at compile time. Consider using constexpr -->
101+
<Rule Id="C26818" Action="None" /> <!-- Switch statement does not cover all cases. Consider adding a 'default' label -->
102+
<Rule Id="C26819" Action="None" /> <!-- Unannotated fallthrough -->
103+
<Rule Id="C26826" Action="None" /> <!-- Don't use C-style variable arguments -->
104+
<Rule Id="C26859" Action="None" /> <!-- Empty optional '<var>' is unwrapped, will throw exception. -->
105+
<Rule Id="C28020" Action="None" /> <!-- The expression 'expr' is not true at this call -->
97106
<Rule Id="C28021" Action="Error" />
98107
<Rule Id="C28022" Action="Error" />
99108
<Rule Id="C28023" Action="Error" />
@@ -142,7 +151,7 @@
142151
<Rule Id="C28156" Action="Error" />
143152
<Rule Id="C28157" Action="Error" />
144153
<Rule Id="C28158" Action="Error" />
145-
<Rule Id="C28159" Action="Error" />
154+
<Rule Id="C28159" Action="None" /> <!-- Consider using *function_name_1* instead of *function_name_2*. -->
146155
<Rule Id="C28160" Action="Error" />
147156
<Rule Id="C28161" Action="Error" />
148157
<Rule Id="C28162" Action="Error" />
@@ -213,9 +222,9 @@
213222
<Rule Id="C28245" Action="Error" />
214223
<Rule Id="C28246" Action="Error" />
215224
<Rule Id="C28250" Action="Error" />
216-
<Rule Id="C28251" Action="Error" />
217-
<Rule Id="C28252" Action="Error" />
218-
<Rule Id="C28253" Action="Error" />
225+
<Rule Id="C28251" Action="None" /> <!-- Inconsistent annotation for function: this instance has an error -->
226+
<Rule Id="C28252" Action="None" /> <!-- Inconsistent annotation for '<func>': <param> has '<annotation>' on the prior instance. -->
227+
<Rule Id="C28253" Action="None" /> <!-- Inconsistent annotation for '<func>': <param> has '<annotations>' on this instance -->
219228
<Rule Id="C28254" Action="Error" />
220229
<Rule Id="C28260" Action="Error" />
221230
<Rule Id="C28262" Action="Error" />
@@ -239,7 +248,7 @@
239248
<Rule Id="C28290" Action="Error" />
240249
<Rule Id="C28291" Action="Error" />
241250
<Rule Id="C28300" Action="Error" />
242-
<Rule Id="C28301" Action="Error" />
251+
<Rule Id="C28301" Action="None" /> <!-- No annotations for first declaration -->
243252
<Rule Id="C28302" Action="Error" />
244253
<Rule Id="C28303" Action="Error" />
245254
<Rule Id="C28304" Action="Error" />
@@ -282,19 +291,19 @@
282291
<Rule Id="C28736" Action="Error" />
283292
<Rule Id="C28750" Action="Error" />
284293
<Rule Id="C28751" Action="Error" />
285-
<Rule Id="C6001" Action="Error" />
286-
<Rule Id="C6011" Action="Error" />
294+
<Rule Id="C6001" Action="None" /> <!-- uninitialized memory -->
295+
<Rule Id="C6011" Action="None" /> <!-- Possible null deref -->
287296
<Rule Id="C6014" Action="Error" />
288297
<Rule Id="C6029" Action="Error" />
289-
<Rule Id="C6031" Action="Error" />
298+
<Rule Id="C6031" Action="None" /> <!-- Return value ignored: '<func>'. -->
290299
<Rule Id="C6053" Action="Error" />
291-
<Rule Id="C6054" Action="Error" />
300+
<Rule Id="C6054" Action="None" /> <!-- String '<var>' might not be zero-terminated. -->
292301
<Rule Id="C6059" Action="Error" />
293302
<Rule Id="C6063" Action="Error" />
294303
<Rule Id="C6064" Action="Error" />
295304
<Rule Id="C6066" Action="Error" />
296305
<Rule Id="C6067" Action="Error" />
297-
<Rule Id="C6101" Action="Error" />
306+
<Rule Id="C6101" Action="None" /> <!-- Returning uninitialized memory -->
298307
<Rule Id="C6200" Action="Error" />
299308
<Rule Id="C6201" Action="Error" />
300309
<Rule Id="C6211" Action="Error" />
@@ -319,7 +328,7 @@
319328
<Rule Id="C6248" Action="Error" />
320329
<Rule Id="C6250" Action="Error" />
321330
<Rule Id="C6255" Action="Error" />
322-
<Rule Id="C6258" Action="Error" />
331+
<Rule Id="C6258" Action="None" /> <!-- Using TerminateThread does not allow proper thread clean up. -->
323332
<Rule Id="C6259" Action="Error" />
324333
<Rule Id="C6260" Action="Error" />
325334
<Rule Id="C6262" Action="Error" />
@@ -338,7 +347,7 @@
338347
<Rule Id="C6280" Action="Error" />
339348
<Rule Id="C6281" Action="Error" />
340349
<Rule Id="C6282" Action="Error" />
341-
<Rule Id="C6283" Action="Error" />
350+
<Rule Id="C6283" Action="None" /> <!-- array new with scalar delete -->
342351
<Rule Id="C6284" Action="Error" />
343352
<Rule Id="C6285" Action="Error" />
344353
<Rule Id="C6286" Action="Error" />
@@ -383,14 +392,14 @@
383392
<Rule Id="C6334" Action="Error" />
384393
<Rule Id="C6335" Action="Error" />
385394
<Rule Id="C6336" Action="Error" />
386-
<Rule Id="C6340" Action="Error" />
395+
<Rule Id="C6340" Action="None" /> <!-- sign mismatch -->
387396
<Rule Id="C6381" Action="Error" />
388397
<Rule Id="C6383" Action="Error" />
389398
<Rule Id="C6384" Action="Error" />
390-
<Rule Id="C6385" Action="Error" />
391-
<Rule Id="C6386" Action="Error" />
392-
<Rule Id="C6387" Action="Error" />
393-
<Rule Id="C6388" Action="Error" />
399+
<Rule Id="C6385" Action="None" /> <!-- Reading invalid data -->
400+
<Rule Id="C6386" Action="None" /> <!-- Overrun -->
401+
<Rule Id="C6387" Action="None" /> <!-- '<expr>' could be '<val>': this does not adhere to the specification for the function '<func>' -->
402+
<Rule Id="C6388" Action="None" /> <!-- '<var>' might not be '<val>': this does not adhere to the specification for the function '<func>' -->
394403
<Rule Id="C6400" Action="Error" />
395404
<Rule Id="C6401" Action="Error" />
396405
<Rule Id="C6411" Action="Error" />
@@ -418,6 +427,7 @@
418427
<Rule Id="C6540" Action="Error" />
419428
<Rule Id="C6551" Action="Error" />
420429
<Rule Id="C6552" Action="Error" />
430+
<Rule Id="C6553" Action="None" /> <!-- Annotation does not apply to a value type -->
421431
<Rule Id="C6701" Action="Error" />
422432
<Rule Id="C6702" Action="Error" />
423433
<Rule Id="C6703" Action="Error" />

0 commit comments

Comments
 (0)