Skip to content

Commit

Permalink
ui: fix problem with sattr_T overflow
Browse files Browse the repository at this point in the history
sattr_T was defined as uint16_t. But this is not enough to handle the
24-bit colors of the terminal. To solve this problem, change it to int.
In 32bit, int may overflow. So, if it overflows, change it to ignore it
without adding more attr_entries.

fixes neovim#12366

(cherry picked from commit 872ecf6)
  • Loading branch information
erw7 authored and jamessan committed Aug 4, 2020
1 parent 0547b4c commit fd02e63
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/nvim/grid_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

// The characters and attributes drawn on grids.
typedef char_u schar_T[(MAX_MCO+1) * 4 + 1];
typedef int16_t sattr_T;
typedef int sattr_T;

/// ScreenGrid represents a resizable rectuangular grid displayed by UI clients.
///
Expand Down
7 changes: 6 additions & 1 deletion src/nvim/highlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ static int get_attr_entry(HlEntry entry)
}
}

id = (int)kv_size(attr_entries);
size_t next_id = kv_size(attr_entries);
if (next_id > INT_MAX) {
ELOG("The index on attr_entries has overflowed");
return 0;
}
id = (int)next_id;
kv_push(attr_entries, entry);

map_put(HlEntry, int)(attr_entry_ids, entry, id);
Expand Down

0 comments on commit fd02e63

Please sign in to comment.