AmendHub

Download (as of this amendment):

jcs

/

textview

/

amendments

/

52

TVUpdate: EraseRect before redrawing, avoid a div-by-zero

The caller may have erased its window and filled the window with a
background pattern, so we have to erase our working area first.

jcs made amendment 52 over 2 years ago
--- textview.c Wed Nov 13 16:26:18 2024 +++ textview.c Wed Nov 13 20:31:30 2024 @@ -767,8 +767,8 @@ TVUpdate(TVHandle tvh) tv = TVLock(tvh); TVUseCanvas(tv); -#ifdef USE_CANVAS EraseRect(&tv->frame); +#ifdef USE_CANVAS tv->canvas_dirty = true; #endif @@ -1269,7 +1269,7 @@ TVAppendLocked(struct TVRec *tv, struct TVStyle *style new_chunk = false; fromline = TVGetLine(tv, tv->nlines); - + /* setup style */ prev_style = tv->cur_style; cur_style = TVFindStyle(tv, style); @@ -1386,6 +1386,9 @@ TVScrollDivisor(struct TVRec *tv) div *= 10; max /= 10; } + + if (div == 0) + Debugger(); return div; } @@ -1669,7 +1672,7 @@ TVFindInRect(struct TVRec *tv, BigRect *rect, long sta TVFindInRectCallback callback, void *cookie) { struct TVFindInRectMatch match; - unsigned long nline; + unsigned long nline, ppl; Boolean ret; TVUseCanvas(tv); @@ -1680,7 +1683,10 @@ TVFindInRect(struct TVRec *tv, BigRect *rect, long sta if (startline == 0 && tv->nlines > 1) { /* take a stab at getting us closer */ - startline = rect->top / (tv->bounds.bottom / tv->nlines); + ppl = (tv->bounds.bottom / tv->nlines); + if (ppl == 0) + ppl = 1; + startline = rect->top / ppl; if (startline > 1) { match.line = TVGetLine(tv, startline); while (startline > 0 && match.line->rect.top > rect->top) {