From 7217360e349ff787933d91b55efdfeb435eb45cb Mon Sep 17 00:00:00 2001 From: James McCoy Date: Mon, 6 Mar 2017 10:44:07 -0500 Subject: vim-patch:7.4.2051 Problem: No proper testing of trunc_string(). Solution: Add a unittest for message.c. https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f --- src/nvim/message.c | 2 +- src/nvim/version.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim') diff --git a/src/nvim/message.c b/src/nvim/message.c index 699f4b87b9..57f7369e73 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -257,7 +257,7 @@ void trunc_string(char_u *s, char_u *buf, int room, int buflen) return; } n = ptr2cells(s + e); - if (len + n >= half) + if (len + n > half) break; len += n; buf[e] = s[e]; diff --git a/src/nvim/version.c b/src/nvim/version.c index 8fd9b4b74f..b755404a58 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -389,7 +389,7 @@ static int included_patches[] = { // 2054 NA // 2053 NA // 2052 NA - // 2051, + 2051, 2050, 2049, // 2048 NA -- cgit From 4e3a2784ec3cb4ff79bd48f55a8edee817dec6e7 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Mon, 6 Mar 2017 12:14:39 -0500 Subject: vim-patch:7.4.2068 Problem: Not all arguments of trunc_string() are tested. Memory access error when running the message tests. Solution: Add another test case. (Yegappan Lakshmanan) Make it easy to run unittests with valgrind. Fix the access error. https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31 --- src/nvim/message.c | 4 ++-- src/nvim/version.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim') diff --git a/src/nvim/message.c b/src/nvim/message.c index 57f7369e73..689e8893bd 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -274,9 +274,9 @@ void trunc_string(char_u *s, char_u *buf, int room, int buflen) for (;;) { do { half = half - (*mb_head_off)(s, s + half - 1) - 1; - } while (utf_iscomposing(utf_ptr2char(s + half)) && half > 0); + } while (half > 0 && utf_iscomposing(utf_ptr2char(s + half))); n = ptr2cells(s + half); - if (len + n > room) { + if (len + n > room || half == 0) { break; } len += n; diff --git a/src/nvim/version.c b/src/nvim/version.c index b755404a58..abd3b7dfc3 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -372,7 +372,7 @@ static int included_patches[] = { 2071, // 2070 NA // 2069, - // 2068, + 2068, 2067, 2066, 2065, -- cgit From 52e56954c6fa211246a55f7877986473d21a238b Mon Sep 17 00:00:00 2001 From: James McCoy Date: Mon, 6 Mar 2017 13:31:39 -0500 Subject: vim-patch:7.4.2097 Problem: Warning from 64 bit compiler. Solution: use size_t instead of int. (Mike Williams) https://github.com/vim/vim/commit/d4f31dc45482e8db527ca044b9c3436b1e750006 --- src/nvim/message.c | 18 ++++++++++-------- src/nvim/version.c | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) (limited to 'src/nvim') diff --git a/src/nvim/message.c b/src/nvim/message.c index 689e8893bd..9d9bed2c1f 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -237,17 +237,19 @@ msg_strtrunc ( * Truncate a string "s" to "buf" with cell width "room". * "s" and "buf" may be equal. */ -void trunc_string(char_u *s, char_u *buf, int room, int buflen) +void trunc_string(char_u *s, char_u *buf, int room_in, int buflen) { - int half; - int len; + size_t room = room_in - 3; // "..." takes 3 chars + size_t half; + size_t len = 0; int e; int i; int n; - room -= 3; + if (room_in < 3) { + room = 0; + } half = room / 2; - len = 0; /* First part: Start of the string. */ for (e = 0; len < half && e < buflen; ++e) { @@ -287,7 +289,7 @@ void trunc_string(char_u *s, char_u *buf, int room, int buflen) // text fits without truncating if (s != buf) { len = STRLEN(s); - if (len >= buflen) { + if (len >= (size_t)buflen) { len = buflen - 1; } len = len - e + 1; @@ -300,8 +302,8 @@ void trunc_string(char_u *s, char_u *buf, int room, int buflen) } else if (e + 3 < buflen) { // set the middle and copy the last part memmove(buf + e, "...", (size_t)3); - len = (int)STRLEN(s + i) + 1; - if (len >= buflen - e - 3) + len = STRLEN(s + i) + 1; + if (len >= (size_t)buflen - e - 3) len = buflen - e - 3 - 1; memmove(buf + e + 3, s + i, len); buf[e + 3 + len - 1] = NUL; diff --git a/src/nvim/version.c b/src/nvim/version.c index abd3b7dfc3..1771e2b95e 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -343,7 +343,7 @@ static int included_patches[] = { 2100, 2099, 2098, - // 2097, + 2097, 2096, 2095, // 2094 NA -- cgit From 532197b4f95596e202fb230523ceb0c9e6233dae Mon Sep 17 00:00:00 2001 From: James McCoy Date: Mon, 6 Mar 2017 14:29:26 -0500 Subject: lint --- src/nvim/message.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/nvim') diff --git a/src/nvim/message.c b/src/nvim/message.c index 9d9bed2c1f..4cd0db21e8 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -259,8 +259,9 @@ void trunc_string(char_u *s, char_u *buf, int room_in, int buflen) return; } n = ptr2cells(s + e); - if (len + n > half) + if (len + n > half) { break; + } len += n; buf[e] = s[e]; if (has_mbyte) @@ -303,8 +304,9 @@ void trunc_string(char_u *s, char_u *buf, int room_in, int buflen) // set the middle and copy the last part memmove(buf + e, "...", (size_t)3); len = STRLEN(s + i) + 1; - if (len >= (size_t)buflen - e - 3) + if (len >= (size_t)buflen - e - 3) { len = buflen - e - 3 - 1; + } memmove(buf + e + 3, s + i, len); buf[e + 3 + len - 1] = NUL; } else { -- cgit