Skip to content

Commit

Permalink
Fix various issues reported by coverity scan
Browse files Browse the repository at this point in the history
  • Loading branch information
martanne committed Oct 5, 2016
1 parent e3c1f30 commit fc575f6
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
4 changes: 3 additions & 1 deletion buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions text-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion ui-curses.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
2 changes: 1 addition & 1 deletion vis-lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion vis-menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit fc575f6

Please sign in to comment.