From ad0153a328f198e75aa239f8e22825f89f48abdb Mon Sep 17 00:00:00 2001 From: PatR Date: Mon, 3 Jun 2024 14:20:21 -0700 Subject: [PATCH] tty_curs() debugpline() More analyzer induced hackery. If tty_curs() discovers that the x,y passed to it are no good, don't use them, even if that results in the next output being in the wrong place. The old issue of behaving differently when built with DEBUG defined versus when it is not defined is fixed in a different way. --- win/tty/wintty.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/win/tty/wintty.c b/win/tty/wintty.c index 04b973fcd..8a7a76c42 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -2035,7 +2035,7 @@ void tty_curs( winid window, int x, int y) /* not xchar: perhaps xchar is unsigned - * then curx-x would be unsigned too */ + * then curx-x would be unsigned too */ { struct WinDesc *cw = 0; int cx = ttyDisplay->curx; @@ -2051,10 +2051,9 @@ tty_curs( #if defined(TILES_IN_GLYPHMAP) && defined(MSDOS) adjust_cursor_flags(cw); #endif - cw->curx = --x; /* column 0 is never used */ - cw->cury = y; + + if (x < 1 || y < 0 || y >= cw->rows || x > cw->cols) { #ifdef DEBUG - if (x < 0 || y < 0 || y >= cw->rows || x > cw->cols) { const char *s = "[unknown type]"; switch (cw->type) { @@ -2078,16 +2077,14 @@ tty_curs( break; } debugpline4("bad curs positioning win %d %s (%d,%d)", window, s, x, y); - /* This return statement caused a functional difference between - DEBUG and non-DEBUG operation, so it is being commented - out. It caused tty_curs() to fail to move the cursor to the - location it needed to be if the x,y range checks failed, - leaving the next piece of output to be displayed at whatever - random location the cursor happened to be at prior. */ - - /* return; */ - } #endif + /* for a while this 'return' was commented out, but that resulted in + using x,y as if they're good after discovering that they're bad */ + return; + } + cw->curx = --x; /* column 0 is not used */ + cw->cury = y; + x += cw->offx; y += cw->offy;