Skip to content

Commit

Permalink
Merge pull request #522 from chewing/0.8.0-rc.3-bug-fixes
Browse files Browse the repository at this point in the history
0.8.0-rc.3 bug fixes
  • Loading branch information
kanru committed May 6, 2024
2 parents fff9f1b + b5a8588 commit 0b26573
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
2 changes: 2 additions & 0 deletions NEWS
Expand Up @@ -28,6 +28,8 @@ What's New in libchewing 0.8.0-rc.2 (UNRELEASED)
(introduced in v0.6.0)
- Special symbol selection missed a couple symbols that was in C version.
(introduced in v0.7.0)
- Panics when a new selection replaces more than one existing selections.
(introduced in v0.7.0)

* Removed
- HashMap implemented Dictionary was removed.
Expand Down
10 changes: 5 additions & 5 deletions src/conversion/mod.rs
Expand Up @@ -228,7 +228,7 @@ impl Composition {
to_remove.push(i);
}
}
for i in to_remove {
for i in to_remove.into_iter().rev() {
self.selections.swap_remove(i);
}
}
Expand All @@ -249,7 +249,7 @@ impl Composition {
selection.end += 1;
}
}
for i in to_remove {
for i in to_remove.into_iter().rev() {
self.selections.swap_remove(i);
}
self.symbols.insert(index, sym);
Expand All @@ -272,7 +272,7 @@ impl Composition {
to_remove.push(i);
}
}
for i in to_remove {
for i in to_remove.into_iter().rev() {
self.selections.swap_remove(i);
}
for i in (interval.start..interval.end).skip(1) {
Expand All @@ -291,7 +291,7 @@ impl Composition {
selection.end -= n;
}
}
for i in to_remove {
for i in to_remove.into_iter().rev() {
self.selections.swap_remove(i);
}
self.symbols.drain(0..n);
Expand All @@ -313,7 +313,7 @@ impl Composition {
selection.end -= 1;
}
}
for i in to_remove {
for i in to_remove.into_iter().rev() {
self.selections.swap_remove(i);
}
self.symbols.remove(index);
Expand Down
2 changes: 1 addition & 1 deletion src/editor/composition_editor.rs
Expand Up @@ -83,7 +83,7 @@ impl CompositionEditor {
}
pub(crate) fn remove_front(&mut self, n: usize) {
self.inner.remove_front(n);
self.cursor -= n;
self.cursor = self.cursor.saturating_sub(n);
}
pub(crate) fn remove_after_cursor(&mut self) {
self.inner.remove(self.cursor);
Expand Down
16 changes: 16 additions & 0 deletions tests/test-regression.c
Expand Up @@ -251,6 +251,21 @@ void test_empty_preedit_ignore_arrow_key()
chewing_delete(ctx);
}

void test_crash_found_by_fuzzing_20240505_0()
{
ChewingContext *ctx;

clean_userphrase();

ctx = chewing_new();
start_testcase(ctx, fd);

type_keystroke_by_string(ctx, "93<D>093<D>0<H><D>2");
ok_preedit_buffer(ctx, "靄靄");

chewing_delete(ctx);
}

int main(int argc, char *argv[])
{
char *logname;
Expand All @@ -277,6 +292,7 @@ int main(int argc, char *argv[])
test_insert_symbol_between_selection();
test_empty_prefix_in_conversion_search();
test_empty_preedit_ignore_arrow_key();
test_crash_found_by_fuzzing_20240505_0();

fclose(fd);

Expand Down

0 comments on commit 0b26573

Please sign in to comment.