From 971b04f9de9dde0e6478300cb5d8d762ea053b1e Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Tue, 3 Apr 2018 18:50:12 +0100 Subject: [PATCH] Extend the scope of the line==NULL dialog box. My theory that this report was completely obsolete seems to have been scuppered, in the most infuriating way possible: a user sent a report from 0.70 of a null-pointer crash happening moments _before_ that check, because the compressed line pointer passed to decompressline() was NULL. So there's still some need for this thing after all, and moreover, it should be happening just before that decompressline() call as well as after it! --- terminal.c | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/terminal.c b/terminal.c index f4902fef..d2ca8a48 100644 --- a/terminal.c +++ b/terminal.c @@ -1045,6 +1045,27 @@ static int sblines(Terminal *term) return sblines; } +static void null_line_error(Terminal *term, int y, int lineno, + tree234 *whichtree, int treeindex, + const char *varname) +{ + extern const char commitid[]; /* in version.c */ + modalfatalbox("%s==NULL in terminal.c\n" + "lineno=%d y=%d w=%d h=%d\n" + "count(scrollback=%p)=%d\n" + "count(screen=%p)=%d\n" + "count(alt=%p)=%d alt_sblines=%d\n" + "whichtree=%p treeindex=%d\n" + "commitid=%s\n\n" + "Please contact " + "and pass on the above information.", + varname, lineno, y, term->cols, term->rows, + term->scrollback, count234(term->scrollback), + term->screen, count234(term->screen), + term->alt_screen, count234(term->alt_screen), + term->alt_sblines, whichtree, treeindex, commitid); +} + /* * Retrieve a line of the screen or of the scrollback, according to * whether the y coordinate is non-negative or negative @@ -1079,29 +1100,16 @@ static termline *lineptr(Terminal *term, int y, int lineno, int screen) } if (whichtree == term->scrollback) { unsigned char *cline = index234(whichtree, treeindex); + if (!cline) + null_line_error(term, y, lineno, whichtree, treeindex, "cline"); line = decompressline(cline, NULL); } else { line = index234(whichtree, treeindex); } /* We assume that we don't screw up and retrieve something out of range. */ - if (line == NULL) { - extern const char commitid[]; /* in version.c */ - modalfatalbox("line==NULL in terminal.c\n" - "lineno=%d y=%d w=%d h=%d\n" - "count(scrollback=%p)=%d\n" - "count(screen=%p)=%d\n" - "count(alt=%p)=%d alt_sblines=%d\n" - "whichtree=%p treeindex=%d\n" - "commitid=%s\n\n" - "Please contact " - "and pass on the above information.", - lineno, y, term->cols, term->rows, - term->scrollback, count234(term->scrollback), - term->screen, count234(term->screen), - term->alt_screen, count234(term->alt_screen), - term->alt_sblines, whichtree, treeindex, commitid); - } + if (line == NULL) + null_line_error(term, y, lineno, whichtree, treeindex, "line"); assert(line != NULL); /*