summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2018-05-19 12:06:21 -0700
committerJoe Wilm <joe@jwilm.com>2018-05-29 21:01:44 -0700
commitf897c998e9166a1fd9e2889ad806a7af954f754d (patch)
treec005a906b19760058bfef066cc2e2b9f0d4c5b01
parent8b156c7c58b7b1d7dd9ec1a8129e7d726c14fc4c (diff)
Fix OOB index in grid::DisplayIter
When resizing prior to this patch, hidden rows in Storage were not having columns added along with everything else. This feels like a bit of tech debt, but the patch is simple enough that it won't be much extra to back out later when the underlying cause is addressed (see comments in code).
-rw-r--r--src/grid/mod.rs2
-rw-r--r--src/grid/storage.rs16
2 files changed, 17 insertions, 1 deletions
diff --git a/src/grid/mod.rs b/src/grid/mod.rs
index 0eea4201..9b36fcdf 100644
--- a/src/grid/mod.rs
+++ b/src/grid/mod.rs
@@ -244,7 +244,7 @@ impl<T: Copy + Clone> Grid<T> {
}
fn grow_cols(&mut self, cols: index::Column, template: &T) {
- for row in self.raw.iter_mut() {
+ for row in self.raw.iter_mut_raw() {
row.grow(cols, template);
}
diff --git a/src/grid/storage.rs b/src/grid/storage.rs
index cadd4e29..e7c1a307 100644
--- a/src/grid/storage.rs
+++ b/src/grid/storage.rs
@@ -12,6 +12,7 @@
/// implementation is provided. Anything from Vec that should be exposed must be
/// done so manually.
use std::ops::{Index, IndexMut};
+use std::slice;
use index::Line;
@@ -183,10 +184,25 @@ impl<T> Storage<T> {
self.inner.swap(a, b);
}
+ /// Iterator over *logical* entries in the storage
+ ///
+ /// This *does not* iterate over hidden entries.
pub fn iter_mut(&mut self) -> IterMut<T> {
IterMut { storage: self, index: 0 }
}
+ /// Iterate over *all* entries in the underlying buffer
+ ///
+ /// This includes hidden entries.
+ ///
+ /// XXX This suggests that Storage is a leaky abstraction. Ultimately, this
+ /// is needed because of the grow lines functionality implemented on
+ /// this type, and maybe that's where the leak is necessitating this
+ /// accessor.
+ pub fn iter_mut_raw<'a>(&'a mut self) -> slice::IterMut<'a, T> {
+ self.inner.iter_mut()
+ }
+
pub fn rotate(&mut self, count: isize) {
debug_assert!(count.abs() as usize <= self.inner.len());