From 04fb65fd76af2fda4302fd79b81f59085d2d5fbe Mon Sep 17 00:00:00 2001 From: Jente Hidskes Date: Fri, 17 Feb 2017 23:29:42 +0100 Subject: screen.c: account for translated string length `[RO]` is appended to the status line and `len` is increased with the length of this string (4). However, the string is marked for translation and may thus well be larger (or smaller) than 4. Therefore, we check the length at runtime. The resulting len is never actually used, and thus could be removed. However, by keeping this line, the body of this if-statement is kept consistent with surrounding code, and future changes can not forget to add this line when additional strings are added to p. --- src/nvim/screen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 6df443754b..fd3489c503 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -4876,7 +4876,7 @@ void win_redr_status(win_T *wp) } if (wp->w_buffer->b_p_ro) { STRCPY(p + len, _("[RO]")); - len += 4; + len += (int)STRLEN(p + len); } this_ru_col = ru_col - (Columns - wp->w_width); -- cgit From 83666f3ce21d748c9e0b8caa307e855a9dcc3626 Mon Sep 17 00:00:00 2001 From: Sander Bosma Date: Sun, 19 Feb 2017 18:31:46 +0100 Subject: screen.c: remove dead code As stated in globals.h, mbyte flags are deprecated, and code using it can be refractored to remove dead code. Since has_mbyte is defined to true, this refractoring correct. --- src/nvim/screen.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index fd3489c503..bb1f4b9a14 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -4880,33 +4880,30 @@ void win_redr_status(win_T *wp) } this_ru_col = ru_col - (Columns - wp->w_width); - if (this_ru_col < (wp->w_width + 1) / 2) + if (this_ru_col < (wp->w_width + 1) / 2) { this_ru_col = (wp->w_width + 1) / 2; + } if (this_ru_col <= 1) { - p = (char_u *)"<"; /* No room for file name! */ + p = (char_u *)"<"; // No room for file name! len = 1; - } else if (has_mbyte) { + } else { int clen = 0, i; - /* Count total number of display cells. */ - clen = (int) mb_string2cells(p); + // Count total number of display cells. + clen = (int)mb_string2cells(p); - /* Find first character that will fit. - * Going from start to end is much faster for DBCS. */ + // Find first character that will fit. + // Going from start to end is much faster for DBCS. for (i = 0; p[i] != NUL && clen >= this_ru_col - 1; - i += (*mb_ptr2len)(p + i)) + i += (*mb_ptr2len)(p + i)) { clen -= (*mb_ptr2cells)(p + i); + } len = clen; if (i > 0) { p = p + i - 1; *p = '<'; ++len; } - - } else if (len > this_ru_col - 1) { - p += len - (this_ru_col - 1); - *p = '<'; - len = this_ru_col - 1; } row = wp->w_winrow + wp->w_height; -- cgit From 8e194c53c78cea7a93caeabfd5b4a72be3a40933 Mon Sep 17 00:00:00 2001 From: Sander Bosma Date: Sun, 19 Feb 2017 20:53:39 +0100 Subject: misc1.c: remove dead initialization --- src/nvim/misc1.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src') diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index db34159f24..eee3c81acf 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -1405,7 +1405,6 @@ void ins_char_bytes(char_u *buf, size_t charlen) coladvance_force(getviscol()); } - int c = buf[0]; size_t col = (size_t)curwin->w_cursor.col; linenr_T lnum = curwin->w_cursor.lnum; char_u *oldp = ml_get(lnum); @@ -1498,10 +1497,7 @@ void ins_char_bytes(char_u *buf, size_t charlen) && msg_silent == 0 && !ins_compl_active() ) { - if (has_mbyte) - showmatch(mb_ptr2char(buf)); - else - showmatch(c); + showmatch(mb_ptr2char(buf)); } if (!p_ri || (State & REPLACE_FLAG)) { -- cgit From ddd8f7d333645169d94bdf8a0ec551a40620a19e Mon Sep 17 00:00:00 2001 From: Sander Bosma Date: Sun, 19 Feb 2017 20:59:11 +0100 Subject: message.c: fix dead assignment by removing dead code `enc_dbcs` and `enc_utf8` are deprecated (globals.h), so the second branch is always taken. --- src/nvim/message.c | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/nvim/message.c b/src/nvim/message.c index 5427ae7793..699f4b87b9 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -269,33 +269,18 @@ void trunc_string(char_u *s, char_u *buf, int room, int buflen) } } - /* Last part: End of the string. */ - i = e; - if (enc_dbcs != 0) { - /* For DBCS going backwards in a string is slow, but - * computing the cell width isn't too slow: go forward - * until the rest fits. */ - n = vim_strsize(s + i); - while (len + n > room) { - n -= ptr2cells(s + i); - i += (*mb_ptr2len)(s + i); - } - } else if (enc_utf8) { - /* For UTF-8 we can go backwards easily. */ - half = i = (int)STRLEN(s); - for (;; ) { - do - half = half - (*mb_head_off)(s, s + half - 1) - 1; - while (utf_iscomposing(utf_ptr2char(s + half)) && half > 0); - n = ptr2cells(s + half); - if (len + n > room) - break; - len += n; - i = half; + // Last part: End of the string. + half = i = (int)STRLEN(s); + for (;;) { + do { + half = half - (*mb_head_off)(s, s + half - 1) - 1; + } while (utf_iscomposing(utf_ptr2char(s + half)) && half > 0); + n = ptr2cells(s + half); + if (len + n > room) { + break; } - } else { - for (i = (int)STRLEN(s); len + (n = ptr2cells(s + i - 1)) <= room; --i) - len += n; + len += n; + i = half; } if (i <= e + 3) { -- cgit From 192fd161f985d43e7432824665ae6caeb532808c Mon Sep 17 00:00:00 2001 From: Sander Bosma Date: Sun, 19 Feb 2017 21:08:14 +0100 Subject: hardcopy.c: fix dead assignment `has_mbyte` is deprecated (globals.h), so `outputlen` is always assigned within the if statement. Therefore, the previous initialization is unnecessary. --- src/nvim/hardcopy.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index c2dc6231f1..19d97ecfef 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -845,12 +845,10 @@ static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T * Loop over the columns until the end of the file line or right margin. */ for (col = ppos->column; line[col] != NUL && !need_break; col += outputlen) { - outputlen = 1; - if (has_mbyte && (outputlen = (*mb_ptr2len)(line + col)) < 1) + if ((outputlen = (*mb_ptr2len)(line + col)) < 1) { outputlen = 1; - /* - * syntax highlighting stuff. - */ + } + // syntax highlighting stuff. if (psettings->do_syntax) { id = syn_get_id(curwin, ppos->file_line, col, 1, NULL, FALSE); if (id > 0) -- cgit From 1a81ec6d8841e96ce01f25fd030f76851b00d895 Mon Sep 17 00:00:00 2001 From: Jente Hidskes Date: Sun, 19 Feb 2017 23:18:00 +0100 Subject: strings.c: remove unused assignment As reported by clang-scan, `length_modifier` is never read in any code path following this branch. It is safe to remove. --- src/nvim/strings.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/nvim/strings.c b/src/nvim/strings.c index f7218cc267..5b6fbf75a9 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -980,7 +980,6 @@ int vim_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap, const void *ptr_arg = NULL; if (fmt_spec == 'p') { - length_modifier = '\0'; ptr_arg = tvs ? tv_ptr(tvs, &arg_idx) : va_arg(ap, void *); if (ptr_arg) { arg_sign = 1; -- cgit