vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 8cf108d337f26bda64e3647ef5425209f2f1548f parent 52250bbd4ca6aab3a14e6d7537b39e83d4b0c3a0 Author: Marc André Tanner <mat@brain-dump.org> Date: Wed, 5 Oct 2016 22:06:06 +0200 Fix various issues reported by coverity scan Diffstat:
| M | buffer.c | | | 4 | +++- |
| M | text-util.c | | | 3 | +-- |
| M | ui-curses.c | | | 4 | +++- |
| M | vis-lua.c | | | 2 | +- |
| M | vis-menu.c | | | 2 | +- |
5 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/buffer.c b/buffer.c @@ -118,8 +118,10 @@ bool buffer_vprintf(Buffer *buf, const char *fmt, va_list ap) { va_list ap_save; va_copy(ap_save, ap); int len = vsnprintf(NULL, 0, fmt, ap); - if (len == -1 || !buffer_grow(buf, len+1)) + if (len == -1 || !buffer_grow(buf, len+1)) { + va_end(ap_save); return false; + } bool ret = vsnprintf(buf->data, len+1, fmt, ap_save) == len; if (ret) buf->len = len+1; diff --git a/text-util.c b/text-util.c @@ -84,7 +84,6 @@ int text_string_width(const char *data, size_t len) { const char *s = data; while (len > 0) { - char buf[MB_CUR_MAX]; wchar_t wc; size_t wclen = mbrtowc(&wc, s, len, &ps); if (wclen == (size_t)-1 && errno == EILSEQ) { @@ -98,7 +97,7 @@ int text_string_width(const char *data, size_t len) { /* assume NUL byte will be displayed as ^@ */ width += 2; wclen = 1; - } else if (buf[0] == '\t') { + } else if (wc == L'\t') { width++; wclen = 1; } else { diff --git a/ui-curses.c b/ui-curses.c @@ -1103,8 +1103,10 @@ static const char *ui_getkey(Ui *ui) { int tty = open("/dev/tty", O_RDWR); if (tty == -1) goto fatal; - if (tty != STDIN_FILENO && dup2(tty, STDIN_FILENO) == -1) + if (tty != STDIN_FILENO && dup2(tty, STDIN_FILENO) == -1) { + close(tty); goto fatal; + } close(tty); termkey_destroy(uic->termkey); if (!(uic->termkey = ui_termkey_new(STDIN_FILENO))) diff --git a/vis-lua.c b/vis-lua.c @@ -800,7 +800,7 @@ static int window_index(lua_State *L) { const char *key = lua_tostring(L, 2); if (strcmp(key, "viewport") == 0) { - Filerange r = win ? view_viewport_get(win->view) : text_range_empty(); + Filerange r = view_viewport_get(win->view); pushrange(L, &r); return 1; } diff --git a/vis-menu.c b/vis-menu.c @@ -458,7 +458,7 @@ run(void) { return EXIT_FAILURE; case CONTROL('M'): /* Return */ case CONTROL('J'): - if (sel) strncpy(text, sel->text, sizeof text); /* Complete the input first, when hitting return */ + if (sel) strncpy(text, sel->text, sizeof(text)-1); /* Complete the input first, when hitting return */ cursor = strlen(text); match(); drawmenu();