vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit e8ceb17c758c60532667018d4c66e1e80cb906ee parent 1bf7e1137ce5015bb0b9c8707eba73b876867d71 Author: Marc André Tanner <mat@brain-dump.org> Date: Tue, 22 Jul 2014 18:03:16 +0200 Perform argument validation Diffstat:
| M | editor.c | | | 9 | +++++---- |
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/editor.c b/editor.c @@ -442,6 +442,8 @@ static void change_free(Change *c) { * \-+ <-- +-----+ <-- +---------------+ <-- +-/ */ bool editor_insert_raw(Editor *ed, size_t pos, const char *data, size_t len) { + if (pos > ed->size) + return false; Location loc = piece_get(ed, pos); Piece *p = loc.piece; size_t off = loc.off; @@ -722,10 +724,9 @@ bool editor_delete(Editor *ed, size_t pos, size_t len) { } bool editor_replace_raw(Editor *ed, size_t pos, const char *data, size_t len) { - // TODO argument validation: pos etc. - editor_delete(ed, pos, len); - editor_insert(ed, pos, data); - return true; + if (!editor_delete(ed, pos, len)) + return false; + return editor_insert_raw(ed, pos, data, len); } bool editor_replace(Editor *ed, size_t pos, const char *data) {