diff options
author | Nikolay Orlyuk <virkony@gmail.com> | 2014-05-04 19:51:31 +0300 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2015-08-25 19:31:08 -0400 |
commit | bbe24da869a071e5dd203f2ff7e249ec06ac6c95 (patch) | |
tree | d1d3d133d38039792e42a09672558255f2e21aa6 /src | |
parent | fc7055f6e951ab0973f121a13a87c4438a799c5c (diff) | |
download | rneovim-bbe24da869a071e5dd203f2ff7e249ec06ac6c95.tar.gz rneovim-bbe24da869a071e5dd203f2ff7e249ec06ac6c95.tar.bz2 rneovim-bbe24da869a071e5dd203f2ff7e249ec06ac6c95.zip |
fix strict-overflow cases #3236
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/getchar.c | 16 | ||||
-rw-r--r-- | src/nvim/undo.c | 12 |
2 files changed, 13 insertions, 15 deletions
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 6a6e4f2214..604425b3ba 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -4109,7 +4109,6 @@ check_map ( int hash; int len, minlen; mapblock_T *mp; - char_u *s; int local; validate_maphash(); @@ -4133,17 +4132,14 @@ check_map ( /* skip entries with wrong mode, wrong length and not matching * ones */ if ((mp->m_mode & mode) && (!exact || mp->m_keylen == len)) { - if (len > mp->m_keylen) - minlen = mp->m_keylen; - else - minlen = len; - s = mp->m_keys; - if (ign_mod && s[0] == K_SPECIAL && s[1] == KS_MODIFIER - && s[2] != NUL) { + char_u *s = mp->m_keys; + int keylen = mp->m_keylen; + if (ign_mod && keylen >= 3 + && s[0] == K_SPECIAL && s[1] == KS_MODIFIER) { s += 3; - if (len > mp->m_keylen - 3) - minlen = mp->m_keylen - 3; + keylen -= 3; } + minlen = keylen < len ? keylen : len; if (STRNCMP(s, keys, minlen) == 0) { if (mp_ptr != NULL) *mp_ptr = mp; diff --git a/src/nvim/undo.c b/src/nvim/undo.c index 329af8acdd..36b629b0b5 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -212,8 +212,11 @@ static void u_check(int newhead_may_be_NULL) { */ int u_save_cursor(void) { - return u_save((linenr_T)(curwin->w_cursor.lnum - 1), - (linenr_T)(curwin->w_cursor.lnum + 1)); + linenr_T cur = curwin->w_cursor.lnum; + linenr_T top = cur > 0 ? cur - 1 : 0; + linenr_T bot = cur + 1; + + return u_save(top, bot); } /* @@ -227,10 +230,9 @@ int u_save(linenr_T top, linenr_T bot) if (undo_off) return OK; - if (top > curbuf->b_ml.ml_line_count - || top >= bot - || bot > curbuf->b_ml.ml_line_count + 1) + if (top >= bot || bot > (curbuf->b_ml.ml_line_count + 1)) { return FAIL; /* rely on caller to do error messages */ + } if (top + 2 == bot) u_saveline((linenr_T)(top + 1)); |