Skip to content

Repo sync for protected branch #5149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions docs/assembler/masm/extern-masm.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
---
description: "Learn more about: EXTERN"
description: "Learn more about the MASM directive: EXTERN"
title: "EXTERN (MASM)"
ms.date: "12/06/2019"
ms.date: 1/10/2025
helpviewer_keywords: ["EXTERN directive"]
ms.assetid: 667d703d-3aaf-4139-a586-29bc5dab1aff
---
# EXTERN

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

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

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

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

## See also

Expand Down
4 changes: 2 additions & 2 deletions docs/c-runtime-library/link-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ ms.assetid: 05b5a77b-9dd1-494b-ae46-314598c770bb
---
# Link options

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.
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.

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.
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.

| Native and /clr | Pure mode | Description |
|---|---|---|
Expand Down
4 changes: 3 additions & 1 deletion docs/code-quality/c26831.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,6 @@ void foo(int i, int j)
## See also

[`C26832`](c26832.md)\
[`C26833`](c26833.md)
[`C26833`](c26833.md)\
[`C26838`](c26838.md)\
[`C26839`](c26839.md)
62 changes: 62 additions & 0 deletions docs/code-quality/c26838.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
title: Warning C26838
description: Learn about Microsoft C++ code analysis warning C26838.
author: Rastaban
ms.author: philc
ms.topic: reference
ms.date: 1/10/2025
---
# Warning C26838

> Allocation size is the result of a signed to unsigned narrowing conversion that could result in overflow if the signed value is negative.

This warning was added in Visual Studio 2022 version 17.13.

## Remarks

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:

```cpp
void* CustomAlloc(size_t);

int* CreateIntArray(int numberOfElements)
{
int* p = (int*)CustomAlloc(numberOfElements * sizeof(int)); // Warning: C26838

return p;
}
```

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
by `sizeof(int)`. When `numberOfElements` is negative, the resulting value may overflow or have unexpected results when passed to `CustomAlloc`.

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.

This check sometimes fails to recognize that certain checks can prevent overflows because the check is conservative.

## Example

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:

```cpp
void* CustomAlloc(size_t);

int* CreateIntArray(int numberOfElements)
{
if (numberOfElements < 0)
return nullptr;

int* p = (int*)CustomAlloc(numberOfElements * sizeof(int));
// ...
return p;
}
```

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.

## See also

[`C26831`](c26831.md)\
[`C26832`](c26832.md)\
[`C26833`](c26833.md)\
[`C26833`](c26839.md)
53 changes: 53 additions & 0 deletions docs/code-quality/c26839.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
title: Warning C26839
description: Learn about Microsoft C++ code analysis warning C26839.
author: Rastaban
ms.author: philc
ms.topic: reference
ms.date: 1/10/2025
---
# Warning C26839

> 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.

This warning was added in Visual Studio 2022 version 17.13.

## Remarks

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:

```cpp
int* CreateIntArray(int size)
{
int* intArray = new int[size];
return intArray;
}
```

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`.

This check is the same as [`C26838`](c26838.md), but applies only to `new T[]`.

This check sometimes fails to recognize that certain checks can prevent overflows because the check is conservative.

## Example

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:

```cpp
int* CreateIntArray(int size)
{
if (size < 0)
return nullptr;

int* intArray = new int[size];
return intArray;
}
```

## See also

[`C26831`](c26831.md)\
[`C26832`](c26832.md)\
[`C26838`](c26833.md)\
[`C26838`](c26838.md)
4 changes: 4 additions & 0 deletions docs/code-quality/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,10 @@ items:
href: ../code-quality/c26830.md
- name: Warning C26831
href: ../code-quality/c26831.md
- name: Warning C26838
href: c26838.md
- name: Warning C26839
href: c26839.md
- name: Warning C26832
href: ../code-quality/c26832.md
- name: Warning C26833
Expand Down