Skip to content

Commit 20177e3

Browse files
Merge pull request #5149 from MicrosoftDocs/main638723899145740799sync_temp
For protected branch, push strategy should use PR and merge to target branch method to work around git push error
2 parents b340aeb + c217be7 commit 20177e3

File tree

6 files changed

+128
-8
lines changed

6 files changed

+128
-8
lines changed

docs/assembler/masm/extern-masm.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
---
2-
description: "Learn more about: EXTERN"
2+
description: "Learn more about the MASM directive: EXTERN"
33
title: "EXTERN (MASM)"
4-
ms.date: "12/06/2019"
4+
ms.date: 1/10/2025
55
helpviewer_keywords: ["EXTERN directive"]
6-
ms.assetid: 667d703d-3aaf-4139-a586-29bc5dab1aff
76
---
87
# EXTERN
98

@@ -17,9 +16,9 @@ Defines one or more external variables, labels, or symbols called *name* whose t
1716

1817
The *language-type* argument is valid in 32-bit MASM only.
1918

20-
The *type* can be [ABS](operator-abs.md), which imports *name* as a constant. Same as [EXTRN](extrn.md).
19+
The *type* can be [`ABS`](operator-abs.md), which imports *name* as a constant. Same as [`EXTRN`](extrn.md).
2120

22-
The *type* can also be PROC, in which case *name* is treated as an external procedure.
21+
The *type* can also be [`PROC`](proc.md), in which case *name* is treated as an external procedure.
2322

2423
## See also
2524

docs/c-runtime-library/link-options.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ ms.assetid: 05b5a77b-9dd1-494b-ae46-314598c770bb
77
---
88
# Link options
99

10-
The CRT lib directory includes several small object files that enable specific CRT features without any code change. These object files are called "link options" since you only have to add them to the linker command line to use them.
10+
The CRT lib directory includes several small object files that enable specific CRT features without code changes. These object files are called "link options" because you only have to add them to the linker command line to use them. To do this from Visual Studio, in the Solution Explorer right-click your project and choose **Properties**. Under **Configuration Properties**, choose **Linker** > **Input** > **Additional Dependencies** and specify the additional items to add to the link command line.
1111

12-
CLR pure mode versions of these objects are deprecated in Visual Studio 2015 and unsupported in Visual Studio 2017. Use the regular versions for native and /clr code.
12+
CLR pure mode versions of these objects are deprecated in Visual Studio 2015 and unsupported in Visual Studio 2017. Use the regular versions for native and `/clr` code.
1313

1414
| Native and /clr | Pure mode | Description |
1515
|---|---|---|

docs/code-quality/c26831.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,6 @@ void foo(int i, int j)
5858
## See also
5959

6060
[`C26832`](c26832.md)\
61-
[`C26833`](c26833.md)
61+
[`C26833`](c26833.md)\
62+
[`C26838`](c26838.md)\
63+
[`C26839`](c26839.md)

