[pango/log-attr-tweaks: 27/32] layout: Validate external log attrs
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/log-attr-tweaks: 27/32] layout: Validate external log attrs
- Date: Sun, 22 Aug 2021 04:45:43 +0000 (UTC)
commit adb3d3fcb41d20e7844a644aae3a3c49957c56de
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Aug 21 15:42:18 2021 -0400
layout: Validate external log attrs
These might be nonsense, better do some checks.
pango/break.c | 27 +++++++++++++++++++++++----
pango/pango-layout.c | 9 ++++++++-
2 files changed, 31 insertions(+), 5 deletions(-)
---
diff --git a/pango/break.c b/pango/break.c
index dbba48da..2a1f9b22 100644
--- a/pango/break.c
+++ b/pango/break.c
@@ -1866,6 +1866,13 @@ check_line_char (int pos,
return FALSE;
}
+ if (attr->is_line_break && !attr->is_char_break)
+ {
+ g_set_error (error,
+ PANGO_VALIDATE_ERROR, PANGO_VALIDATE_ERROR_BREAK,
+ "char %d: Line breaks must also be marked as char breaks", pos);
+ return FALSE;
+ }
if (break_type == G_UNICODE_BREAK_OPEN_PUNCTUATION &&
prev_break_type == G_UNICODE_BREAK_OPEN_PUNCTUATION &&
attr->is_line_break && !attr->is_mandatory_break)
@@ -1956,6 +1963,14 @@ check_word_invariants (const char *text,
break;
case AFTER_START:
+ if (log_attrs[i].is_word_end)
+ {
+ if (log_attrs[i].is_word_start)
+ state = AFTER_START;
+ else
+ state = AFTER_END;
+ break;
+ }
if (log_attrs[i].is_word_start)
{
g_set_error (error,
@@ -1963,8 +1978,6 @@ check_word_invariants (const char *text,
"char %d: Unexpected word start", i);
return FALSE;
}
- if (log_attrs[i].is_word_end)
- state = AFTER_END;
break;
}
}
@@ -2007,6 +2020,14 @@ check_sentence_invariants (const char *text,
break;
case AFTER_START:
+ if (log_attrs[i].is_sentence_end)
+ {
+ if (log_attrs[i].is_sentence_start)
+ state = AFTER_START;
+ else
+ state = AFTER_END;
+ break;
+ }
if (log_attrs[i].is_sentence_start)
{
g_set_error (error,
@@ -2014,8 +2035,6 @@ check_sentence_invariants (const char *text,
"char %d: Unexpected sentence start", i);
return FALSE;
}
- if (log_attrs[i].is_sentence_end)
- state = AFTER_END;
break;
}
}
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index d96344db..99cb6381 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -1589,7 +1589,14 @@ pango_layout_set_log_attrs (PangoLayout *layout,
const PangoLogAttr *attrs,
int n_attrs)
{
- g_return_if_fail (layout->n_chars + 1 == n_attrs);
+ GError *error = NULL;
+
+ if (!pango_validate_log_attrs (layout->text, layout->length, attrs, n_attrs, &error))
+ {
+ g_warning ("pango_layout_set_log_attrs: %s", error->message);
+ g_error_free (error);
+ return;
+ }
if (!layout->log_attrs)
layout->log_attrs = g_new (PangoLogAttr, layout->n_chars + 1);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]