From 150089ac169d660de748b58486d2d4775154c9a7 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Tue, 27 Oct 2020 18:15:12 +0000 Subject: [PATCH] Fix bit rot in TERM_CC_DIAGS ifdef. This is a piece of conditioned-out code that I haven't used since I originally invented the compressed scrollback format, which decompressed every scrollback line immediately after compressing it to check that the round-trip conversion worked. Now I have occasion to actually use it, I find that (of course) changes around it have made it not quite work any more: the thing the diagnostic code is passing to decompressline hasn't had its length field filled in yet, because that gets done 20 lines later. Now you can compile with -DTERM_CC_DIAGS again, and it doesn't crash _unless_ it detects the actual bug it was intended to spot. --- terminal.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/terminal.c b/terminal.c index 4313a1b8..0329df85 100644 --- a/terminal.c +++ b/terminal.c @@ -723,6 +723,11 @@ static compressed_scrollback_line *compressline(termline *ldata) makerle(b, ldata, makeliteral_truecolour); makerle(b, ldata, makeliteral_cc); + size_t linelen = b->len - sizeof(compressed_scrollback_line); + compressed_scrollback_line *line = + (compressed_scrollback_line *)strbuf_to_str(b); + line->len = linelen; + /* * Diagnostics: ensure that the compressed data really does * decompress to the right thing. @@ -742,7 +747,7 @@ static compressed_scrollback_line *compressline(termline *ldata) printf("\n"); #endif - dcl = decompressline((compressed_scrollback_line *)b->u); + dcl = decompressline(line); assert(ldata->cols == dcl->cols); assert(ldata->lattr == dcl->lattr); for (i = 0; i < ldata->cols; i++) @@ -759,10 +764,6 @@ static compressed_scrollback_line *compressline(termline *ldata) #endif #endif /* TERM_CC_DIAGS */ - size_t linelen = b->len - sizeof(compressed_scrollback_line); - compressed_scrollback_line *line = - (compressed_scrollback_line *)strbuf_to_str(b); - line->len = linelen; return line; }