diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/interface-curses/curses-info-popup.c | 20 | ||||
| -rw-r--r-- | src/interface-curses/interface.c | 6 | ||||
| -rw-r--r-- | src/search.c | 30 |
3 files changed, 41 insertions, 15 deletions
diff --git a/src/interface-curses/curses-info-popup.c b/src/interface-curses/curses-info-popup.c index 83d4665..0e5716d 100644 --- a/src/interface-curses/curses-info-popup.c +++ b/src/interface-curses/curses-info-popup.c @@ -19,6 +19,7 @@ #include "config.h" #endif +#include <stdlib.h> #include <string.h> #include <glib.h> @@ -72,7 +73,7 @@ teco_curses_info_popup_add(teco_curses_info_popup_t *ctx, teco_popup_entry_type_ ctx->length++; } -static void +static gboolean teco_curses_info_popup_init_pad(teco_curses_info_popup_t *ctx, attr_t attr, gshort pair) { int pad_lines; /**! pad height */ @@ -100,6 +101,9 @@ teco_curses_info_popup_init_pad(teco_curses_info_popup_t *ctx, attr_t attr, gsho * and right borders. */ ctx->pad = newpad(pad_lines, COLS - 2); + if (G_UNLIKELY(!ctx->pad)) + /* can well fail for huge pad_lines */ + return FALSE; /* * NOTE: attr could contain WA_REVERSE on monochrome terminals, @@ -158,6 +162,8 @@ teco_curses_info_popup_init_pad(teco_curses_info_popup_t *ctx, attr_t attr, gsho cur_col++; } + + return TRUE; } void @@ -167,11 +173,9 @@ teco_curses_info_popup_show(teco_curses_info_popup_t *ctx, attr_t attr, gshort p /* nothing to display */ return; - if (ctx->window) - delwin(ctx->window); - - if (!ctx->pad) - teco_curses_info_popup_init_pad(ctx, attr, pair); + if (!ctx->pad && G_UNLIKELY(!teco_curses_info_popup_init_pad(ctx, attr, pair))) + /* OOM */ + return; gint pad_lines = getmaxy(ctx->pad); /* @@ -180,8 +184,12 @@ teco_curses_info_popup_show(teco_curses_info_popup_t *ctx, attr_t attr, gshort p */ gint popup_lines = MIN(pad_lines + 1, LINES - teco_cmdline.height); + if (ctx->window) + delwin(ctx->window); /* window covers message, scintilla and info windows */ ctx->window = newwin(popup_lines, 0, LINES - teco_cmdline.height - popup_lines, 0); + if (G_UNLIKELY(!ctx->window)) + abort(); wattr_set(ctx->window, attr, pair, NULL); diff --git a/src/interface-curses/interface.c b/src/interface-curses/interface.c index 11441d2..db996f5 100644 --- a/src/interface-curses/interface.c +++ b/src/interface-curses/interface.c @@ -761,7 +761,11 @@ teco_interface_init_interactive(GError **error) leaveok(stdscr, TRUE); teco_interface.info_window = newwin(1, 0, 0, 0); + if (G_UNLIKELY(!teco_interface.info_window)) + abort(); teco_interface.msg_window = newwin(1, 0, LINES - teco_cmdline.height - 1, 0); + if (G_UNLIKELY(!teco_interface.msg_window)) + abort(); WINDOW *cmdline_win = teco_view_get_window(teco_cmdline.view); wresize(cmdline_win, teco_cmdline.height, COLS); @@ -769,6 +773,8 @@ teco_interface_init_interactive(GError **error) teco_cmdline_resized(COLS); teco_interface.input_pad = newpad(1, 1); + if (G_UNLIKELY(!teco_interface.input_pad)) + abort(); /* * Controlling function key processing is important * on Unix Curses, as ESCAPE is handled as the beginning diff --git a/src/search.c b/src/search.c index 1b5026a..357a0c0 100644 --- a/src/search.c +++ b/src/search.c @@ -152,14 +152,6 @@ teco_state_search_initial(teco_machine_main_t *ctx, GError **error) teco_error_range_set(error, "S"); return FALSE; } - } else if (v2 == 0) { - /* - * NOTE: Video TECO always succeeds on `0S...$`. - * TECOC however fails just like we do. - */ - g_set_error_literal(error, TECO_ERROR, TECO_ERROR_FAILED, - "The search counter must not be zero."); - return FALSE; } else { /* search for v2-th occurrence */ teco_search_parameters.count = (gint)v2; @@ -172,6 +164,16 @@ teco_state_search_initial(teco_machine_main_t *ctx, GError **error) } } + if (!teco_search_parameters.count) { + /* + * NOTE: Video TECO always succeeds on `0S...$`. + * TECOC however fails just like we do. + */ + g_set_error_literal(error, TECO_ERROR, TECO_ERROR_FAILED, + "The search counter must not be zero."); + return FALSE; + } + teco_search_parameters.from_buffer = teco_qreg_current ? NULL : teco_ring_current; teco_search_parameters.to_buffer = NULL; return TRUE; @@ -1251,7 +1253,17 @@ teco_state_search_all_initial(teco_machine_main_t *ctx, GError **error) } } - if (teco_search_parameters.count >= 0) { + if (!teco_search_parameters.count) { + /* + * NOTE: Video TECO always succeeds on `0N...$`. + * TECOC however fails just like we do. + */ + g_set_error_literal(error, TECO_ERROR, TECO_ERROR_FAILED, + "The search counter must not be zero."); + return FALSE; + } + + if (teco_search_parameters.count > 0) { teco_search_parameters.from = teco_search_parameters.pos; teco_search_parameters.to = teco_interface_ssm(SCI_GETLENGTH, 0, 0); } else { |
