From 45e05099904407acf060a19d9876feb0104733e0 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 3 May 2015 16:23:21 +0200 Subject: vtcol.rs: check for valid index prior to assigning palette color from scheme --- vtcol.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/vtcol.rs b/vtcol.rs index 14abf4b..4c30289 100644 --- a/vtcol.rs +++ b/vtcol.rs @@ -409,7 +409,9 @@ impl Palette { let parse_res : Option = std::str::FromStr::from_str(str_idx); match parse_res { - Some(new_idx) => pal_idx = new_idx * 3_us, + Some(new_idx) => { + if new_idx < PALETTE_SIZE { pal_idx = new_idx * 3_us; } + }, None => () } } @@ -423,7 +425,7 @@ impl Palette { pal[pal_idx + 0_us] = r; pal[pal_idx + 1_us] = g; pal[pal_idx + 2_us] = b; - pal_idx = pal_idx + 3_us; + pal_idx = (pal_idx + 3_us) % PALETTE_BYTES; } }; -- cgit v1.2.3