[pango/log-attr-tweaks: 18/19] layout: Validate external log attrs
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/log-attr-tweaks: 18/19] layout: Validate external log attrs
- Date: Tue, 24 Aug 2021 02:47:00 +0000 (UTC)
commit 10b0795d3146bb8e11ce6e3502d47c8f9b639ef5
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 767f6264..943c2a4a 100644
--- a/pango/break.c
+++ b/pango/break.c
@@ -1921,6 +1921,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)
@@ -2021,6 +2028,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,
@@ -2028,8 +2043,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;
default:
@@ -2075,6 +2088,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,
@@ -2082,8 +2103,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;
default:
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index 5269c634..07f70f28 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]