diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2020-07-26 19:36:28 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2020-07-26 19:36:28 +0000 |
commit | cfca06d7963fa0909f90483b42a6d7d194d01e08 (patch) | |
tree | 209fb2a2d68f8f277793fc8df46c753d31bc853b /compiler-rt/lib/dfsan/dfsan_custom.cpp | |
parent | 706b4fc47bbc608932d3b491ae19a3b9cde9497b (diff) |
Notes
Diffstat (limited to 'compiler-rt/lib/dfsan/dfsan_custom.cpp')
-rw-r--r-- | compiler-rt/lib/dfsan/dfsan_custom.cpp | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/compiler-rt/lib/dfsan/dfsan_custom.cpp b/compiler-rt/lib/dfsan/dfsan_custom.cpp index 84f0271b15e0..1acd2d47d154 100644 --- a/compiler-rt/lib/dfsan/dfsan_custom.cpp +++ b/compiler-rt/lib/dfsan/dfsan_custom.cpp @@ -84,7 +84,13 @@ SANITIZER_INTERFACE_ATTRIBUTE char *__dfsw_strchr(const char *s, int c, *ret_label = dfsan_union(dfsan_read_label(s, i + 1), dfsan_union(s_label, c_label)); } - return s[i] == 0 ? nullptr : const_cast<char *>(s+i); + + // If s[i] is the \0 at the end of the string, and \0 is not the + // character we are searching for, then return null. + if (s[i] == 0 && c != 0) { + return nullptr; + } + return const_cast<char *>(s + i); } } } @@ -151,14 +157,17 @@ SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_strcasecmp(const char *s1, const char *s2, dfsan_label s1_label, dfsan_label s2_label, dfsan_label *ret_label) { for (size_t i = 0;; ++i) { - if (tolower(s1[i]) != tolower(s2[i]) || s1[i] == 0 || s2[i] == 0) { + char s1_lower = tolower(s1[i]); + char s2_lower = tolower(s2[i]); + + if (s1_lower != s2_lower || s1[i] == 0 || s2[i] == 0) { if (flags().strict_data_dependencies) { *ret_label = 0; } else { *ret_label = dfsan_union(dfsan_read_label(s1, i + 1), dfsan_read_label(s2, i + 1)); } - return s1[i] - s2[i]; + return s1_lower - s2_lower; } } return 0; @@ -206,15 +215,17 @@ __dfsw_strncasecmp(const char *s1, const char *s2, size_t n, } for (size_t i = 0;; ++i) { - if (tolower(s1[i]) != tolower(s2[i]) || s1[i] == 0 || s2[i] == 0 || - i == n - 1) { + char s1_lower = tolower(s1[i]); + char s2_lower = tolower(s2[i]); + + if (s1_lower != s2_lower || s1[i] == 0 || s2[i] == 0 || i == n - 1) { if (flags().strict_data_dependencies) { *ret_label = 0; } else { *ret_label = dfsan_union(dfsan_read_label(s1, i + 1), dfsan_read_label(s2, i + 1)); } - return s1[i] - s2[i]; + return s1_lower - s2_lower; } } return 0; |