Skip to content

Commit 21b0af6

Browse files
Fix Libtxt unit test errors found by ASAN (flutter#28146)
1 parent c99d6c6 commit 21b0af6

File tree

3 files changed

+33
-36
lines changed

3 files changed

+33
-36
lines changed

third_party/txt/src/txt/paragraph_txt.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1992,7 +1992,8 @@ Paragraph::Range<size_t> ParagraphTxt::GetWordBoundary(size_t offset) {
19921992
return Range<size_t>(0, 0);
19931993
}
19941994

1995-
word_breaker_->setText(icu::UnicodeString(false, text_.data(), text_.size()));
1995+
icu::UnicodeString icu_text(false, text_.data(), text_.size());
1996+
word_breaker_->setText(icu_text);
19961997

19971998
int32_t prev_boundary = word_breaker_->preceding(offset + 1);
19981999
int32_t next_boundary = word_breaker_->next();

third_party/txt/src/txt/text_style.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ bool TextStyle::equals(const TextStyle& other) const {
5454
return false;
5555
if (foreground != other.foreground)
5656
return false;
57+
if (font_families.size() != other.font_families.size())
58+
return false;
5759
if (text_shadows.size() != other.text_shadows.size())
5860
return false;
5961
for (size_t font_index = 0; font_index < font_families.size(); ++font_index) {

third_party/txt/tests/paragraph_unittests.cc

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,11 +2489,10 @@ TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(RightAlignParagraph)) {
24892489
ASSERT_TRUE(paragraph->records_[0].style().equals(text_style));
24902490
ASSERT_DOUBLE_EQ(paragraph->records_[0].offset().y(), expected_y);
24912491
expected_y += 30;
2492-
ASSERT_NEAR(
2493-
paragraph->records_[0].offset().x(),
2494-
paragraph->width_ -
2495-
paragraph->breaker_.getWidths()[paragraph->records_[0].line()],
2496-
2.0);
2492+
ASSERT_NEAR(paragraph->records_[0].offset().x(),
2493+
paragraph->width_ -
2494+
paragraph->line_widths_[paragraph->records_[0].line()],
2495+
2.0);
24972496

24982497
// width_ takes the full available space, while longest_line_ wraps the glyphs
24992498
// as tightly as possible. Even though this text is more than one line long,
@@ -2506,37 +2505,33 @@ TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(RightAlignParagraph)) {
25062505
ASSERT_TRUE(paragraph->records_[2].style().equals(text_style));
25072506
ASSERT_DOUBLE_EQ(paragraph->records_[2].offset().y(), expected_y);
25082507
expected_y += 30;
2509-
ASSERT_NEAR(
2510-
paragraph->records_[2].offset().x(),
2511-
paragraph->width_ -
2512-
paragraph->breaker_.getWidths()[paragraph->records_[2].line()],
2513-
2.0);
2508+
ASSERT_NEAR(paragraph->records_[2].offset().x(),
2509+
paragraph->width_ -
2510+
paragraph->line_widths_[paragraph->records_[2].line()],
2511+
2.0);
25142512

25152513
ASSERT_TRUE(paragraph->records_[4].style().equals(text_style));
25162514
ASSERT_DOUBLE_EQ(paragraph->records_[4].offset().y(), expected_y);
25172515
expected_y += 30;
2518-
ASSERT_NEAR(
2519-
paragraph->records_[4].offset().x(),
2520-
paragraph->width_ -
2521-
paragraph->breaker_.getWidths()[paragraph->records_[4].line()],
2522-
2.0);
2516+
ASSERT_NEAR(paragraph->records_[4].offset().x(),
2517+
paragraph->width_ -
2518+
paragraph->line_widths_[paragraph->records_[4].line()],
2519+
2.0);
25232520

25242521
ASSERT_TRUE(paragraph->records_[6].style().equals(text_style));
25252522
ASSERT_DOUBLE_EQ(paragraph->records_[6].offset().y(), expected_y);
25262523
expected_y += 30 * 10;
2527-
ASSERT_NEAR(
2528-
paragraph->records_[6].offset().x(),
2529-
paragraph->width_ -
2530-
paragraph->breaker_.getWidths()[paragraph->records_[6].line()],
2531-
2.0);
2524+
ASSERT_NEAR(paragraph->records_[6].offset().x(),
2525+
paragraph->width_ -
2526+
paragraph->line_widths_[paragraph->records_[6].line()],
2527+
2.0);
25322528

25332529
ASSERT_TRUE(paragraph->records_[26].style().equals(text_style));
25342530
ASSERT_DOUBLE_EQ(paragraph->records_[26].offset().y(), expected_y);
2535-
ASSERT_NEAR(
2536-
paragraph->records_[26].offset().x(),
2537-
paragraph->width_ -
2538-
paragraph->breaker_.getWidths()[paragraph->records_[26].line()],
2539-
2.0);
2531+
ASSERT_NEAR(paragraph->records_[26].offset().x(),
2532+
paragraph->width_ -
2533+
paragraph->line_widths_[paragraph->records_[26].line()],
2534+
2.0);
25402535

25412536
ASSERT_EQ(paragraph_style.text_align,
25422537
paragraph->GetParagraphStyle().text_align);
@@ -2609,7 +2604,7 @@ TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(CenterAlignParagraph)) {
26092604
expected_y += 30;
26102605
ASSERT_NEAR(paragraph->records_[0].offset().x(),
26112606
(paragraph->width_ -
2612-
paragraph->breaker_.getWidths()[paragraph->records_[0].line()]) /
2607+
paragraph->line_widths_[paragraph->records_[0].line()]) /
26132608
2,
26142609
2.0);
26152610

@@ -2618,7 +2613,7 @@ TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(CenterAlignParagraph)) {
26182613
expected_y += 30;
26192614
ASSERT_NEAR(paragraph->records_[2].offset().x(),
26202615
(paragraph->width_ -
2621-
paragraph->breaker_.getWidths()[paragraph->records_[2].line()]) /
2616+
paragraph->line_widths_[paragraph->records_[2].line()]) /
26222617
2,
26232618
2.0);
26242619

@@ -2627,7 +2622,7 @@ TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(CenterAlignParagraph)) {
26272622
expected_y += 30;
26282623
ASSERT_NEAR(paragraph->records_[4].offset().x(),
26292624
(paragraph->width_ -
2630-
paragraph->breaker_.getWidths()[paragraph->records_[4].line()]) /
2625+
paragraph->line_widths_[paragraph->records_[4].line()]) /
26312626
2,
26322627
2.0);
26332628

