1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Avoid passing NULL pointers to curses functions.

This allows profanity to work without segfaulting from NULL
pointer dereferences when used with NetBSD libcurses.

Basic functionality was tested, there may be more NULL pointer
issues hiding.
This commit is contained in:
nia 2020-09-04 12:59:20 +02:00
parent 52e9be4abc
commit ce67753423
3 changed files with 23 additions and 9 deletions

View File

@ -308,7 +308,9 @@ _inp_win_update_virtual(void)
{ {
int wcols = getmaxx(stdscr); int wcols = getmaxx(stdscr);
int row = screen_inputwin_row(); int row = screen_inputwin_row();
pnoutrefresh(inp_win, 0, pad_start, row, 0, row, wcols - 2); if (inp_win != NULL) {
pnoutrefresh(inp_win, 0, pad_start, row, 0, row, wcols - 2);
}
} }
static void static void

View File

@ -95,7 +95,10 @@ rosterwin_roster(void)
ProfLayoutSplit* layout = (ProfLayoutSplit*)console->layout; ProfLayoutSplit* layout = (ProfLayoutSplit*)console->layout;
assert(layout->memcheck == LAYOUT_SPLIT_MEMCHECK); assert(layout->memcheck == LAYOUT_SPLIT_MEMCHECK);
werase(layout->subwin);
if (layout->subwin != NULL) {
werase(layout->subwin);
}
char* roomspos = prefs_get_string(PREF_ROSTER_ROOMS_POS); char* roomspos = prefs_get_string(PREF_ROSTER_ROOMS_POS);
if (prefs_get_boolean(PREF_ROSTER_ROOMS) && (g_strcmp0(roomspos, "first") == 0)) { if (prefs_get_boolean(PREF_ROSTER_ROOMS) && (g_strcmp0(roomspos, "first") == 0)) {
@ -1106,9 +1109,11 @@ _rosterwin_contacts_header(ProfLayoutSplit* layout, const char* const title, GSL
gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP); gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP);
wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); if (layout->subwin != NULL) {
win_sub_print(layout->subwin, header->str, FALSE, wrap, 1); wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); win_sub_print(layout->subwin, header->str, FALSE, wrap, 1);
wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
}
g_string_free(header, TRUE); g_string_free(header, TRUE);
} }
@ -1166,9 +1171,11 @@ _rosterwin_rooms_header(ProfLayoutSplit* layout, GList* rooms, char* title)
gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP); gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP);
wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); if (layout->subwin != NULL) {
win_sub_print(layout->subwin, header->str, FALSE, wrap, 1); wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); win_sub_print(layout->subwin, header->str, FALSE, wrap, 1);
wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
}
g_string_free(header, TRUE); g_string_free(header, TRUE);
} }

View File

@ -1863,7 +1863,12 @@ win_sub_print(WINDOW* win, char* msg, gboolean newline, gboolean wrap, int inden
void void
win_sub_newline_lazy(WINDOW* win) win_sub_newline_lazy(WINDOW* win)
{ {
int curx = getcurx(win); int curx;
if (win == NULL) {
return;
}
curx = getcurx(win);
if (curx > 0) { if (curx > 0) {
int cury = getcury(win); int cury = getcury(win);
wmove(win, cury + 1, 0); wmove(win, cury + 1, 0);