diff options
author | KillTheMule <KillTheMule@users.noreply.github.com> | 2018-02-11 23:02:53 +0100 |
---|---|---|
committer | KillTheMule <KillTheMule@users.noreply.github.com> | 2018-05-23 22:07:27 +0200 |
commit | 2106bada5bbd6de4729a8714d011e0eca61cee35 (patch) | |
tree | 63ac8998a25853f3fd5cbf5af1556b368a63dbcf | |
parent | 6bdcbef2f5acfd9815599c751bd8dcbe3204281f (diff) | |
download | rneovim-2106bada5bbd6de4729a8714d011e0eca61cee35.tar.gz rneovim-2106bada5bbd6de4729a8714d011e0eca61cee35.tar.bz2 rneovim-2106bada5bbd6de4729a8714d011e0eca61cee35.zip |
Enable -Wconversion
-rw-r--r-- | src/nvim/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/nvim/api/buffer.c | 10 | ||||
-rw-r--r-- | src/nvim/buffer_updates.c | 22 | ||||
-rw-r--r-- | src/nvim/buffer_updates.h | 11 | ||||
-rw-r--r-- | src/nvim/ex_cmds.c | 2 | ||||
-rw-r--r-- | src/nvim/fold.c | 6 | ||||
-rw-r--r-- | src/nvim/misc1.c | 6 | ||||
-rw-r--r-- | src/nvim/undo.c | 4 |
8 files changed, 38 insertions, 24 deletions
diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index 97495eec6d..2d803792c8 100644 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -142,7 +142,6 @@ set(CONV_SOURCES message.c regexp.c screen.c - buffer_updates.c search.c spell.c spellfile.c diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index d59ce1ce3d..f6a6534560 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -85,9 +85,9 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err) /// @return False when updates couldn't be enabled because the buffer isn't /// loaded; otherwise True. Boolean nvim_buf_attach(uint64_t channel_id, - Buffer buffer, - Boolean send_buffer, - Error *err) + Buffer buffer, + Boolean send_buffer, + Error *err) FUNC_API_SINCE(4) FUNC_API_REMOTE_ONLY { buf_T *buf = find_buffer_by_handle(buffer, err); @@ -106,8 +106,8 @@ Boolean nvim_buf_attach(uint64_t channel_id, /// @return False when updates couldn't be disabled because the buffer /// isn't loaded; otherwise True. Boolean nvim_buf_detach(uint64_t channel_id, - Buffer buffer, - Error *err) + Buffer buffer, + Error *err) FUNC_API_SINCE(4) FUNC_API_REMOTE_ONLY { buf_T *buf = find_buffer_by_handle(buffer, err); diff --git a/src/nvim/buffer_updates.c b/src/nvim/buffer_updates.c index d7bb11d125..3d0c969491 100644 --- a/src/nvim/buffer_updates.c +++ b/src/nvim/buffer_updates.c @@ -2,6 +2,7 @@ #include "nvim/memline.h" #include "nvim/api/private/helpers.h" #include "nvim/msgpack_rpc/channel.h" +#include "nvim/assert.h" // Register a channel. Return True if the channel was added, or already added. // Return False if the channel couldn't be added because the buffer is @@ -30,7 +31,10 @@ bool buffer_updates_register(buf_T *buf, uint64_t channel_id, bool send_buffer) Array linedata = ARRAY_DICT_INIT; if (send_buffer) { // collect buffer contents - size_t line_count = buf->b_ml.ml_line_count; + // True now, but a compile time reminder for future systems we support + STATIC_ASSERT(SIZE_MAX >= MAXLNUM, "size_t to small to hold the number of" + " lines in a buffer"); + size_t line_count = (size_t)buf->b_ml.ml_line_count; linedata.size = line_count; linedata.items = xcalloc(sizeof(Object), line_count); for (size_t i = 0; i < line_count; i++) { @@ -118,8 +122,11 @@ void buffer_updates_unregister_all(buf_T *buf) } } -void buffer_updates_send_changes(buf_T *buf, linenr_T firstline, int64_t num_added, - int64_t num_removed, bool send_tick) +void buffer_updates_send_changes(buf_T *buf, + linenr_T firstline, + int64_t num_added, + int64_t num_removed, + bool send_tick) { // if one the channels doesn't work, put its ID here so we can remove it later uint64_t badchannelid = 0; @@ -148,8 +155,13 @@ void buffer_updates_send_changes(buf_T *buf, linenr_T firstline, int64_t num_add // linedata of lines being swapped in Array linedata = ARRAY_DICT_INIT; if (num_added > 0) { - linedata.size = num_added; - linedata.items = xcalloc(sizeof(Object), num_added); + // True now, but a compile time reminder for future systems we support + // Note that `num_added` is a `int64_t`, but still must be lower than + // `MAX_LNUM` + STATIC_ASSERT(SIZE_MAX >= MAXLNUM, "size_t to small to hold the number " + "of lines in a buffer"); + linedata.size = (size_t)num_added; + linedata.items = xcalloc(sizeof(Object), (size_t)num_added); for (int64_t i = 0; i < num_added; i++) { int64_t lnum = firstline + i; const char *bufstr = (char *)ml_get_buf(buf, (linenr_T)lnum, false); diff --git a/src/nvim/buffer_updates.h b/src/nvim/buffer_updates.h index 8fe33a0ebe..63ae2d3984 100644 --- a/src/nvim/buffer_updates.h +++ b/src/nvim/buffer_updates.h @@ -1,13 +1,16 @@ -#ifndef BUFFER_UPDATES_H -#define BUFFER_UPDATES_H +#ifndef NVIM_BUFFER_UPDATES_H +#define NVIM_BUFFER_UPDATES_H #include "nvim/buffer_defs.h" bool buffer_updates_register(buf_T *buf, uint64_t channel_id, bool send_buffer); void buffer_updates_unregister(buf_T *buf, uint64_t channel_id); void buffer_updates_unregister_all(buf_T *buf); -void buffer_updates_send_changes(buf_T *buf, linenr_T firstline, int64_t num_added, - int64_t num_removed, bool send_tick); +void buffer_updates_send_changes(buf_T *buf, + linenr_T firstline, + int64_t num_added, + int64_t num_removed, + bool send_tick); void buffer_updates_send_tick(buf_T *buf); #endif // NVIM_BUFFER_UPDATES_H diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index fdb8c87213..3960412782 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -4022,7 +4022,7 @@ skip: int64_t num_added = last_line - first_line; int64_t num_removed = num_added - i; buffer_updates_send_changes(curbuf, first_line, num_added, num_removed, - send_buffer_update_changedtick); + send_buffer_update_changedtick); } } diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 2cf1c6f394..9869e0fd30 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -754,7 +754,7 @@ deleteFold ( // notification that includes every line that was part of the fold int64_t num_changed = last_lnum - first_lnum; buffer_updates_send_changes(curbuf, first_lnum, num_changed, - num_changed, true); + num_changed, true); } } } @@ -1607,8 +1607,8 @@ static void foldCreateMarkers(linenr_T start, linenr_T end) if (kv_size(curbuf->update_channels)) { // Note: foldAddMarker() may not actually change start and/or end if - // u_save() is unable to save the buffer line, but we send the nvim_buf_update - // anyway since it won't do any harm. + // u_save() is unable to save the buffer line, but we send the + // nvim_buf_update anyway since it won't do any harm. int64_t num_changed = 1 + end - start; buffer_updates_send_changes(curbuf, start, num_changed, num_changed, true); } diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 7c9e728c92..47ec3eff32 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -1921,9 +1921,9 @@ changed_lines( linenr_T lnume, // line below last changed line long xtra, // number of extra lines (negative when deleting) bool send_update // some callers like undo/redo call changed_lines() - // and then increment b_changedtick *again*. This flag - // allows these callers to send the nvim_buf_update events - // after they're done modifying b_changedtick. + // and then increment b_changedtick *again*. This flag + // allows these callers to send the nvim_buf_update events + // after they're done modifying b_changedtick. ) { changed_lines_buf(curbuf, lnum, lnume, xtra); diff --git a/src/nvim/undo.c b/src/nvim/undo.c index 9da9693c90..ed4515398d 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -1698,8 +1698,8 @@ bool u_undo_and_forget(int count) count = 1; } undo_undoes = true; - // don't send a nvim_buf_update for this undo is part of 'inccommand' playing with - // buffer contents + // don't send a nvim_buf_update for this undo is part of 'inccommand' playing + // with buffer contents u_doit(count, true, false); if (curbuf->b_u_curhead == NULL) { |