summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <phg42.2a@gmail.com>2015-05-03 16:23:21 +0200
committerPhilipp Gesang <phg42.2a@gmail.com>2015-05-03 16:26:52 +0200
commit45e05099904407acf060a19d9876feb0104733e0 (patch)
treeae80985fcc7cfec37b86f2c496940b54c548704f
parentb421a17ed14e966bddb62165c9d944e565f1ba7a (diff)
downloadvtcol-45e05099904407acf060a19d9876feb0104733e0.tar.gz
vtcol.rs: check for valid index prior to assigning palette color from scheme
-rw-r--r--vtcol.rs6
1 files 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<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;
}
};