diff options
author | Pavel Platto <hinidu@gmail.com> | 2014-05-15 16:49:58 +0300 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2014-05-28 10:42:06 -0400 |
commit | 2a154ef71de506e64fbbc2d8e613b5a696f8cb60 (patch) | |
tree | 647f302c1d1ae4366c1214887b8d4beb202f4c7f | |
parent | e62722922b671d6f529570af8c96c463878dd46d (diff) | |
download | rneovim-2a154ef71de506e64fbbc2d8e613b5a696f8cb60.tar.gz rneovim-2a154ef71de506e64fbbc2d8e613b5a696f8cb60.tar.bz2 rneovim-2a154ef71de506e64fbbc2d8e613b5a696f8cb60.zip |
Enable -Wconversion on cursor.c
-rw-r--r-- | src/nvim/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/nvim/cursor.c | 36 | ||||
-rw-r--r-- | src/nvim/cursor.h | 2 |
3 files changed, 14 insertions, 25 deletions
diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index bdb262731d..b74832840c 100644 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -36,6 +36,7 @@ file( GLOB API_PRIV_SOURCES api/private/*.c ) set(CONV_SRCS api.c arabic.c + cursor.c garray.c hashtab.c memory.c 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; diff --git a/src/nvim/cursor.h b/src/nvim/cursor.h index bbd20683bf..5cf28ce590 100644 --- a/src/nvim/cursor.h +++ b/src/nvim/cursor.h @@ -19,7 +19,7 @@ void check_cursor(void); void adjust_cursor_col(void); int leftcol_changed(void); int gchar_cursor(void); -void pchar_cursor(int c); +void pchar_cursor(char_u c); char_u *ml_get_curline(void); char_u *ml_get_cursor(void); |