Skip to content

Commit

Permalink
Check Buffer::ensure result.
Browse files Browse the repository at this point in the history
Closes #135
  • Loading branch information
RazrFalcon committed Oct 1, 2024
1 parent 9a0ec97 commit 839ef07
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
19 changes: 11 additions & 8 deletions src/hb/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,9 @@ impl hb_buffer_t {
}

fn add(&mut self, codepoint: u32, cluster: u32) {
self.ensure(self.len + 1);
if !self.ensure(self.len + 1) {
return;
}

let i = self.len;
self.info[i] = hb_glyph_info_t {
Expand Down Expand Up @@ -1193,6 +1195,7 @@ impl hb_buffer_t {
true
}

#[must_use]
pub fn ensure(&mut self, size: usize) -> bool {
if size < self.len {
return true;
Expand All @@ -1208,11 +1211,7 @@ impl hb_buffer_t {
true
}

pub fn set_len(&mut self, len: usize) {
self.ensure(len);
self.len = len;
}

#[must_use]
fn make_room_for(&mut self, num_in: usize, num_out: usize) -> bool {
if !self.ensure(self.out_len + num_out) {
return false;
Expand All @@ -1232,7 +1231,9 @@ impl hb_buffer_t {

fn shift_forward(&mut self, count: usize) {
assert!(self.have_output);
self.ensure(self.len + count);
if !self.ensure(self.len + count) {
return;
}

for i in (0..(self.len - self.idx)).rev() {
self.info[self.idx + count + i] = self.info[self.idx + i];
Expand Down Expand Up @@ -1415,7 +1416,9 @@ impl hb_buffer_t {
}

fn push_str(&mut self, text: &str) {
self.ensure(self.len + text.chars().count());
if !self.ensure(self.len + text.chars().count()) {
return;
}

for (i, c) in text.char_indices() {
self.add(c as u32, i as u32);
Expand Down
6 changes: 4 additions & 2 deletions src/hb/ot_shaper_arabic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,10 +584,12 @@ fn apply_stch(face: &hb_font_t, buffer: &mut hb_buffer_t) {
}

if step == MEASURE {
buffer.ensure(buffer.len + extra_glyphs_needed);
if !buffer.ensure(buffer.len + extra_glyphs_needed) {
break;
}
} else {
debug_assert_eq!(j, 0);
buffer.set_len(new_len);
buffer.len = new_len;
}
}

Expand Down

0 comments on commit 839ef07

Please sign in to comment.