[Core] Fix an out of bounds access for single newline characters

This commit is contained in:
Nic Barker 2025-06-10 11:38:56 +10:00
parent b25a31c1a1
commit 6b03a215b7

2
clay.h
View file

@ -2512,7 +2512,7 @@ void Clay__CalculateFinalLayout(void) {
// measuredWord->length == 0 means a newline character // measuredWord->length == 0 means a newline character
else if (measuredWord->length == 0 || lineWidth + measuredWord->width > containerElement->dimensions.width) { else if (measuredWord->length == 0 || lineWidth + measuredWord->width > containerElement->dimensions.width) {
// Wrapped text lines list has overflowed, just render out the line // Wrapped text lines list has overflowed, just render out the line
bool finalCharIsSpace = textElementData->text.chars[lineStartOffset + lineLengthChars - 1] == ' '; bool finalCharIsSpace = textElementData->text.chars[CLAY__MAX(lineStartOffset + lineLengthChars - 1, 0)] == ' ';
Clay__WrappedTextLineArray_Add(&context->wrappedTextLines, CLAY__INIT(Clay__WrappedTextLine) { { lineWidth + (finalCharIsSpace ? -spaceWidth : 0), lineHeight }, { .length = lineLengthChars + (finalCharIsSpace ? -1 : 0), .chars = &textElementData->text.chars[lineStartOffset] } }); Clay__WrappedTextLineArray_Add(&context->wrappedTextLines, CLAY__INIT(Clay__WrappedTextLine) { { lineWidth + (finalCharIsSpace ? -spaceWidth : 0), lineHeight }, { .length = lineLengthChars + (finalCharIsSpace ? -1 : 0), .chars = &textElementData->text.chars[lineStartOffset] } });
textElementData->wrappedLines.length++; textElementData->wrappedLines.length++;
if (lineLengthChars == 0 || measuredWord->length == 0) { if (lineLengthChars == 0 || measuredWord->length == 0) {