From be979ad11e619c01f7ba30bded0138b11237f07d Mon Sep 17 00:00:00 2001 From: sunshihao520 Date: Mon, 9 Nov 2020 10:41:45 +0800 Subject: [PATCH] app/spdk_top: check NULL pointer after use newwin or new_panel When use newwin or new_panel function, the return value maybe NULL. Check the return value before use it will be more safe. Signed-off-by: sunshihao Signed-off-by: linfeilong Signed-off-by: liuzhqiang Signed-off-by: suweifeng Change-Id: Ifef8ed91b778cc4577cec1834f6596c58643e5c4 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5050 Reviewed-by: Changpeng Liu Reviewed-by: Shuhei Matsumoto Reviewed-by: Aleksey Marchuk Reviewed-by: Jim Harris Tested-by: SPDK CI Jenkins --- app/spdk_top/spdk_top.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/spdk_top/spdk_top.c b/app/spdk_top/spdk_top.c index 8531cd32a..c45375361 100644 --- a/app/spdk_top/spdk_top.c +++ b/app/spdk_top/spdk_top.c @@ -1485,8 +1485,10 @@ filter_columns(uint8_t tab) filter_win = newwin(elements + WINDOW_HEADER_LEN, len + WINDOW_BORDER_LEN, (g_max_row - elements - 1) / 2, (g_max_col - len) / 2); + assert(filter_win != NULL); keypad(filter_win, TRUE); filter_panel = new_panel(filter_win); + assert(filter_panel != NULL); top_panel(filter_panel); update_panels(); @@ -1611,8 +1613,10 @@ change_sorting(uint8_t tab) sort_win = newwin(elements + WINDOW_HEADER_LEN, len + WINDOW_BORDER_LEN, (g_max_row - elements) / 2, (g_max_col - len) / 2); + assert(sort_win != NULL); keypad(sort_win, TRUE); sort_panel = new_panel(sort_win); + assert(sort_panel != NULL); top_panel(sort_panel); update_panels(); @@ -1683,8 +1687,10 @@ change_refresh_rate(void) refresh_win = newwin(RR_WIN_HEIGHT, RR_WIN_WIDTH, (g_max_row - RR_WIN_HEIGHT - 1) / 2, (g_max_col - RR_WIN_WIDTH) / 2); + assert(refresh_win != NULL); keypad(refresh_win, TRUE); refresh_panel = new_panel(refresh_win); + assert(refresh_panel != NULL); top_panel(refresh_panel); update_panels(); @@ -1887,17 +1893,20 @@ draw_interface(void) g_menu_win = newwin(MENU_WIN_HEIGHT, g_max_col, g_max_row - MENU_WIN_HEIGHT - 1, MENU_WIN_LOCATION_COL); + assert(g_menu_win != NULL); draw_menu_win(); for (i = 0; i < NUMBER_OF_TABS; i++) { g_tab_win[i] = newwin(TAB_WIN_HEIGHT, g_max_col / NUMBER_OF_TABS - TABS_SPACING, TAB_WIN_LOCATION_ROW, g_max_col / NUMBER_OF_TABS * i + 1); + assert(g_tab_win[i] != NULL); draw_tab_win(i); g_tabs[i] = newwin(g_max_row - MENU_WIN_HEIGHT - TAB_WIN_HEIGHT - 2, g_max_col, TABS_LOCATION_ROW, TABS_LOCATION_COL); draw_tabs(i, g_current_sort_col[i]); g_panels[i] = new_panel(g_tabs[i]); + assert(g_panels[i] != NULL); } update_panels();