Skip to content

Commit

Permalink
update_view_title: Fix NULL dereference at startup (#1293)
Browse files Browse the repository at this point in the history
update_view_title can be called with a `struct view`
where `line` is NULL, and `lines` is 0.

Add a check for the value of line where it's first used.
  • Loading branch information
abhinav authored Oct 21, 2023
1 parent 1894954 commit 2634298
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,6 @@ void
update_view_title(struct view *view)
{
WINDOW *window = view->title;
struct line *line = &view->line[view->pos.lineno];
unsigned int view_lines, lines;
int update_increment = view_has_flags(view, VIEW_LOG_LIKE | VIEW_GREP_LIKE)
? 100
Expand All @@ -707,16 +706,18 @@ update_view_title(struct view *view)
wprintw(window, " %s", view->ref);
}

if (!view_has_flags(view, VIEW_CUSTOM_STATUS) && view_has_line(view, line) &&
line->lineno) {
wprintw(window, " - %s %u of %zu",
view->ops->type,
line->lineno,
MAX(line->lineno,
view->pipe
? update_increment *
(size_t) ((view->lines - view->custom_lines) / update_increment)
: view->lines - view->custom_lines));
if (!view_has_flags(view, VIEW_CUSTOM_STATUS) && view->line != NULL) {
struct line *line = &view->line[view->pos.lineno];
if (view_has_line(view, line) && line->lineno) {
wprintw(window, " - %s %u of %zu",
view->ops->type,
line->lineno,
MAX(line->lineno,
view->pipe
? update_increment *
(size_t) ((view->lines - view->custom_lines) / update_increment)
: view->lines - view->custom_lines));
}
}

if (view->pipe) {
Expand Down

0 comments on commit 2634298

Please sign in to comment.