Skip to content

Commit

Permalink
[view_curses] check color
Browse files Browse the repository at this point in the history
Related to #1245
  • Loading branch information
tstack committed Mar 31, 2024
1 parent 3a63791 commit a2b573a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/base/ansi_scrubber.cc
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,10 @@ scrub_ansi_string(std::string& str, string_attrs_t* sa)
semi_pred);
auto color_index = scn::scan_value<short>(
color_index_pair.first.to_string_view());
if (!color_index.has_value()) {
if (!color_index.has_value()
|| color_index.value() < 0
|| color_index.value() > 255)
{
break;
}
if (ansi_code == 38) {
Expand Down
2 changes: 1 addition & 1 deletion src/third-party/prqlc-c/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ default = []
# We produce both of these at the moment, but could consider refining this. ref
# https://github.com/rust-lang/cargo/issues/8607 &
# https://github.com/rust-lang/rust/issues/59302
crate_type = ["staticlib", "cdylib"]
crate_type = ["staticlib"]
doctest = false
test = false
doc = false
Expand Down
2 changes: 1 addition & 1 deletion src/third-party/rapidyaml/ryml_all.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1766,7 +1766,7 @@ __inline__ static void trap_instruction(void)
/* Known problem:
* Same problem and workaround as Thumb mode */
}
#elif defined(__aarch64__) && defined(__APPLE__)
#elif defined(__aarch64__) && defined(__APPLE__) && defined(__clang__)
#define DEBUG_BREAK_IMPL DEBUG_BREAK_USE_BULTIN_DEBUGTRAP
#elif defined(__aarch64__)
#define DEBUG_BREAK_IMPL DEBUG_BREAK_USE_TRAP_INSTRUCTION
Expand Down
13 changes: 8 additions & 5 deletions src/view_curses.cc
Original file line number Diff line number Diff line change
Expand Up @@ -430,14 +430,17 @@ view_curses::mvwattrline(WINDOW* window,
short cur_fg, cur_bg;
pair_content(cur_pair, &cur_fg, &cur_bg);

if (fg_color[lpc] != -1 && bg_color[lpc] == -1
&& base_attrs.ta_bg_color.value_or(0) >= 0)
if (fg_color[lpc] >= 0
&& fg_color[lpc] < view_colors::vc_active_palette->tc_palette.size()
&& bg_color[lpc] == -1 && base_attrs.ta_bg_color.value_or(0) >= 0
&& base_attrs.ta_bg_color.value_or(0)
< view_colors::vc_active_palette->tc_palette.size())
{
const auto& fg_color_info
= view_colors::vc_active_palette->tc_palette[fg_color[lpc]];
= view_colors::vc_active_palette->tc_palette.at(fg_color[lpc]);
const auto& bg_color_info
= view_colors::vc_active_palette
->tc_palette[base_attrs.ta_bg_color.value_or(0)];
= view_colors::vc_active_palette->tc_palette.at(
base_attrs.ta_bg_color.value_or(0));

if (!fg_color_info.xc_lab_color.sufficient_contrast(
bg_color_info.xc_lab_color))
Expand Down

0 comments on commit a2b573a

Please sign in to comment.