diff options
author | Matthias Clasen <mclasen@redhat.com> | 2021-12-05 10:45:52 -0500 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2021-12-05 10:51:24 -0500 |
commit | f5fdfe4e16b7da761d918f40bb82dad52513c9ff (patch) | |
tree | f7e3e22790db7532672e73fddabfaa18ffc891c0 /pango | |
parent | c1254259233dc9916cf1983d8e51d5441a0ab617 (diff) | |
download | pango-f5fdfe4e16b7da761d918f40bb82dad52513c9ff.tar.gz |
Fix a crash in tab handlingtab-crash-fix
When we uninsert the current tab run, we need to reset
our tab state to prevent last_tab->glyphs to become a
dangling pointer.
Test included.
Fixes: #634
Diffstat (limited to 'pango')
-rw-r--r-- | pango/pango-layout.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/pango/pango-layout.c b/pango/pango-layout.c index 060420a8..ed46d57a 100644 --- a/pango/pango-layout.c +++ b/pango/pango-layout.c @@ -3775,6 +3775,7 @@ insert_run (PangoLayoutLine *line, if (state->last_tab.glyphs && run->glyphs != state->last_tab.glyphs) { gboolean found_decimal = FALSE; + int width; /* Adjust the tab position so placing further runs will continue to * maintain the tab placement. In the case of decimal tabs, we are @@ -3794,9 +3795,10 @@ insert_run (PangoLayoutLine *line, state->last_tab.width += width; } - state->last_tab.glyphs->glyphs[0].geometry.width = MAX (state->last_tab.pos - state->last_tab.width, 0); + width = MAX (state->last_tab.pos - state->last_tab.width, 0); + state->last_tab.glyphs->glyphs[0].geometry.width = width; - if (found_decimal) + if (found_decimal || width == 0) state->last_tab.glyphs = NULL; } } @@ -4494,7 +4496,21 @@ process_line (PangoLayout *layout, case BREAK_NONE_FIT: /* Back up over unused runs to run where there is a break */ while (line->runs && line->runs != break_link) - state->items = g_list_prepend (state->items, uninsert_run (line)); + { + PangoLayoutRun *run = line->runs->data; + + /* If we uninsert the current tab run, + * we need to reset the tab state + */ + if (run->glyphs == state->last_tab.glyphs) + { + state->last_tab.glyphs = NULL; + state->last_tab.index = 0; + state->last_tab.align = PANGO_TAB_LEFT; + } + + state->items = g_list_prepend (state->items, uninsert_run (line)); + } state->start_offset = break_start_offset; state->remaining_width = break_remaining_width; |