aboutsummaryrefslogtreecommitdiff
path: root/text-iterator.c
AgeCommit message (Collapse)AuthorFilesLines
2025-12-22move all standard library includes into util.hRandy Palamar1-5/+0
2025-12-16text-iterator: fix one byte over-read in codepoint iteratorRandy Palamar1-8/+8
Reported by @kyx0r here: https://github.com/kyx0r/nextvi/issues/189#issuecomment-3650406932 The crash is relatively hard to reproduce as it relies on there being no padding after the end of the memory allocation. This can only happen if the text size is an exact multiple of the system page size. In the linked backtrace it->start = 0x7ffff0e00000 and it->end = 0x7ffff7200000 (page size was likely 4K or 0x1000) so it->end, which is one past the last byte of the text, was pointing to an entirely different page. Dereferencing it can cause a segfault. If it doesn't segfault it is still incorrect to read beyond the end of the text even if it happens to work due to padding. The underlying text_iterator_byte_{next,prev}() functions were already handling this correctly. The fix is to not throw away their work.
2025-12-08util: replace memrchr with internal versionRandy Palamar1-4/+11
The amount of code we need to detect if this is present and handle the fallback is more than if we just provide it ourselves. Also we are passing in a difference of pointers so the argument type should be ptrdiff_t. This avoids a C brain damage of having unsigned size type which can wrap around if the caller is careful.
2020-10-30text: fix invalid pointer comparisonMarc André Tanner1-1/+1
2020-10-10text: move generic iterator functionality to separate fileMarc André Tanner1-0/+177