aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/cursor.c
diff options
context:
space:
mode:
authorPavel Platto <hinidu@gmail.com>2014-05-15 16:49:58 +0300
committerJustin M. Keyes <justinkz@gmail.com>2014-05-28 10:42:06 -0400
commit2a154ef71de506e64fbbc2d8e613b5a696f8cb60 (patch)
tree647f302c1d1ae4366c1214887b8d4beb202f4c7f /src/nvim/cursor.c
parente62722922b671d6f529570af8c96c463878dd46d (diff)
downloadrneovim-2a154ef71de506e64fbbc2d8e613b5a696f8cb60.tar.gz
rneovim-2a154ef71de506e64fbbc2d8e613b5a696f8cb60.tar.bz2
rneovim-2a154ef71de506e64fbbc2d8e613b5a696f8cb60.zip
Enable -Wconversion on cursor.c
Diffstat (limited to 'src/nvim/cursor.c')
-rw-r--r--src/nvim/cursor.c36
1 files changed, 12 insertions, 24 deletions
diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c
index 661516b52d..e90422bf6d 100644
--- a/src/nvim/cursor.c
+++ b/src/nvim/cursor.c
@@ -161,16 +161,9 @@ coladvance2 (
if (line[idx] == NUL) {
/* Append spaces */
int correct = wcol - col;
- char_u *newline = xmalloc(idx + correct + 1);
- int t;
-
- for (t = 0; t < idx; ++t)
- newline[t] = line[t];
-
- for (t = 0; t < correct; ++t)
- newline[t + idx] = ' ';
-
- newline[idx + correct] = NUL;
+ char_u *newline = xmallocz((size_t)(idx + correct));
+ memcpy(newline, line, (size_t)idx);
+ memset(newline + idx, ' ', (size_t)correct);
ml_replace(pos->lnum, newline, FALSE);
changed_bytes(pos->lnum, (colnr_T)idx);
@@ -181,23 +174,18 @@ coladvance2 (
int linelen = (int)STRLEN(line);
int correct = wcol - col - csize + 1; /* negative!! */
char_u *newline;
- int t, s = 0;
- int v;
if (-correct > csize)
return FAIL;
- newline = xmalloc(linelen + csize);
-
- for (t = 0; t < linelen; t++) {
- if (t != idx)
- newline[s++] = line[t];
- else
- for (v = 0; v < csize; v++)
- newline[s++] = ' ';
- }
-
- newline[linelen + csize - 1] = NUL;
+ newline = xmallocz((size_t)(linelen - 1 + csize));
+ // Copy first idx chars
+ memcpy(newline, line, (size_t)idx);
+ // Replace idx'th char with csize spaces
+ memset(newline + idx, ' ', (size_t)csize);
+ // Copy the rest of the line
+ memcpy(newline + idx + csize, line + idx + 1,
+ (size_t)(linelen - idx - 1));
ml_replace(pos->lnum, newline, FALSE);
changed_bytes(pos->lnum, idx);
@@ -464,7 +452,7 @@ int gchar_cursor(void)
* Write a character at the current cursor position.
* It is directly written into the block.
*/
-void pchar_cursor(int c)
+void pchar_cursor(char_u c)
{
*(ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE)
+ curwin->w_cursor.col) = c;