Skip to content

Commit b5c5b51

Browse files
committed
Include test fix-ups.
1 parent aac5be9 commit b5c5b51

File tree

5 files changed

+10
-7
lines changed

5 files changed

+10
-7
lines changed

docs/sanitizers/error-global-buffer-overflow.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ int main(int argc, char **argv) {
126126
case 'g': return global[one * 11]; //Boom! simple global
127127
case 'c': return C::array[one * 11]; //Boom! class static
128128
case 'f':
129-
static int array[10];
130-
memset(array, 0, 10);
129+
static int array[10] = {};
131130
return array[one * 11]; //Boom! function static
132131
case 'l':
133132
// literal global ptr created by compiler

docs/sanitizers/error-memcpy-param-overlap.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ cl example1.cpp /fsanitize=address /Zi /Oi
3939
devenv /debugexe example1.exe
4040
```
4141

42-
The [/Oi flag](../../build/reference/oi-generate-intrinsic-functions) tells the compiler to treat memcpy and memmove as intrinsic functions. This is necessary because some versions of the standard library implement memcpy and memmove in the same way and ASAN only detects bad code that is actually executed.
42+
The [/Oi flag](../../build/reference/oi-generate-intrinsic-functions) tells the compiler to treat memcpy and memmove as intrinsic functions. This is necessary because some versions of the standard library implement memcpy and memmove in the same way. Because ASAN is a dynamic analysis tool, it only detects errors with an observable runtime effect.
4343

4444
### Resulting error
4545

docs/sanitizers/error-stack-buffer-overflow.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ int main(void) {
9595
Child *c = (Child*)&p;
9696
c->extra_field = 42; // Boom !
9797

98-
return 0;
98+
return (c->extra_field == 42);
9999
}
100100
```
101101

docs/sanitizers/error-stack-buffer-underflow.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ int main() {
3131
To build and test this example, run these commands in a Visual Studio 2019 version 16.9 or later [developer command prompt](../build/building-on-the-command-line.md#developer_command_prompt_shortcuts):
3232

3333
```cmd
34-
cl example1.cpp /fsanitize=address /Zi
34+
cl example1.cpp /fsanitize=address /Zi /Od
3535
devenv /debugexe example1.exe
3636
```
3737

38+
ASAN is a form of dynamic analysis, which means it can only detect bad code that is actually executed. An optimizer will remove the assignment to `buffer[subscript]` because `buffer[subscript]` is never read from. As a result, this example requires the `/Od` flag.
39+
3840
### Resulting error
3941

4042
:::image type="content" source="media/stack-buffer-underflow-example-1.png" alt-text="Screenshot of debugger displaying stack-buffer-underflow error in example 1.":::

docs/sanitizers/error-stack-use-after-return.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ int main() {
3333
foo();
3434
*x = 42; // Boom!
3535

36-
return 0;
36+
return (*x == 42);
3737
}
3838
```
3939

@@ -96,11 +96,13 @@ int main(int argc, char* argv[]) {
9696
To build and test this example, run these commands in a Visual Studio 2019 version 16.9 or later [developer command prompt](../build/building-on-the-command-line.md#developer_command_prompt_shortcuts):
9797
9898
```cmd
99-
cl example2.cpp /fsanitize=address /fsanitize-address-use-after-return /Zi
99+
cl example2.cpp /fsanitize=address /fsanitize-address-use-after-return /Zi /Od
100100
set ASAN_OPTIONS=detect_stack_use_after_return=1
101101
devenv /debugexe example2.exe 1
102102
```
103103

104+
ASAN is a form of dynamic analysis, which means it can only detect bad code that is actually executed. An optimizer may determine that the value of `t[100 + Idx]` or `sink` is never used and elide the assignment. As a result, this example requires the `/Od` flag.
105+
104106
### Resulting error - C++ and templates
105107

106108
:::image type="content" source="media/stack-use-after-return-example-2.png" alt-text="Screenshot of debugger displaying stack-use-after-return error in example 2.":::

0 commit comments

Comments
 (0)