aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2015-10-23 14:42:35 +0300
committerZyX <kp-pav@yandex.ru>2015-10-23 14:47:59 +0300
commite96aa067f3a94e9633ffd577fce83575e7fd00a7 (patch)
treef7e875055b91c59b8dc86dd1454659de6c8c71d8
parent7a1090eef54800c42086610b5ed9b373ce8af3ec (diff)
downloadrneovim-e96aa067f3a94e9633ffd577fce83575e7fd00a7.tar.gz
rneovim-e96aa067f3a94e9633ffd577fce83575e7fd00a7.tar.bz2
rneovim-e96aa067f3a94e9633ffd577fce83575e7fd00a7.zip
mark: Make clrallmarks correctly free all marks, and set zero tstamps
This and the previous commit together fix #3472. This one also fixes memory leak on :delmarks!.
-rw-r--r--src/nvim/mark.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/nvim/mark.c b/src/nvim/mark.c
index dd49b311d3..0432ec5cef 100644
--- a/src/nvim/mark.c
+++ b/src/nvim/mark.c
@@ -546,19 +546,26 @@ int check_mark(pos_T *pos)
return OK;
}
-/*
- * clrallmarks() - clear all marks in the buffer 'buf'
- *
- * Used mainly when trashing the entire buffer during ":e" type commands
- */
-void clrallmarks(buf_T *buf)
+/// Clear all marks and change list in the given buffer
+///
+/// Used mainly when trashing the entire buffer during ":e" type commands.
+///
+/// @param[out] buf Buffer to clear marks in.
+void clrallmarks(buf_T *const buf)
+ FUNC_ATTR_NONNULL_ALL
{
- memset(&(buf->b_namedm[0]), 0, sizeof(buf->b_namedm));
- buf->b_op_start.lnum = 0; /* start/end op mark cleared */
+ for (size_t i = 0; i < NMARKS; i++) {
+ clear_fmark(&buf->b_namedm[i]);
+ }
+ clear_fmark(&buf->b_last_cursor);
+ buf->b_last_cursor.mark.lnum = 1;
+ clear_fmark(&buf->b_last_insert);
+ clear_fmark(&buf->b_last_change);
+ buf->b_op_start.lnum = 0; // start/end op mark cleared
buf->b_op_end.lnum = 0;
- RESET_FMARK(&buf->b_last_cursor, ((pos_T) {1, 0, 0}), 0); // '" mark
- CLEAR_FMARK(&buf->b_last_insert); // '^ mark
- CLEAR_FMARK(&buf->b_last_change); // '. mark
+ for (int i = 0; i < buf->b_changelistlen; i++) {
+ clear_fmark(&buf->b_changelist[i]);
+ }
buf->b_changelistlen = 0;
}