Skip to content

Commit 0a75a74

Browse files
committed
Fix test cases.
1 parent b5c5b51 commit 0a75a74

File tree

4 files changed

+7
-3
lines changed

4 files changed

+7
-3
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,10 @@ 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+
{
129130
static int array[10] = {};
130131
return array[one * 11]; //Boom! function static
132+
}
131133
case 'l':
132134
// literal global ptr created by compiler
133135
const char *str = "0123456789";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public:
8686

8787
class Child : public Parent {
8888
public:
89-
int extra_field;
89+
volatile int extra_field;
9090
};
9191

9292
int main(void) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ This check can slow your application down substantially. Consider the [Clang sum
2121
```cpp
2222
// example1.cpp
2323
// stack-use-after-return error
24-
char* x;
24+
volatile char* x;
2525

2626
void foo() {
2727
char stack_buffer[42];

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,12 @@ void main() {
147147
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):
148148
149149
```cmd
150-
cl example4.cpp /EHsc /fsanitize=address /Zi
150+
cl example4.cpp /EHsc /fsanitize=address /Zi /Od
151151
devenv /debugexe example4.exe
152152
```
153153

154+
ASAN is a form of dynamic analysis, which means it can only detect bad code that is actually executed. An optimizer may propagate the value of `v` in these cases instead of reading from the address stored in `p`. As a result, this example requires the `/Od` flag.
155+
154156
### Resulting error - temporaries
155157

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

0 commit comments

Comments
 (0)