From 8707ac0d5771cd6a84e0cee54dd00373ab4b00da Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 23 Mar 2020 23:18:02 +0900 Subject: [PATCH] [qwaq] Add a guard to formatLine I got really weird error (invalid panel passed to top_panel) when there was no such call, so I guess there was some memory corruption. formatLine is the only suspect, but when I put in the guard, the error wasn't reproduced (just scrolling through qwaq's makefile in a big window). --- ruamoko/qwaq/qwaq-editbuffer-bi.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ruamoko/qwaq/qwaq-editbuffer-bi.c b/ruamoko/qwaq/qwaq-editbuffer-bi.c index ef870e4a0..1beb6eabd 100644 --- a/ruamoko/qwaq/qwaq-editbuffer-bi.c +++ b/ruamoko/qwaq/qwaq-editbuffer-bi.c @@ -456,6 +456,8 @@ formatLine (txtbuffer_t *buffer, unsigned linePtr, unsigned xpos, int col; byte c = 0; int count; + int *startdst = dst; + int startlen = length; while (pos < xpos && ptr < buffer->textSize) { c = getChar (buffer, ptr); @@ -498,6 +500,10 @@ formatLine (txtbuffer_t *buffer, unsigned linePtr, unsigned xpos, while (length-- > 0) { *dst++ = col | ' '; } + if (dst - startdst > startlen) { + Sys_Error ("formatLine wrote too much: %zd %u %d", + dst - startdst, startlen, length); + } return ptr; }