diff options
author | Behdad Esfahbod <behdad@behdad.org> | 2009-09-10 12:37:07 -0400 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2009-09-10 15:09:30 -0400 |
commit | 6f8d5b1da087a741c6cf6bbbf27d5a46d66720c8 (patch) | |
tree | 145785e98d4c96bf70ef719691f371a7c0d69bcc /src | |
parent | d41ff743ec9bb287c3bd2d37f514f259503d03cc (diff) |
[ring] Limit line length to 0xFFFF
Make rowdata structures a bit more compact
Diffstat (limited to 'src')
-rw-r--r-- | src/ring.c | 29 | ||||
-rw-r--r-- | src/ring.h | 6 |
2 files changed, 24 insertions, 11 deletions
@@ -95,14 +95,19 @@ _vte_row_data_fini (VteRowData *row) row->cells = NULL; } -static inline void +static inline gboolean _vte_row_data_ensure (VteRowData *row, guint len) { VteCells *cells = _vte_cells_for_cell_array (row->cells); if (G_LIKELY (cells && len <= cells->alloc_len)) - return; + return TRUE; + + if (G_UNLIKELY (len >= 0xFFFF)) + return FALSE; row->cells = _vte_cells_realloc (cells, len)->cells; + + return TRUE; } void @@ -110,7 +115,8 @@ _vte_row_data_insert (VteRowData *row, guint col, const VteCell *cell) { guint i; - _vte_row_data_ensure (row, row->len + 1); + if (G_UNLIKELY (!_vte_row_data_ensure (row, row->len + 1))) + return; for (i = row->len; i > col; i--) row->cells[i] = row->cells[i - 1]; @@ -121,7 +127,9 @@ _vte_row_data_insert (VteRowData *row, guint col, const VteCell *cell) void _vte_row_data_append (VteRowData *row, const VteCell *cell) { - _vte_row_data_ensure (row, row->len + 1); + if (G_UNLIKELY (!_vte_row_data_ensure (row, row->len + 1))) + return; + row->cells[row->len] = *cell; row->len++; } @@ -142,7 +150,8 @@ void _vte_row_data_fill (VteRowData *row, const VteCell *cell, guint len) if (row->len < len) { guint i = len - row->len; - _vte_row_data_ensure (row, len); + if (G_UNLIKELY (!_vte_row_data_ensure (row, len))) + return; for (i = row->len; i < len; i++) row->cells[i] = *cell; @@ -170,10 +179,11 @@ ASSERT_STATIC (sizeof (VteRowStorage) == 1); typedef struct _VteCompactRowData { guchar *bytes; - guint32 len; + guint16 len; VteRowAttr attr; VteRowStorage storage; } VteCompactRowData; +ASSERT_STATIC (sizeof (VteCompactRowData) <= 2 * sizeof (void *)); static guint @@ -333,9 +343,12 @@ _vte_compact_row_data_uncompact (const VteCompactRowData *compact_row, VteRowDat _vte_debug_print(VTE_DEBUG_RING, "Uncompacting row: %d %d.\n", storage.charbytes, storage.attrbytes); - _vte_row_data_ensure (row, compact_row->len); - row->len = compact_row->len; row->attr = compact_row->attr; + if (G_UNLIKELY (!_vte_row_data_ensure (row, compact_row->len))) { + row->len = 0; + return; + } + row->len = compact_row->len; from = _fetch (from, (guint32 *) row->cells, 0, storage.charbytes, compact_row->len); from = _fetch (from, 1 + (guint32 *) row->cells, basic_attrs, storage.attrbytes, compact_row->len); @@ -119,9 +119,9 @@ static const union { */ typedef struct _VteRowAttr { - guint32 soft_wrapped: 1; + guint8 soft_wrapped: 1; } VteRowAttr; -ASSERT_STATIC (sizeof (VteRowAttr) == 4); +ASSERT_STATIC (sizeof (VteRowAttr) == 1); /* * VteRowData: A single row's data @@ -129,7 +129,7 @@ ASSERT_STATIC (sizeof (VteRowAttr) == 4); typedef struct _VteRowData { VteCell *cells; - guint32 len; + guint16 len; VteRowAttr attr; } VteRowData; |