diff options
author | Philipp Gesang <phg42.2a@gmail.com> | 2015-05-03 16:23:21 +0200 |
---|---|---|
committer | Philipp Gesang <phg42.2a@gmail.com> | 2015-05-03 16:26:52 +0200 |
commit | 45e05099904407acf060a19d9876feb0104733e0 (patch) | |
tree | ae80985fcc7cfec37b86f2c496940b54c548704f | |
parent | b421a17ed14e966bddb62165c9d944e565f1ba7a (diff) | |
download | vtcol-45e05099904407acf060a19d9876feb0104733e0.tar.gz |
vtcol.rs: check for valid index prior to assigning palette color from scheme
-rw-r--r-- | vtcol.rs | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -409,7 +409,9 @@ impl Palette { let parse_res : Option<usize> = 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; } }; |