docs/code-quality/c26838.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
title: Warning C26838
3+
description: Learn about Microsoft C++ code analysis warning C26838.
4+
author: Rastaban
5+
ms.author: philc
6+
ms.topic: reference
7+
ms.date: 1/10/2025
8+
---
9+
# Warning C26838
10+
11+
> Allocation size is the result of a signed to unsigned narrowing conversion that could result in overflow if the signed value is negative.
12+
13+
This warning was added in Visual Studio 2022 version 17.13.
14+
15+
## Remarks
16+
17+
Reports that the size specified for an allocation may be the result of the conversion of a possibly negative signed value to an unsigned value. For example:
18+
19+
```cpp
20+
void* CustomAlloc(size_t);
21+
22+
int* CreateIntArray(int numberOfElements)
23+
{
24+
int* p = (int*)CustomAlloc(numberOfElements * sizeof(int)); // Warning: C26838
25+
26+
return p;
27+
}
28+
```
29+
30+
The expression `numberOfElements * sizeof(int)`, `numberOfElements` is signed and `sizeof(int)` is unsigned. On 64-bit machines, `numberOfElements` is promoted to an unsigned value when multiplied
31+
by `sizeof(int)`. When `numberOfElements` is negative, the resulting value may overflow or have unexpected results when passed to `CustomAlloc`.
32+
33+
This check applies to common allocation functions like `new`, `malloc`, and `VirtualAlloc`. The check also applies to custom allocator functions that have `alloc` (case insensitive) in the function name.
34+
35+
This check sometimes fails to recognize that certain checks can prevent overflows because the check is conservative.
36+
37+
## Example
38+
39+
To fix the previous code example in which `numberOfElements * sizeof(int)` might overflow due to a negative signed value, introduce a check to ensure it won't. For example:
40+
41+
```cpp
42+
void* CustomAlloc(size_t);
43+
44+
int* CreateIntArray(int numberOfElements)
45+
{
46+
if (numberOfElements < 0)
47+
return nullptr;
48+
49+
int* p = (int*)CustomAlloc(numberOfElements * sizeof(int));
50+
// ...
51+
return p;
52+
}
53+
```
54+
55+
In the previous example, checking for a negative value addresses the `C26832` warning. Depending on the size of the types involved, this check may result in a different warning such as [`C26831`](c26831.md). For example, on a 32-bit system, both `int` and `size_t` are 32 bits, so the result of the multiplication can still overflow without negative values.
56+
57+
## See also
58+
59+
[`C26831`](c26831.md)\
60+
[`C26832`](c26832.md)\
61+
[`C26833`](c26833.md)\
62+
[`C26833`](c26839.md)

docs/code-quality/c26839.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
title: Warning C26839
3+
description: Learn about Microsoft C++ code analysis warning C26839.
4+
author: Rastaban
5+
ms.author: philc
6+
ms.topic: reference
7+
ms.date: 1/10/2025
8+
---
9+
# Warning C26839
10+
11+
> Array new allocation size is the result of a signed to unsigned narrowing conversion that could result in overflow if the signed value is negative.
12+
13+
This warning was added in Visual Studio 2022 version 17.13.
14+
15+
## Remarks
16+
17+
Reports that the size specified for an array `new` allocation may be the result of the conversion of a possibly negative signed value to an unsigned value. For example:
18+
19+
```cpp
20+
int* CreateIntArray(int size)
21+
{
22+
int* intArray = new int[size];
23+
return intArray;
24+
}
25+
```
26+
27+
The expression `new int[size]`, `size` is signed. The compiler converts the signed value to an unsigned value to calculate how many bytes to be allocated for the array. When `size` is negative, the result of that calculation may overflow or have unexpected results when passed to `new`.
28+
29+
This check is the same as [`C26838`](c26838.md), but applies only to `new T[]`.
30+
31+
This check sometimes fails to recognize that certain checks can prevent overflows because the check is conservative.
32+
33+
## Example
34+
35+
To fix the previous code example in which the size calculation might overflow due to a negative signed value, introduce a check to ensure it won't. For example:
36+
37+
```cpp
38+
int* CreateIntArray(int size)
39+
{
40+
if (size < 0)
41+
return nullptr;
42+
43+
int* intArray = new int[size];
44+
return intArray;
45+
}
46+
```
47+
48+
## See also
49+
50+
[`C26831`](c26831.md)\
51+
[`C26832`](c26832.md)\
52+
[`C26838`](c26833.md)\
53+
[`C26838`](c26838.md)

docs/code-quality/toc.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,10 @@ items:
633633
href: ../code-quality/c26830.md
634634
- name: Warning C26831
635635
href: ../code-quality/c26831.md
636+
- name: Warning C26838
637+
href: c26838.md
638+
- name: Warning C26839
639+
href: c26839.md
636640
- name: Warning C26832
637641
href: ../code-quality/c26832.md
638642
- name: Warning C26833

0 commit comments

Comments
 (0)