If a non-temporal identifier, that ends with a temporal macro, happens
to be at the end of the buffer with the temporal suffix starting on the
avx boundary, then it would be incorrectly classified as a temporal
macro. This since the helper function lacks the context to see that the
data before the match is something that invalidates the match.
}
int
-check_for_temporal_macros_bmh(std::string_view str)
+check_for_temporal_macros_bmh(std::string_view str, size_t start = 0)
{
int result = 0;
// We're using the Boyer-Moore-Horspool algorithm, which searches starting
// from the *end* of the needle. Our needles are 8 characters long, so i
// starts at 7.
- size_t i = 7;
+ size_t i = start + 7;
while (i < str.length()) {
// Check whether the substring ending at str[i] has the form "_....E..". On
}
}
- result |= check_for_temporal_macros_bmh(str.substr(pos));
+ result |= check_for_temporal_macros_bmh(str, pos);
return result;
}
"#define alphabet abcdefghijklmnopqrstuvwxyz\n"
"__DATE__";
+ const std::string_view no_temporal_at_avx_boundary =
+ "#define alphabet abcdefghijklmnopqrstuvwxyz\n"
+ "a__DATE__";
+
CHECK(check_for_temporal_macros(time_start));
CHECK(!check_for_temporal_macros(time_start.substr(1)));
CHECK(!check_for_temporal_macros(no_temporal.substr(6)));
CHECK(!check_for_temporal_macros(no_temporal.substr(7)));
- for (size_t i = 0; i < sizeof(temporal_at_avx_boundary) - 8; ++i) {
+ for (size_t i = 0; i < temporal_at_avx_boundary.size() - 8; ++i) {
CHECK(check_for_temporal_macros(temporal_at_avx_boundary.substr(i)));
}
+ for (size_t i = 0; i < no_temporal_at_avx_boundary.size() - 8; ++i) {
+ CHECK(!check_for_temporal_macros(no_temporal_at_avx_boundary.substr(i)));
+ }
}
TEST_SUITE_END();