From 8854eee224bf457f920c42e4b3223cb91c884f54 Mon Sep 17 00:00:00 2001 From: Phil Christensen Date: Tue, 11 Feb 2025 11:53:44 -0800 Subject: [PATCH 01/14] Learn Editor: Update c26132.md --- docs/code-quality/c26132.md | 15 +++++++++++++++ docs/code-quality/toc.yml | 3 +++ 2 files changed, 18 insertions(+) create mode 100644 docs/code-quality/c26132.md diff --git a/docs/code-quality/c26132.md b/docs/code-quality/c26132.md new file mode 100644 index 00000000000..5f452351b83 --- /dev/null +++ b/docs/code-quality/c26132.md @@ -0,0 +1,15 @@ +--- +# Required metadata +# For more information, see https://review.learn.microsoft.com/en-us/help/platform/learn-editor-add-metadata?branch=main +# For valid values of ms.service, ms.prod, and ms.topic, see https://review.learn.microsoft.com/en-us/help/platform/metadata-taxonomies?branch=main + +title: # Add a title for the browser tab +description: # Add a meaningful description for search results +author: Rastaban # GitHub alias +ms.author: philc # Microsoft alias +ms.service: # Add the ms.service or ms.prod value +# ms.prod: # To use ms.prod, uncomment it and delete ms.service +ms.topic: # Add the ms.topic value +ms.date: 02/11/2025 +--- +Warning C26132 \ No newline at end of file diff --git a/docs/code-quality/toc.yml b/docs/code-quality/toc.yml index b22549c06f7..015c145a85c 100644 --- a/docs/code-quality/toc.yml +++ b/docs/code-quality/toc.yml @@ -591,6 +591,9 @@ items: href: ../code-quality/c26117.md - name: Warning C26130 href: ../code-quality/c26130.md + - name: Warning C26132 + href: c26132.md + displayName: C26132 - name: Warning C26135 href: ../code-quality/c26135.md - name: Warning C26138 From 10e9567bd3c2c6b732d9916b2dfb8276652e6b83 Mon Sep 17 00:00:00 2001 From: Phil Christensen Date: Tue, 11 Feb 2025 12:28:05 -0800 Subject: [PATCH 02/14] Learn Editor: Update c26132.md --- docs/code-quality/c26132.md | 63 ++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/docs/code-quality/c26132.md b/docs/code-quality/c26132.md index 5f452351b83..db0a47e07c1 100644 --- a/docs/code-quality/c26132.md +++ b/docs/code-quality/c26132.md @@ -12,4 +12,65 @@ ms.service: # Add the ms.service or ms.prod value ms.topic: # Add the ms.topic value ms.date: 02/11/2025 --- -Warning C26132 \ No newline at end of file +# Warning C26132 + +> Variable '*variable name*' should be protected by '*lock 1*', but '*lock 2*' is held instead. Possible annotation mismatch. + +Warning C26132 is issued when the analyzer detects that the lock that is annotated to protect a value is not held when the value is accessed. 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. + +## Examples + +In the following example, C26132 is emitted when `data` is used. + +> warning C26132: Variable 'data' should be protected by 'customLock01', but '(&customLock01)->cs' is held instead. Possible annotation mismatch. + + The variable `data` is annotated to be protected by `customLock01`, but the locking function `CustomLockAcquire` is annotated to acquire the related lock `customLock01->cs`. + +```cpp +#include +struct CustomLock { + int cs; // "Critical Section" lock +}; + +_Acquires_exclusive_lock_(criticalSection->cs) // notice the `->` indirection +void CustomLockAcquire(CustomLock* criticalSection); + +_Releases_lock_(criticalSection->cs) // notice the `->` indirection +void CustomLockRelease(CustomLock* criticalSection); + +// global lock +CustomLock customLock01; + +void Initialize(_Guarded_by_(customLock01) int* data) +{ + CustomLockAcquire(&customLock01); + *data = 1; // C26132 + CustomLockRelease(&customLock01); +} +``` + +In this example the `Initialize` 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 `_Guarded_by_` annotation from `customLock01` to `customLock01.cs`. + +```cpp +#include +struct CustomLock { + int cs; // "Critical Section" lock +}; + +_Acquires_exclusive_lock_(criticalSection) +void CustomLockAcquire(CustomLock* criticalSection); + +_Releases_lock_(criticalSection) +void CustomLockRelease(CustomLock* criticalSection); + +// global lock +CustomLock customLock01; + +void Initialize(_Guarded_by_(customLock01) int* data) +{ + CustomLockAcquire(&customLock01); + *data = 1; + CustomLockRelease(&customLock01); +} +``` + From 45df304bf9365d38eeff826c2257e0903225f85e Mon Sep 17 00:00:00 2001 From: Phil Christensen Date: Tue, 11 Feb 2025 12:28:14 -0800 Subject: [PATCH 03/14] update Metadata --- docs/code-quality/c26132.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/docs/code-quality/c26132.md b/docs/code-quality/c26132.md index db0a47e07c1..9baac40db65 100644 --- a/docs/code-quality/c26132.md +++ b/docs/code-quality/c26132.md @@ -3,13 +3,12 @@ # For more information, see https://review.learn.microsoft.com/en-us/help/platform/learn-editor-add-metadata?branch=main # For valid values of ms.service, ms.prod, and ms.topic, see https://review.learn.microsoft.com/en-us/help/platform/metadata-taxonomies?branch=main -title: # Add a title for the browser tab -description: # Add a meaningful description for search results +title: Warning C26132 +description: Documentation on static analysis warning C26132 author: Rastaban # GitHub alias ms.author: philc # Microsoft alias -ms.service: # Add the ms.service or ms.prod value -# ms.prod: # To use ms.prod, uncomment it and delete ms.service -ms.topic: # Add the ms.topic value +ms.service: visual-cpp +ms.topic: article ms.date: 02/11/2025 --- # Warning C26132 From 304b8cb5068b876f0ecc88fb1ded7b77ad3bbc75 Mon Sep 17 00:00:00 2001 From: Phil Christensen Date: Tue, 11 Feb 2025 12:31:52 -0800 Subject: [PATCH 04/14] Learn Editor: Update c26133.md --- docs/code-quality/c26133.md | 15 +++++++++++++++ docs/code-quality/toc.yml | 3 +++ 2 files changed, 18 insertions(+) create mode 100644 docs/code-quality/c26133.md diff --git a/docs/code-quality/c26133.md b/docs/code-quality/c26133.md new file mode 100644 index 00000000000..a924afd7f29 --- /dev/null +++ b/docs/code-quality/c26133.md @@ -0,0 +1,15 @@ +--- +# Required metadata +# For more information, see https://review.learn.microsoft.com/en-us/help/platform/learn-editor-add-metadata?branch=main +# For valid values of ms.service, ms.prod, and ms.topic, see https://review.learn.microsoft.com/en-us/help/platform/metadata-taxonomies?branch=main + +title: # Add a title for the browser tab +description: # Add a meaningful description for search results +author: Rastaban # GitHub alias +ms.author: philc # Microsoft alias +ms.service: # Add the ms.service or ms.prod value +# ms.prod: # To use ms.prod, uncomment it and delete ms.service +ms.topic: # Add the ms.topic value +ms.date: 02/11/2025 +--- +Warning C26133 \ No newline at end of file diff --git a/docs/code-quality/toc.yml b/docs/code-quality/toc.yml index 015c145a85c..823bf4e3a75 100644 --- a/docs/code-quality/toc.yml +++ b/docs/code-quality/toc.yml @@ -594,6 +594,9 @@ items: - name: Warning C26132 href: c26132.md displayName: C26132 + - name: Warning C26133 + href: c26133.md + displayName: C26133 - name: Warning C26135 href: ../code-quality/c26135.md - name: Warning C26138 From 51ebfe10d56ae8e42c5870cb05214cbc1a9fc608 Mon Sep 17 00:00:00 2001 From: Phil Christensen Date: Tue, 11 Feb 2025 13:35:33 -0800 Subject: [PATCH 05/14] Learn Editor: Update c26133.md --- docs/code-quality/c26133.md | 64 ++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/docs/code-quality/c26133.md b/docs/code-quality/c26133.md index a924afd7f29..3c7661b4ab9 100644 --- a/docs/code-quality/c26133.md +++ b/docs/code-quality/c26133.md @@ -12,4 +12,66 @@ ms.service: # Add the ms.service or ms.prod value ms.topic: # Add the ms.topic value ms.date: 02/11/2025 --- -Warning C26133 \ No newline at end of file +# Warning C26133 + +> Caller failing to hold lock '*lock 1*' before calling function '*function name*', but '*lock 2*' is held instead. Possible annotation mismatch. + +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. + +## Examples + +In the following example, C26133 is emitted when `DoTaskWithCustomLock` is called. + +> warning C26133: Caller failing to hold lock 'customLock01' before calling function 'DoTaskWithCustomLock', but '(&customLock01)->cs' is held instead. Possible annotation mismatch. + +```cpp +#include + +struct CustomLock { + int cs; // "Critical Section" +}; + +_Acquires_exclusive_lock_(criticalSection->cs) // notice the `->` indirection +void CustomLockAcquire(CustomLock* criticalSection); + +_Releases_lock_(criticalSection->cs) // notice the `->` indirection +void CustomLockRelease(CustomLock* criticalSection); + +CustomLock customLock01; + +_Requires_lock_held_(customLock01) void DoTaskWithCustomLock(); + +void DoTask() +{ + CustomLockAcquire(&customLock01); + DoTaskWithCustomLock(); // C26133 + CustomLockRelease(&customLock01); +} +``` + +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`. + +```cpp +#include + +struct CustomLock { + int cs; // "Critical Section" +}; + +_Acquires_exclusive_lock_(criticalSection) +void CustomLockAcquire(CustomLock* criticalSection); + +_Releases_lock_(criticalSection) +void CustomLockRelease(CustomLock* criticalSection); + +CustomLock customLock01; + +_Requires_lock_held_(customLock01) void DoTaskWithCustomLock(); + +void DoTask() +{ + CustomLockAcquire(&customLock01); + DoTaskWithCustomLock(); + CustomLockRelease(&customLock01); +} +``` \ No newline at end of file From dd93484b68362aaafc87f9835243ab1d0e45af9e Mon Sep 17 00:00:00 2001 From: Phil Christensen Date: Tue, 11 Feb 2025 13:35:41 -0800 Subject: [PATCH 06/14] update Metadata --- docs/code-quality/c26133.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/docs/code-quality/c26133.md b/docs/code-quality/c26133.md index 3c7661b4ab9..bdd658d37df 100644 --- a/docs/code-quality/c26133.md +++ b/docs/code-quality/c26133.md @@ -3,13 +3,12 @@ # For more information, see https://review.learn.microsoft.com/en-us/help/platform/learn-editor-add-metadata?branch=main # For valid values of ms.service, ms.prod, and ms.topic, see https://review.learn.microsoft.com/en-us/help/platform/metadata-taxonomies?branch=main -title: # Add a title for the browser tab -description: # Add a meaningful description for search results +title: Warning C26133 +description: Documentation on static analysis warning C26133 author: Rastaban # GitHub alias ms.author: philc # Microsoft alias -ms.service: # Add the ms.service or ms.prod value -# ms.prod: # To use ms.prod, uncomment it and delete ms.service -ms.topic: # Add the ms.topic value +ms.service: visual-cpp +ms.topic: article ms.date: 02/11/2025 --- # Warning C26133 From 6d4bf752b3bc8e726c0d84f17d1e79d1c274a832 Mon Sep 17 00:00:00 2001 From: Phil Christensen Date: Wed, 12 Feb 2025 13:58:35 -0800 Subject: [PATCH 07/14] Remove displayName fields from toc.yml --- docs/code-quality/toc.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/code-quality/toc.yml b/docs/code-quality/toc.yml index 823bf4e3a75..fecfcb69813 100644 --- a/docs/code-quality/toc.yml +++ b/docs/code-quality/toc.yml @@ -593,10 +593,8 @@ items: href: ../code-quality/c26130.md - name: Warning C26132 href: c26132.md - displayName: C26132 - name: Warning C26133 href: c26133.md - displayName: C26133 - name: Warning C26135 href: ../code-quality/c26135.md - name: Warning C26138 From 780f6007ba8e64df2c9fcfd834e9bf01d3b2f6e6 Mon Sep 17 00:00:00 2001 From: Phil Christensen Date: Wed, 12 Feb 2025 13:59:39 -0800 Subject: [PATCH 08/14] Fix relative links in toc.yml file --- docs/code-quality/toc.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/code-quality/toc.yml b/docs/code-quality/toc.yml index fecfcb69813..61bafc57ca1 100644 --- a/docs/code-quality/toc.yml +++ b/docs/code-quality/toc.yml @@ -638,9 +638,9 @@ items: - name: Warning C26831 href: ../code-quality/c26831.md - name: Warning C26838 - href: c26838.md + href: ../code-quality/c26838.md - name: Warning C26839 - href: c26839.md + href: ../code-quality/c26839.md - name: Warning C26832 href: ../code-quality/c26832.md - name: Warning C26833 From 41d118f18d19fc1982c3a8475458b65a804470d5 Mon Sep 17 00:00:00 2001 From: Phil Christensen Date: Wed, 19 Feb 2025 11:33:35 -0800 Subject: [PATCH 09/14] Remove metadata comments and fix formatting in docs --- docs/code-quality/c26132.md | 18 +++++++----------- docs/code-quality/c26133.md | 16 +++++++--------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/docs/code-quality/c26132.md b/docs/code-quality/c26132.md index 9baac40db65..95dfdb1f1fd 100644 --- a/docs/code-quality/c26132.md +++ b/docs/code-quality/c26132.md @@ -1,12 +1,8 @@ --- -# Required metadata -# For more information, see https://review.learn.microsoft.com/en-us/help/platform/learn-editor-add-metadata?branch=main -# For valid values of ms.service, ms.prod, and ms.topic, see https://review.learn.microsoft.com/en-us/help/platform/metadata-taxonomies?branch=main - title: Warning C26132 description: Documentation on static analysis warning C26132 -author: Rastaban # GitHub alias -ms.author: philc # Microsoft alias +author: Rastaban +ms.author: philc ms.service: visual-cpp ms.topic: article ms.date: 02/11/2025 @@ -21,13 +17,12 @@ Warning C26132 is issued when the analyzer detects that the lock that is annotat In the following example, C26132 is emitted when `data` is used. -> warning C26132: Variable 'data' should be protected by 'customLock01', but '(&customLock01)->cs' is held instead. Possible annotation mismatch. - The variable `data` is annotated to be protected by `customLock01`, but the locking function `CustomLockAcquire` is annotated to acquire the related lock `customLock01->cs`. ```cpp #include -struct CustomLock { +struct CustomLock +{ int cs; // "Critical Section" lock }; @@ -48,11 +43,12 @@ void Initialize(_Guarded_by_(customLock01) int* data) } ``` -In this example the `Initialize` 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 `_Guarded_by_` annotation from `customLock01` to `customLock01.cs`. +In this example, the `Initialize` 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 `_Guarded_by_` annotation from `customLock01` to `customLock01.cs`. ```cpp #include -struct CustomLock { +struct CustomLock +{ int cs; // "Critical Section" lock }; diff --git a/docs/code-quality/c26133.md b/docs/code-quality/c26133.md index bdd658d37df..f6a7bc90a9d 100644 --- a/docs/code-quality/c26133.md +++ b/docs/code-quality/c26133.md @@ -1,12 +1,8 @@ --- -# Required metadata -# For more information, see https://review.learn.microsoft.com/en-us/help/platform/learn-editor-add-metadata?branch=main -# For valid values of ms.service, ms.prod, and ms.topic, see https://review.learn.microsoft.com/en-us/help/platform/metadata-taxonomies?branch=main - title: Warning C26133 description: Documentation on static analysis warning C26133 -author: Rastaban # GitHub alias -ms.author: philc # Microsoft alias +author: Rastaban +ms.author: philc ms.service: visual-cpp ms.topic: article ms.date: 02/11/2025 @@ -26,7 +22,8 @@ In the following example, C26133 is emitted when `DoTaskWithCustomLock` is calle ```cpp #include -struct CustomLock { +struct CustomLock +{ int cs; // "Critical Section" }; @@ -48,12 +45,13 @@ void DoTask() } ``` -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`. +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`. ```cpp #include -struct CustomLock { +struct CustomLock +{ int cs; // "Critical Section" }; From 40e13d2a28e210fbdca4d52bb2c152348e0c7dfd Mon Sep 17 00:00:00 2001 From: Tyler Whitney Date: Wed, 19 Feb 2025 13:52:46 -0800 Subject: [PATCH 10/14] Fix typo and update ms.date in c26133.md --- docs/code-quality/c26133.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/code-quality/c26133.md b/docs/code-quality/c26133.md index f6a7bc90a9d..0e760a8154f 100644 --- a/docs/code-quality/c26133.md +++ b/docs/code-quality/c26133.md @@ -5,13 +5,13 @@ author: Rastaban ms.author: philc ms.service: visual-cpp ms.topic: article -ms.date: 02/11/2025 +ms.date: 02/19/2025 --- # Warning C26133 > Caller failing to hold lock '*lock 1*' before calling function '*function name*', but '*lock 2*' is held instead. Possible annotation mismatch. -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. +Warning C26133 is issued when the analyzer detects that the lock that is required to call a function isn't 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. ## Examples From 66c3e692b320094a3331b41bf963b815412c264a Mon Sep 17 00:00:00 2001 From: Tyler Whitney Date: Wed, 19 Feb 2025 16:36:46 -0800 Subject: [PATCH 11/14] fix acrolinx errors by rewriting in active voice --- docs/code-quality/c26132.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/code-quality/c26132.md b/docs/code-quality/c26132.md index 95dfdb1f1fd..969f5847b76 100644 --- a/docs/code-quality/c26132.md +++ b/docs/code-quality/c26132.md @@ -11,13 +11,13 @@ ms.date: 02/11/2025 > Variable '*variable name*' should be protected by '*lock 1*', but '*lock 2*' is held instead. Possible annotation mismatch. -Warning C26132 is issued when the analyzer detects that the lock that is annotated to protect a value is not held when the value is accessed. 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. +The analyzer issues Warning C26132 when it detects that a lock, which is annotated to protect a value, isn't held while accessing the value. However, a related lock is held. The code may be thread-safe, so you might need to update the annotations. ## Examples In the following example, C26132 is emitted when `data` is used. - The variable `data` is annotated to be protected by `customLock01`, but the locking function `CustomLockAcquire` is annotated to acquire the related lock `customLock01->cs`. + The annotation specifies that `customLock01` should protect the variable `data`, but `CustomLockAcquire` is responsible for acquiring the related lock `customLock01->cs`. ```cpp #include @@ -43,7 +43,7 @@ void Initialize(_Guarded_by_(customLock01) int* data) } ``` -In this example, the `Initialize` 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 `_Guarded_by_` annotation from `customLock01` to `customLock01.cs`. +In this example, the `Initialize` function is thread-safe and behaves as designed, but that design isn't correctly reflected in the concurrency SAL annotations. Fix by adjusting the annotations on the custom locking functions to use `criticalSection` rather than `criticalSection->cs`. This could also be fixed by changing the `_Guarded_by_` annotation from `customLock01` to `customLock01.cs`. ```cpp #include From e848088c34b623bf12b550fba073e734e6bd7579 Mon Sep 17 00:00:00 2001 From: Tyler Whitney Date: Wed, 19 Feb 2025 16:39:10 -0800 Subject: [PATCH 12/14] acrolinx --- docs/code-quality/c26133.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/code-quality/c26133.md b/docs/code-quality/c26133.md index 0e760a8154f..cdc18a407ee 100644 --- a/docs/code-quality/c26133.md +++ b/docs/code-quality/c26133.md @@ -11,7 +11,7 @@ ms.date: 02/19/2025 > Caller failing to hold lock '*lock 1*' before calling function '*function name*', but '*lock 2*' is held instead. Possible annotation mismatch. -Warning C26133 is issued when the analyzer detects that the lock that is required to call a function isn't 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. +Warning C26133 is issued when the analyzer detects that the lock required to call a function isn't held when the function is called. However, another lock that appears to be related is held. It's possible the code is thread-safe, and the annotations need to be updated. ## Examples @@ -45,7 +45,7 @@ void DoTask() } ``` -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`. +In this example, the `DoTask` function is thread-safe and behaves as designed, but that design isn't correctly reflected in the concurrency SAL annotations. Fix 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`. ```cpp #include From 70cf715d7dfcf2c9beafbf13d5220cad28d4404c Mon Sep 17 00:00:00 2001 From: Phil Christensen Date: Thu, 20 Feb 2025 11:20:01 -0800 Subject: [PATCH 13/14] Add clarification on why this should be fixed by developers --- docs/code-quality/c26132.md | 2 ++ docs/code-quality/c26133.md | 2 ++ 2 files changed, 4 insertions(+) diff --git a/docs/code-quality/c26132.md b/docs/code-quality/c26132.md index 969f5847b76..54dcf037bfc 100644 --- a/docs/code-quality/c26132.md +++ b/docs/code-quality/c26132.md @@ -13,6 +13,8 @@ ms.date: 02/11/2025 The analyzer issues Warning C26132 when it detects that a lock, which is annotated to protect a value, isn't held while accessing the value. However, a related lock is held. The code may be thread-safe, so you might need to update the annotations. +This diagnostic usually does not indicate a bug in the code, but rather a mismatch between the annotations and the actual locking behavior. If this is the case, the diagnostic should be resolved as there may be other static analysis issues that are not being reported due to the inconsistant annotations. + ## Examples In the following example, C26132 is emitted when `data` is used. diff --git a/docs/code-quality/c26133.md b/docs/code-quality/c26133.md index cdc18a407ee..9e4f9ef7465 100644 --- a/docs/code-quality/c26133.md +++ b/docs/code-quality/c26133.md @@ -13,6 +13,8 @@ ms.date: 02/19/2025 Warning C26133 is issued when the analyzer detects that the lock required to call a function isn't held when the function is called. However, another lock that appears to be related is held. It's possible the code is thread-safe, and the annotations need to be updated. +This diagnostic usually does not indicate a bug in the code, but rather a mismatch between the annotations and the actual locking behavior. If this is the case, the diagnostic should be resolved as there may be other static analysis issues that are not being reported due to the inconsistant annotations. + ## Examples In the following example, C26133 is emitted when `DoTaskWithCustomLock` is called. From da1ffe0f3828088c598d751041daf9d42835f476 Mon Sep 17 00:00:00 2001 From: Phil Christensen Date: Thu, 20 Feb 2025 11:27:36 -0800 Subject: [PATCH 14/14] Fix typos and improve clarity in docs --- docs/code-quality/c26132.md | 4 ++-- docs/code-quality/c26133.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/code-quality/c26132.md b/docs/code-quality/c26132.md index 54dcf037bfc..390903a6059 100644 --- a/docs/code-quality/c26132.md +++ b/docs/code-quality/c26132.md @@ -13,7 +13,7 @@ ms.date: 02/11/2025 The analyzer issues Warning C26132 when it detects that a lock, which is annotated to protect a value, isn't held while accessing the value. However, a related lock is held. The code may be thread-safe, so you might need to update the annotations. -This diagnostic usually does not indicate a bug in the code, but rather a mismatch between the annotations and the actual locking behavior. If this is the case, the diagnostic should be resolved as there may be other static analysis issues that are not being reported due to the inconsistant annotations. +This diagnostic usually doesn't indicate a bug in the code, but rather a mismatch between the annotations and the actual locking behavior. If so, the diagnostic should be resolved as there may be other static analysis issues that aren't being reported due to the inconsistent annotations. ## Examples @@ -45,7 +45,7 @@ void Initialize(_Guarded_by_(customLock01) int* data) } ``` -In this example, the `Initialize` function is thread-safe and behaves as designed, but that design isn't correctly reflected in the concurrency SAL annotations. Fix by adjusting the annotations on the custom locking functions to use `criticalSection` rather than `criticalSection->cs`. This could also be fixed by changing the `_Guarded_by_` annotation from `customLock01` to `customLock01.cs`. +In this example, the `Initialize` function is thread-safe and behaves as designed, but that design isn't correctly reflected in the concurrency SAL annotations. Fix by adjusting the annotations on the custom locking functions to use `criticalSection` rather than `criticalSection->cs`. The warning could also be fixed by changing the `_Guarded_by_` annotation from `customLock01` to `customLock01.cs`. ```cpp #include diff --git a/docs/code-quality/c26133.md b/docs/code-quality/c26133.md index 9e4f9ef7465..0074674044e 100644 --- a/docs/code-quality/c26133.md +++ b/docs/code-quality/c26133.md @@ -13,7 +13,7 @@ ms.date: 02/19/2025 Warning C26133 is issued when the analyzer detects that the lock required to call a function isn't held when the function is called. However, another lock that appears to be related is held. It's possible the code is thread-safe, and the annotations need to be updated. -This diagnostic usually does not indicate a bug in the code, but rather a mismatch between the annotations and the actual locking behavior. If this is the case, the diagnostic should be resolved as there may be other static analysis issues that are not being reported due to the inconsistant annotations. +This diagnostic usually doesn't indicate a bug in the code, but rather a mismatch between the annotations and the actual locking behavior. If so, the diagnostic should be resolved as there may be other static analysis issues that aren't being reported due to the inconsistent annotations. ## Examples @@ -47,7 +47,7 @@ void DoTask() } ``` -In this example, the `DoTask` function is thread-safe and behaves as designed, but that design isn't correctly reflected in the concurrency SAL annotations. Fix 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`. +In this example, the `DoTask` function is thread-safe and behaves as designed, but that design isn't correctly reflected in the concurrency SAL annotations. Fix by adjusting the annotations on the custom locking functions to use `criticalSection` rather than `criticalSection->cs`. The warning could also be fixed by changing the `_Requires_lock_held_` annotation from `customLock01` to `customLock01.cs`. ```cpp #include