Skip to content

Commit 46cb683

Browse files
authored
Merge pull request #4535 from MugBergerFries/patch-13
Updated C6504, C28285
2 parents b0565fc + 6b12f86 commit 46cb683

File tree

2 files changed

+30
-28
lines changed

2 files changed

+30
-28
lines changed

docs/code-quality/c28285.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
11
---
22
description: "Learn more about: C28285"
33
title: C28285
4-
ms.date: 12/17/2019
4+
ms.date: 09/22/2022
55
ms.topic: reference
6-
f1_keywords: ["C28285"]
6+
f1_keywords: ["C28285", "SPEC_INVALID_SYNTAX2", "__WARNING_SPEC_INVALID_SYNTAX2"]
77
helpviewer_keywords: ["C28285"]
88
ms.assetid: 6197eb0f-7e1e-4c3e-b097-1f6481405994
99
---
10-
# C28285
10+
# Warning C28285
1111

12-
> warning C28285: For function 'function_name', syntax error in 'annotation'
12+
> For function '*function-name*', syntax error in '*annotation*'
1313
14-
The Code Analysis tool reports this warning for syntax errors in the SAL annotation. The SAL parser will recover by discarding the malformed annotation.
14+
## Remarks
15+
16+
The Code Analysis tool reports this warning for syntax errors in the SAL annotation. The SAL parser will recover by discarding the malformed annotation. Double check the documentation for the SAL annotations being used and try to simplify the annotation. You shouldn't use implementation layer annotations such as `__declspec("SAL_begin")` directly. If you're using that layer, then change them into higher layers such as `_In_`/`_Out_`/`_Ret_`. For more information, see [Annotating Function Parameters and Return Values](annotating-function-parameters-and-return-values.md).
1517

1618
## Example
1719

20+
The following code generates this warning. The argument `(2,n)` is malformed and will cause a C28285 warning after the `_Out_writes_z_` macro is expanded.
21+
1822
```cpp
19-
// The argument '(n,2)' is malformed and will cause a C28285 warning after the _Out_writes_z_ macro is expanded.
2023
void example_func(_Out_writes_z_((2,n)) char* buffer, int n)
2124
{
22-
// ...
23-
buffer[n] = '\0';
25+
buffer[n] = '\0';
2426
}
2527
```
2628
27-
Double check the documentation to the SAL annotations being used and try to simplify the annotation. You should not use implementation layer annotations such as `__declspec("SAL_begin")` directly. If you are using that layer then change them into higher layers such as `_In_`/`_Out_`/`_Ret_`. See [Annotating Function Parameters and Return Values](annotating-function-parameters-and-return-values.md) for more information.
29+
The following code remediates this warning by correcting the malformed annotation
2830
2931
```cpp
3032
void example_func(_Out_writes_z_(n) char* buffer, int n)
3133
{
32-
// ...
33-
buffer[n] = '\0';
34+
buffer[n] = '\0';
3435
}
3536
```
37+

docs/code-quality/c6504.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
11
---
22
description: "Learn more about: C6504"
33
title: C6504
4-
ms.date: 12/19/2019
4+
ms.date: 09/22/2022
55
ms.topic: reference
6-
f1_keywords: ["C6504"]
6+
f1_keywords: ["C6504", "NULL_ON_NON_POINTER", "__WARNING_NULL_ON_NON_POINTER"]
77
helpviewer_keywords: ["C6504"]
88
ms.assetid: 6baeed46-e73d-4974-af16-7487c55b3473
99
---
1010
# C6504
1111

12-
> warning C6504: invalid annotation: property may only be used on values of pointer, pointer-to-member, or array type
12+
> Invalid annotation: property may only be used on values of pointer, pointer-to-member, or array type
1313
14-
This warning indicates the use of a pointer-specific SAL annotation on a non-pointer data type. For more information about what data types are supported by properties, see [Annotation Properties](using-sal-annotations-to-reduce-c-cpp-code-defects.md).
14+
This warning indicates the use of a pointer-specific SAL annotation on a non-pointer data type.
15+
16+
## Remarks
17+
18+
For more information about what data types are supported by properties, see [Annotation Properties](using-sal-annotations-to-reduce-c-cpp-code-defects.md).
19+
20+
Code analysis name: NULL_ON_NON_POINTER
1521

1622
## Example
1723

18-
```cpp
19-
#include<sal.h>
24+
The following code generates this warning. This issue stems from the use of the pointer-specific `_Maybenull_` and `_Notnull_` on reference `pt`.
2025

26+
```cpp
2127
class Point
2228
{
23-
public:
24-
// members
29+
public:
30+
// members
2531
};
2632

27-
// Oops, according to this annotation, pt may be null which does not make sense for a reference types
2833
void f(_Pre_ _Maybenull_ Point& pt)
2934
{
3035
// code ...
3136
}
3237

33-
// Oops, according to this annotation, pt cannot be null which does not make sense for a reference types
3438
void g(_Pre_ _Notnull_ Point& pt)
3539
{
3640
// code ...
3741
}
3842
```
3943
40-
To correct this warning remove the annotation if it does not make sense. You could also change to an annotation to be applicable to the type used, or change to type to match the annotation.
44+
To correct this warning, remove the annotation if it doesn't make sense. You could also change to an annotation to be applicable to the type used, or change the type to match the annotation. The following code remediates this warning by changing the first instance of `pt` to a pointer and by removing the second annotation to match the reference type.
4145
4246
```cpp
43-
#include<sal.h>
44-
4547
class Point
4648
{
47-
public:
48-
// members
49+
public:
50+
// members
4951
};
5052
51-
// Changed to pointer type because it may be null
5253
void f(_Pre_ _Maybenull_ Point* pt)
5354
{
5455
// code ...
5556
}
5657
57-
// Removed annotation because it did not apply to reference types.
5858
void g(Point& pt)
5959
{
6060
// code ...

0 commit comments

Comments
 (0)