diff options
| author | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2026-08-13 00:49:42 +0200 |
|---|---|---|
| committer | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2026-08-13 01:04:41 +0200 |
| commit | 64c8e378b251669241a3565adf2c8f2d792e1b8d (patch) | |
| tree | f2129aa9009af9a2c6858b507a007ba2686f4e45 /src/interface-curses/curses-info-popup.c | |
| parent | b24c22dd15c0b02847d105b12e2fde72cb301d7d (diff) | |
curses: check for return values of newpad() and newwin()HEADmaster-fmsbw-cimaster
These can fail, so abort() just like glib does internally in case of OOM.
A special case is the pad allocation for autocompletion popups, which
can have excessively many lines. This is handled gracefully now
(the popup simply won't be displayed).
Diffstat (limited to 'src/interface-curses/curses-info-popup.c')
| -rw-r--r-- | src/interface-curses/curses-info-popup.c | 20 |
1 files changed, 14 insertions, 6 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); |