@@ -2636,18 +2631,17 @@ TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(CenterAlignParagraph)) {
26362631
expected_y += 30 * 10;
26372632
ASSERT_NEAR(paragraph->records_[6].offset().x(),
26382633
(paragraph->width_ -
2639-
paragraph->breaker_.getWidths()[paragraph->records_[6].line()]) /
2634+
paragraph->line_widths_[paragraph->records_[6].line()]) /
26402635
2,
26412636
2.0);
26422637

26432638
ASSERT_TRUE(paragraph->records_[26].style().equals(text_style));
26442639
ASSERT_DOUBLE_EQ(paragraph->records_[26].offset().y(), expected_y);
2645-
ASSERT_NEAR(
2646-
paragraph->records_[26].offset().x(),
2647-
(paragraph->width_ -
2648-
paragraph->breaker_.getWidths()[paragraph->records_[26].line()]) /
2649-
2,
2650-
2.0);
2640+
ASSERT_NEAR(paragraph->records_[26].offset().x(),
2641+
(paragraph->width_ -
2642+
paragraph->line_widths_[paragraph->records_[26].line()]) /
2643+
2,
2644+
2.0);
26512645

26522646
ASSERT_EQ(paragraph_style.text_align,
26532647
paragraph->GetParagraphStyle().text_align);

0 commit comments

Comments
 (0)