[pango/line-breaker] lines: Fix some corner cases



commit ff315ea17391473231c5145f04348d8d7c165c47
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Jan 24 13:50:54 2022 -0500

    lines: Fix some corner cases

 pango/pango-lines.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
---
diff --git a/pango/pango-lines.c b/pango/pango-lines.c
index 663f0581..de86735c 100644
--- a/pango/pango-lines.c
+++ b/pango/pango-lines.c
@@ -541,9 +541,7 @@ pango_lines_get_x_ranges (PangoLines       *lines,
   g_return_if_fail (PANGO_IS_LINES (lines));
   g_return_if_fail (PANGO_IS_LAYOUT_LINE (line));
   g_return_if_fail (start_line == NULL || PANGO_IS_LAYOUT_LINE (start_line));
-  g_return_if_fail (start_index >= 0);
   g_return_if_fail (end_line == NULL || PANGO_IS_LAYOUT_LINE (end_line));
-  g_return_if_fail (end_index >= 0);
   g_return_if_fail (ranges != NULL);
   g_return_if_fail (n_ranges != NULL);
 
@@ -667,8 +665,8 @@ pango_lines_get_x_ranges (PangoLines       *lines,
  * Given an index (and possibly line), determine the line number,
  * and offset for the line.
  *
- * @idx may refer to any byte position inside @lines, as well
- * as the position after the last character (i.e.
+ * @idx may refer to any byte position inside @lines, as well as
+ * the position before the first or after the last character (i.e.
  * line->start_index + line->length, for the last line).
  *
  * If @lines contains lines with different backing data (i.e.
@@ -690,13 +688,12 @@ pango_lines_index_to_line (PangoLines       *lines,
   int i;
 
   g_return_if_fail (PANGO_IS_LINES (lines));
-  g_return_if_fail (idx >= 0);
 
   for (i = 0; i < lines->lines->len; i++)
     {
       Line *l = &g_array_index (lines->lines, Line, i);
 
-      if (l->line->start_index > idx)
+      if (l->line->start_index > idx && found)
         break;
 
       found = l;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]