aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/CMakeLists.txt36
-rw-r--r--src/nvim/msgpack_rpc/channel.c2
-rw-r--r--src/nvim/msgpack_rpc/server.c3
-rw-r--r--src/nvim/os/input.c14
-rw-r--r--src/nvim/os/shell.c28
-rw-r--r--src/nvim/os/time.c38
6 files changed, 61 insertions, 60 deletions
diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt
index 1cedeebb37..a77e5e27a0 100644
--- a/src/nvim/CMakeLists.txt
+++ b/src/nvim/CMakeLists.txt
@@ -38,8 +38,7 @@ endforeach()
list(REMOVE_ITEM NEOVIM_SOURCES ${to_remove})
-set(CONV_SRCS
- api.c
+set(CONV_SOURCES
arabic.c
cursor.c
garray.c
@@ -48,31 +47,24 @@ set(CONV_SRCS
map.c
memory.c
misc2.c
- map.c
profile.c
- os/env.c
- os/event.c
- os/job.c
- os/mem.c
- os/rstream.c
- os/signal.c
- os/users.c
- os/provider.c
- os/uv_helpers.c
- os/wstream.c
- os/msgpack_rpc.c
tempfile.c
- api/buffer.c
- api/private/helpers.c
- api/private/handle.c
- api/tabpage.c
- api/window.c
- api/vim.h
- api/vim.c
)
+foreach(sfile ${CONV_SOURCES})
+ if(NOT EXISTS "${PROJECT_SOURCE_DIR}/src/nvim/${sfile}")
+ message(FATAL_ERROR "${sfile} doesn't exist(it was added to CONV_SOURCES)")
+ endif()
+endforeach()
+
+file(GLOB_RECURSE EXTRA_CONV_SOURCES os/*.c api/*.c msgpack_rpc/*.c)
+foreach(sfile ${EXTRA_CONV_SOURCES})
+ file(RELATIVE_PATH f "${PROJECT_SOURCE_DIR}/src/nvim" "${sfile}")
+ list(APPEND CONV_SOURCES ${f})
+endforeach()
+
set_source_files_properties(
- ${CONV_SRCS} PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -Wconversion")
+ ${CONV_SOURCES} PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -Wconversion")
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
if(DEFINED ENV{SANITIZE})
diff --git a/src/nvim/msgpack_rpc/channel.c b/src/nvim/msgpack_rpc/channel.c
index 6ddda10c5f..a1ab12f7c3 100644
--- a/src/nvim/msgpack_rpc/channel.c
+++ b/src/nvim/msgpack_rpc/channel.c
@@ -331,7 +331,7 @@ static void parse_msgpack(RStream *rstream, void *data, bool eof)
goto end;
}
- uint32_t count = rstream_pending(rstream);
+ size_t count = rstream_pending(rstream);
DLOG("Feeding the msgpack parser with %u bytes of data from RStream(%p)",
count,
rstream);
diff --git a/src/nvim/msgpack_rpc/server.c b/src/nvim/msgpack_rpc/server.c
index 33e01fe562..087ba24111 100644
--- a/src/nvim/msgpack_rpc/server.c
+++ b/src/nvim/msgpack_rpc/server.c
@@ -119,7 +119,8 @@ int server_start(const char *endpoint)
ip_end = strchr(addr, NUL);
}
- uint32_t addr_len = ip_end - addr;
+ // (ip_end - addr) is always > 0, so convert to size_t
+ size_t addr_len = (size_t)(ip_end - addr);
if (addr_len > sizeof(ip) - 1) {
// Maximum length of an IP address buffer is 15(eg: 255.255.255.255)
diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c
index d9dae2b44e..cc693b9f1b 100644
--- a/src/nvim/os/input.c
+++ b/src/nvim/os/input.c
@@ -72,7 +72,7 @@ void input_stop(void)
}
// Low level input function.
-int os_inchar(uint8_t *buf, int maxlen, int32_t ms, int tb_change_cnt)
+int os_inchar(uint8_t *buf, int maxlen, int ms, int tb_change_cnt)
{
InbufPollResult result;
@@ -86,7 +86,7 @@ int os_inchar(uint8_t *buf, int maxlen, int32_t ms, int tb_change_cnt)
return 0;
}
} else {
- if ((result = inbuf_poll(p_ut)) == kInputNone) {
+ if ((result = inbuf_poll((int)p_ut)) == kInputNone) {
if (trigger_cursorhold() && maxlen >= 3
&& !typebuf_changed(tb_change_cnt)) {
buf[0] = K_SPECIAL;
@@ -116,7 +116,9 @@ int os_inchar(uint8_t *buf, int maxlen, int32_t ms, int tb_change_cnt)
}
convert_input();
- return rbuffer_read(input_buffer, (char *)buf, maxlen);
+ // Safe to convert rbuffer_read to int, it will never overflow since
+ // we use relatively small buffers.
+ return (int)rbuffer_read(input_buffer, (char *)buf, (size_t)maxlen);
}
// Check if a character is available for reading
@@ -170,7 +172,7 @@ static bool input_poll(int ms)
}
// This is a replacement for the old `WaitForChar` function in os_unix.c
-static InbufPollResult inbuf_poll(int32_t ms)
+static InbufPollResult inbuf_poll(int ms)
{
if (typebuf_was_filled || rbuffer_pending(input_buffer)) {
return kInputAvail;
@@ -260,9 +262,9 @@ static void convert_input(void)
char *inbuf = rbuffer_read_ptr(input_buffer);
size_t count = rbuffer_pending(input_buffer), consume_count = 0;
- for (int i = count - 1; i >= 0; i--) {
+ for (int i = (int)count - 1; i >= 0; i--) {
if (inbuf[i] == 3) {
- consume_count = i + 1;
+ consume_count = (size_t)(i + 1);
break;
}
}
diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c
index 453cc6d605..a127597e52 100644
--- a/src/nvim/os/shell.c
+++ b/src/nvim/os/shell.c
@@ -1,4 +1,5 @@
#include <string.h>
+#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
@@ -58,11 +59,11 @@ typedef struct {
/// `shell_free_argv` when no longer needed.
char **shell_build_argv(const char_u *cmd, const char_u *extra_shell_opt)
{
- int argc = tokenize(p_sh, NULL) + tokenize(p_shcf, NULL);
+ size_t argc = tokenize(p_sh, NULL) + tokenize(p_shcf, NULL);
char **rv = xmalloc((unsigned)((argc + 4) * sizeof(char *)));
// Split 'shell'
- int i = tokenize(p_sh, rv);
+ size_t i = tokenize(p_sh, rv);
if (extra_shell_opt != NULL) {
// Push a copy of `extra_shell_opt`
@@ -356,9 +357,9 @@ static void system_data_cb(RStream *rstream, void *data, bool eof)
/// @param argv The vector that will be filled with copies of the parsed
/// words. It can be NULL if the caller only needs to count words.
/// @return The number of words parsed.
-static int tokenize(const char_u *str, char **argv)
+static size_t tokenize(const char_u *str, char **argv)
{
- int argc = 0, len;
+ size_t argc = 0, len;
char_u *p = (char_u *) str;
while (*p != NUL) {
@@ -383,11 +384,11 @@ static int tokenize(const char_u *str, char **argv)
///
/// @param str A pointer to the first character of the word
/// @return The offset from `str` at which the word ends.
-static int word_length(const char_u *str)
+static size_t word_length(const char_u *str)
{
const char_u *p = str;
bool inquote = false;
- int length = 0;
+ size_t length = 0;
// Move `p` to the end of shell word by advancing the pointer while it's
// inside a quote or it's a non-whitespace character
@@ -418,15 +419,15 @@ static void write_selection(uv_write_t *req)
// TODO(tarruda): use a static buffer for up to a limit(BUFFER_LENGTH) and
// only after filled we should start allocating memory(skip unnecessary
// allocations for small writes)
- int buflen = BUFFER_LENGTH;
+ size_t buflen = BUFFER_LENGTH;
pdata->wbuffer = (char *)xmalloc(buflen);
uv_buf_t uvbuf;
linenr_T lnum = curbuf->b_op_start.lnum;
- int off = 0;
- int written = 0;
+ size_t off = 0;
+ size_t written = 0;
char_u *lp = ml_get(lnum);
- int l;
- int len;
+ size_t l;
+ size_t len;
for (;;) {
l = strlen((char *)lp + written);
@@ -443,7 +444,7 @@ static void write_selection(uv_write_t *req)
pdata->wbuffer[off++] = NUL;
} else {
char_u *s = vim_strchr(lp + written, NL);
- len = s == NULL ? l : s - (lp + written);
+ len = s == NULL ? l : (size_t)(s - (lp + written));
while (off + len >= buflen) {
// Resize the buffer
buflen *= 2;
@@ -584,6 +585,7 @@ static void exit_cb(uv_process_t *proc, int64_t status, int term_signal)
{
ProcessData *data = (ProcessData *)proc->data;
data->exited++;
- data->exit_status = status;
+ assert(status <= INT_MAX);
+ data->exit_status = (int)status;
uv_close((uv_handle_t *)proc, NULL);
}
diff --git a/src/nvim/os/time.c b/src/nvim/os/time.c
index e3b76ac833..a4871ef499 100644
--- a/src/nvim/os/time.c
+++ b/src/nvim/os/time.c
@@ -1,3 +1,4 @@
+#include <assert.h>
#include <stdint.h>
#include <stdbool.h>
#include <time.h>
@@ -64,23 +65,6 @@ void os_microdelay(uint64_t microseconds, bool ignoreinput)
}
}
-static void microdelay(uint64_t microseconds)
-{
- uint64_t hrtime;
- int64_t ns = microseconds * 1000; // convert to nanoseconds
-
- uv_mutex_lock(&delay_mutex);
-
- while (ns > 0) {
- hrtime = uv_hrtime();
- if (uv_cond_timedwait(&delay_cond, &delay_mutex, ns) == UV_ETIMEDOUT)
- break;
- ns -= uv_hrtime() - hrtime;
- }
-
- uv_mutex_unlock(&delay_mutex);
-}
-
/// Portable version of POSIX localtime_r()
///
/// @return NULL in case of error
@@ -112,3 +96,23 @@ struct tm *os_get_localtime(struct tm *result) FUNC_ATTR_NONNULL_ALL
time_t rawtime = time(NULL);
return os_localtime_r(&rawtime, result);
}
+
+static void microdelay(uint64_t microseconds)
+{
+ uint64_t elapsed = 0;
+ uint64_t ns = microseconds * 1000; // convert to nanoseconds
+ uint64_t base = uv_hrtime();
+
+ uv_mutex_lock(&delay_mutex);
+
+ while (elapsed < ns) {
+ if (uv_cond_timedwait(&delay_cond, &delay_mutex, ns - elapsed)
+ == UV_ETIMEDOUT)
+ break;
+ uint64_t now = uv_hrtime();
+ elapsed += now - base;
+ base = now;
+ }
+
+ uv_mutex_unlock(&delay_mutex);
+}