Skip to content

Commit 1601879

Browse files
[compiler-rt][nsan] Fix strsep interceptor (#106307)
Fix strsep interceptor. For strsep description see https://www.man7.org/linux/man-pages/man3/strsep.3.html
1 parent ccbee71 commit 1601879

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

compiler-rt/lib/nsan/nsan_interceptors.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ INTERCEPTOR(char *, strfry, char *s) {
9494

9595
INTERCEPTOR(char *, strsep, char **Stringp, const char *delim) {
9696
char *OrigStringp = REAL(strsep)(Stringp, delim);
97-
if (Stringp != nullptr) {
97+
if (*Stringp != nullptr) {
9898
// The previous character has been overwritten with a '\0' char.
9999
__nsan_set_value_unknown(reinterpret_cast<u8 *>(*Stringp) - 1, 1);
100100
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %clangxx_nsan -O2 %s -o %t
2+
// RUN: %run %t 2>&1 | FileCheck %s
3+
4+
#include <cstring>
5+
#include <iostream>
6+
7+
extern "C" void __nsan_dump_shadow_mem(const char *addr, size_t size_bytes,
8+
size_t bytes_per_line, size_t reserved);
9+
10+
int main() {
11+
// Define a C-style string with commas as delimiters
12+
char input[] = "apple,banana,cherry,date";
13+
char *token;
14+
char *rest = input; // Pointer to keep track of the rest of the string
15+
16+
// Tokenize the string using strsep
17+
while ((token = strsep(&rest, ",")) != NULL) {
18+
std::cout << token << std::endl;
19+
}
20+
21+
__nsan_dump_shadow_mem(&input[5], 1, 1, 0);
22+
// CHECK: 0x{{[a-f0-9]*}}: _
23+
return 0;
24+
}

0 commit comments

Comments
 (0)