From 6b03a215b76a2558accc3b9396b7fadde3a7b751 Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Tue, 10 Jun 2025 11:38:56 +1000 Subject: [PATCH] [Core] Fix an out of bounds access for single newline characters --- clay.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clay.h b/clay.h index 8ee7f50..32a8e87 100644 --- a/clay.h +++ b/clay.h @@ -2512,7 +2512,7 @@ void Clay__CalculateFinalLayout(void) { // measuredWord->length == 0 means a newline character else if (measuredWord->length == 0 || lineWidth + measuredWord->width > containerElement->dimensions.width) { // 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] } }); textElementData->wrappedLines.length++; if (lineLengthChars == 0 || measuredWord->length == 0) {