|
9 | 9 | // Tests for *scanf interceptors implementation in sanitizer_common.
|
10 | 10 | //
|
11 | 11 | //===----------------------------------------------------------------------===//
|
| 12 | +#include <wchar.h> |
| 13 | + |
12 | 14 | #include <algorithm>
|
13 | 15 | #include <vector>
|
14 | 16 |
|
| 17 | +#include "gtest/gtest.h" |
15 | 18 | #include "interception/interception.h"
|
16 |
| -#include "sanitizer_test_utils.h" |
17 |
| -#include "sanitizer_common/sanitizer_libc.h" |
18 | 19 | #include "sanitizer_common/sanitizer_common.h"
|
19 |
| -#include "gtest/gtest.h" |
| 20 | +#include "sanitizer_common/sanitizer_libc.h" |
| 21 | +#include "sanitizer_test_utils.h" |
20 | 22 |
|
21 | 23 | using namespace __sanitizer;
|
22 | 24 |
|
@@ -206,21 +208,35 @@ TEST(SanitizerCommonInterceptors, Scanf) {
|
206 | 208 |
|
207 | 209 | TEST(SanitizerCommonInterceptors, ScanfAllocate) {
|
208 | 210 | const char *buf = "123456";
|
| 211 | + const wchar_t *wbuf = L"123"; |
209 | 212 |
|
210 | 213 | // Can not use testScanf() because this case needs a valid pointer to a string
|
211 | 214 | // in the scanf argument.
|
| 215 | + { |
| 216 | + std::vector<unsigned> scanf_sizes; |
| 217 | + testScanf3((void *)&scanf_sizes, 2, /*allowGnuMalloc=*/false, "%mc", &buf); |
| 218 | + verifyFormatResults("%mc", 2, scanf_sizes, {P, 1u}); |
| 219 | + } |
| 220 | + { |
| 221 | + std::vector<unsigned> scanf_sizes; |
| 222 | + testScanf3((void *)&scanf_sizes, 2, /*allowGnuMalloc=*/false, "%mC", &wbuf); |
| 223 | + verifyFormatResults("%mC", 2, scanf_sizes, {P, (unsigned)sizeof(wchar_t)}); |
| 224 | + } |
212 | 225 | {
|
213 | 226 | std::vector<unsigned> scanf_sizes;
|
214 | 227 | testScanf3((void *)&scanf_sizes, 2, /*allowGnuMalloc=*/false, "%ms", &buf);
|
215 |
| - verifyFormatResults("%ms", 2, scanf_sizes, |
216 |
| - {P, (unsigned)(strlen(buf) + 1)}); |
| 228 | + verifyFormatResults("%ms", 2, scanf_sizes, {P, unsigned(strlen(buf) + 1)}); |
| 229 | + scanf_sizes.clear(); |
| 230 | + testScanf3((void *)&scanf_sizes, 2, /*allowGnuMalloc=*/false, "%m[0-9]", |
| 231 | + &buf); |
| 232 | + verifyFormatResults("%m[0-9]", 2, scanf_sizes, |
| 233 | + {P, unsigned(strlen(buf) + 1)}); |
217 | 234 | }
|
218 |
| - |
219 | 235 | {
|
220 | 236 | std::vector<unsigned> scanf_sizes;
|
221 |
| - testScanf3((void *)&scanf_sizes, 2, /*allowGnuMalloc=*/false, "%mc", &buf); |
222 |
| - verifyFormatResults("%mc", 2, scanf_sizes, |
223 |
| - {P, (unsigned)(strlen(buf) + 1)}); |
| 237 | + testScanf3((void *)&scanf_sizes, 2, /*allowGnuMalloc=*/false, "%mS", &wbuf); |
| 238 | + verifyFormatResults("%mS", 2, scanf_sizes, |
| 239 | + {P, unsigned((wcslen(wbuf) + 1) * sizeof(wchar_t))}); |
224 | 240 | }
|
225 | 241 | }
|
226 | 242 |
|
|
0 commit comments