AmendHub

Download (as of this amendment):

jcs

/

textview

/

amendments

/

43

TVGetText: Fix slab iteration


jcs made amendment 43 over 2 years ago
--- textview.c Tue Oct 29 13:39:30 2024 +++ textview.c Sun Nov 3 22:08:08 2024 @@ -499,23 +499,31 @@ TVGetText(TVHandle tvh, char *dst, unsigned long start tv = TVLock(tvh); + read = 0; while (read < end - start) { slab = TVGetTextSlab(tv, start + read); - slabend = slab->base + slab->size; + if (slab == NULL) { + read = 0; + break; + } slabstart = slab->base; + slabend = slab->base + slab->size; if (start > slabstart) slabstart = start; - if (end - read < slabend) - slabend = end - read; + if (end < slabend) + slabend = end; size = slabend - slabstart; + if (size == 0) + Debugger(); memcpy(dst, slab->data + (slabstart - slab->base), size); dst += size; read += size; } + TVUnlock(tv); return read; }