You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/code-quality/c26133.md
+63-1Lines changed: 63 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -12,4 +12,66 @@ ms.service: # Add the ms.service or ms.prod value
12
12
ms.topic: # Add the ms.topic value
13
13
ms.date: 02/11/2025
14
14
---
15
-
Warning C26133
15
+
# Warning C26133
16
+
17
+
> Caller failing to hold lock '*lock 1*' before calling function '*function name*', but '*lock 2*' is held instead. Possible annotation mismatch.
18
+
19
+
Warning C26133is issued when the analyzer detects that the lock that is required to call a function, is not held when the function is called. However, another lock that appears to be related is held. It is possible the code is thread safe, and the annotations need to be updated.
20
+
21
+
## Examples
22
+
23
+
In the following example, C26133 is emitted when `DoTaskWithCustomLock` is called.
24
+
25
+
> warning C26133: Caller failing to hold lock 'customLock01' before calling function 'DoTaskWithCustomLock', but '(&customLock01)->cs' is held instead. Possible annotation mismatch.
26
+
27
+
```cpp
28
+
#include<sal.h>
29
+
30
+
structCustomLock {
31
+
int cs; // "Critical Section"
32
+
};
33
+
34
+
_Acquires_exclusive_lock_(criticalSection->cs) // notice the `->` indirection
In this example the `DoTask` function is thread safe and behaves as designed, but that design is not correctly reflected in the concurrency SAL annotations. This is fixed by adjusting the annotations on the custom locking functions to use `criticalSection` rather than `criticalSection->cs`. This could also be fixed by changing the `_Requires_lock_held_` annotation from `customLock01` to `customLock01.cs`.
0 commit comments