aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/undo.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/undo.c')
-rw-r--r--src/nvim/undo.c34
1 files changed, 9 insertions, 25 deletions
diff --git a/src/nvim/undo.c b/src/nvim/undo.c
index ed5c9a508c..c403e94184 100644
--- a/src/nvim/undo.c
+++ b/src/nvim/undo.c
@@ -1132,17 +1132,11 @@ static void serialize_pos(bufinfo_T *bi, pos_T pos)
static void unserialize_pos(bufinfo_T *bi, pos_T *pos)
{
pos->lnum = undo_read_4c(bi);
- if (pos->lnum < 0) {
- pos->lnum = 0;
- }
+ pos->lnum = MAX(pos->lnum, 0);
pos->col = undo_read_4c(bi);
- if (pos->col < 0) {
- pos->col = 0;
- }
+ pos->col = MAX(pos->col, 0);
pos->coladd = undo_read_4c(bi);
- if (pos->coladd < 0) {
- pos->coladd = 0;
- }
+ pos->coladd = MAX(pos->coladd, 0);
}
/// Serializes "info".
@@ -1209,14 +1203,12 @@ void u_write_undo(const char *const name, const bool forceit, buf_T *const buf,
// Strip any sticky and executable bits.
perm = perm & 0666;
- int fd;
-
// If the undo file already exists, verify that it actually is an undo
// file, and delete it.
if (os_path_exists(file_name)) {
if (name == NULL || !forceit) {
// Check we can read it and it's an undo file.
- fd = os_open(file_name, O_RDONLY, 0);
+ int fd = os_open(file_name, O_RDONLY, 0);
if (fd < 0) {
if (name != NULL || p_verbose > 0) {
if (name == NULL) {
@@ -1261,7 +1253,7 @@ void u_write_undo(const char *const name, const bool forceit, buf_T *const buf,
goto theend;
}
- fd = os_open(file_name, O_CREAT|O_WRONLY|O_EXCL|O_NOFOLLOW, perm);
+ int fd = os_open(file_name, O_CREAT|O_WRONLY|O_EXCL|O_NOFOLLOW, perm);
if (fd < 0) {
semsg(_(e_not_open), file_name);
goto theend;
@@ -2001,9 +1993,7 @@ void undo_time(int step, bool sec, bool file, bool absolute)
target = curbuf->b_u_seq_cur + step;
}
if (step < 0) {
- if (target < 0) {
- target = 0;
- }
+ target = MAX(target, 0);
closest = -1;
} else {
if (dosec) {
@@ -2396,9 +2386,7 @@ static void u_undoredo(bool undo, bool do_buf_event)
}
// Set the '[ mark.
- if (top + 1 < curbuf->b_op_start.lnum) {
- curbuf->b_op_start.lnum = top + 1;
- }
+ curbuf->b_op_start.lnum = MIN(curbuf->b_op_start.lnum, top + 1);
// Set the '] mark.
if (newsize == 0 && top + 1 > curbuf->b_op_end.lnum) {
curbuf->b_op_end.lnum = top + 1;
@@ -2419,12 +2407,8 @@ static void u_undoredo(bool undo, bool do_buf_event)
}
// Ensure the '[ and '] marks are within bounds.
- if (curbuf->b_op_start.lnum > curbuf->b_ml.ml_line_count) {
- curbuf->b_op_start.lnum = curbuf->b_ml.ml_line_count;
- }
- if (curbuf->b_op_end.lnum > curbuf->b_ml.ml_line_count) {
- curbuf->b_op_end.lnum = curbuf->b_ml.ml_line_count;
- }
+ curbuf->b_op_start.lnum = MIN(curbuf->b_op_start.lnum, curbuf->b_ml.ml_line_count);
+ curbuf->b_op_end.lnum = MIN(curbuf->b_op_end.lnum, curbuf->b_ml.ml_line_count);
// Adjust Extmarks
if (undo) {