Skip to content

Commit

Permalink
Prevent compiler-warning of possible out-of-bounds access.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 296967895
  • Loading branch information
hzeller committed Feb 24, 2020
1 parent c449490 commit a76f7e9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion common/text/tree_utils_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,10 @@ TEST_F(FindSubtreeStartingAtOffsetTest, LeafOnlyOffsetGreaterThan) {
EXPECT_EQ(subtree, nullptr);
}

constexpr absl::string_view kBaseText("abcdefghijklmnopqrst");
// Allow to look beyond kBaseText by cutting it out of a larger string.
constexpr absl::string_view kBaseTextPadded("_abcdefghijklmnopqrst_");
constexpr absl::string_view kBaseText = {kBaseTextPadded.data() + 1,
kBaseTextPadded.length() - 2};

// Return a tree with monotonically increasing token locations.
// This is suitable for tests that require only location offsets,
Expand All @@ -644,6 +647,7 @@ struct FindSubtreeStartingAtOffsetFakeTreeTest : public testing::Test {

// Test that a whole tree is returned when offset is less than leftmost token.
TEST_F(FindSubtreeStartingAtOffsetFakeTreeTest, TreeOffsetLessThanFirstToken) {
// Note: begin() - 1 points to a valid location due to kBaseTextPadded
SymbolPtr* subtree =
FindSubtreeStartingAtOffset(&tree, kBaseText.begin() - 1);
EXPECT_EQ(*subtree, tree);
Expand Down

0 comments on commit a76f7e9

Please sign in to comment.