Skip to content

Commit a0b66b5

Browse files
authored
[compiler-rt][asan][test] Make wchar tests more robust (#163715)
The stack buffer which is used to trigger out of bounds issue doesn't have obervable side effects, so it can easily be optimized by compiler as dead code. Signed-off-by: Maosu Zhao <[email protected]>
1 parent 8ae8737 commit a0b66b5

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

compiler-rt/test/asan/TestCases/wcscat.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
int main() {
1010
const wchar_t *start = L"X means ";
1111
const wchar_t *append = L"dog";
12-
wchar_t goodDst[12];
12+
wchar_t goodArray[12];
13+
wchar_t *volatile goodDst = goodArray;
1314
wcscpy(goodDst, start);
1415
wcscat(goodDst, append);
1516

16-
wchar_t badDst[9];
17+
wchar_t badArray[9];
18+
wchar_t *volatile badDst = badArray;
1719
wcscpy(badDst, start);
1820
fprintf(stderr, "Good so far.\n");
1921
// CHECK-DAG: Good so far.

compiler-rt/test/asan/TestCases/wcscpy.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88

99
int main() {
1010
const wchar_t *src = L"X means dog";
11-
wchar_t goodDst[12];
11+
wchar_t goodArray[12];
12+
wchar_t *volatile goodDst = goodArray;
1213
wcscpy(goodDst, src);
1314

14-
wchar_t badDst[7];
15+
wchar_t badArray[7];
16+
wchar_t *volatile badDst = badArray;
1517
fprintf(stderr, "Good so far.\n");
1618
// CHECK-DAG: Good so far.
1719
fflush(stderr);

compiler-rt/test/asan/TestCases/wcsncat.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
int main() {
1010
const wchar_t *start = L"X means ";
1111
const wchar_t *append = L"dog";
12-
wchar_t goodDst[15];
12+
wchar_t goodArray[15];
13+
wchar_t *volatile goodDst = goodArray;
1314
wcscpy(goodDst, start);
1415
wcsncat(goodDst, append, 5);
1516

16-
wchar_t badDst[11];
17+
wchar_t badArray[11];
18+
wchar_t *volatile badDst = badArray;
1719
wcscpy(badDst, start);
1820
wcsncat(badDst, append, 1);
1921
fprintf(stderr, "Good so far.\n");

compiler-rt/test/asan/TestCases/wcsncpy.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88

99
int main() {
1010
const wchar_t *src = L"X means dog";
11-
wchar_t goodDst[12];
11+
wchar_t goodArray[12];
12+
wchar_t *volatile goodDst = goodArray;
1213
wcsncpy(goodDst, src, 12);
1314

14-
wchar_t badDst[7];
15+
wchar_t badArray[7];
16+
wchar_t *volatile badDst = badArray;
1517
wcsncpy(badDst, src, 7); // This should still work.
1618
fprintf(stderr, "Good so far.\n");
1719
// CHECK-DAG: Good so far.

0 commit comments

Comments
 (0)