Compare commits

...

3 Commits

Author SHA1 Message Date
Yaroslav Erohin
da381445c5
Merge d7e072fe25 into 06167b4f4b 2025-04-12 19:45:17 +04:00
Nic Barker
06167b4f4b [Core] Fix a potential null pointer deref in scroll GetScrollContainerData
Some checks failed
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, ubuntu-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Has been cancelled
2025-04-12 11:27:10 +12:00
Iaroslav Erokhin
d7e072fe25 fix heap buffer overflow and support unicode characters 2025-03-06 14:20:46 +01:00
2 changed files with 17 additions and 7 deletions

6
clay.h
View File

@ -4118,11 +4118,15 @@ Clay_ScrollContainerData Clay_GetScrollContainerData(Clay_ElementId id) {
for (int32_t i = 0; i < context->scrollContainerDatas.length; ++i) { for (int32_t i = 0; i < context->scrollContainerDatas.length; ++i) {
Clay__ScrollContainerDataInternal *scrollContainerData = Clay__ScrollContainerDataInternalArray_Get(&context->scrollContainerDatas, i); Clay__ScrollContainerDataInternal *scrollContainerData = Clay__ScrollContainerDataInternalArray_Get(&context->scrollContainerDatas, i);
if (scrollContainerData->elementId == id.id) { if (scrollContainerData->elementId == id.id) {
Clay_ScrollElementConfig *scrollElementConfig = Clay__FindElementConfigWithType(scrollContainerData->layoutElement, CLAY__ELEMENT_CONFIG_TYPE_SCROLL).scrollElementConfig;
if (!scrollElementConfig) { // This can happen on the first frame before a scroll container is declared
return CLAY__INIT(Clay_ScrollContainerData) CLAY__DEFAULT_STRUCT;
}
return CLAY__INIT(Clay_ScrollContainerData) { return CLAY__INIT(Clay_ScrollContainerData) {
.scrollPosition = &scrollContainerData->scrollPosition, .scrollPosition = &scrollContainerData->scrollPosition,
.scrollContainerDimensions = { scrollContainerData->boundingBox.width, scrollContainerData->boundingBox.height }, .scrollContainerDimensions = { scrollContainerData->boundingBox.width, scrollContainerData->boundingBox.height },
.contentDimensions = scrollContainerData->contentSize, .contentDimensions = scrollContainerData->contentSize,
.config = *Clay__FindElementConfigWithType(scrollContainerData->layoutElement, CLAY__ELEMENT_CONFIG_TYPE_SCROLL).scrollElementConfig, .config = *scrollElementConfig,
.found = true .found = true
}; };
} }

View File

@ -99,16 +99,22 @@ static inline Clay_Dimensions Raylib_MeasureText(Clay_StringSlice text, Clay_Tex
float scaleFactor = config->fontSize/(float)fontToUse.baseSize; float scaleFactor = config->fontSize/(float)fontToUse.baseSize;
for (int i = 0; i < text.length; ++i) int byte_index = 0;
{ while (byte_index < text.length) {
if (text.chars[i] == '\n') { if (text.chars[byte_index] == '\n') {
maxTextWidth = fmax(maxTextWidth, lineTextWidth); maxTextWidth = fmax(maxTextWidth, lineTextWidth);
lineTextWidth = 0; lineTextWidth = 0;
byte_index++;
continue; continue;
} }
int index = text.chars[i] - 32;
if (fontToUse.glyphs[index].advanceX != 0) lineTextWidth += fontToUse.glyphs[index].advanceX; int codepoint_bytes = 0;
else lineTextWidth += (fontToUse.recs[index].width + fontToUse.glyphs[index].offsetX); int codepoint = GetCodepoint(&text.chars[byte_index], &codepoint_bytes);
int glyph_index = GetGlyphIndex(fontToUse, codepoint);
byte_index += codepoint_bytes;
if (fontToUse.glyphs[glyph_index].advanceX != 0) lineTextWidth += fontToUse.glyphs[glyph_index].advanceX;
else lineTextWidth += (fontToUse.recs[glyph_index].width + fontToUse.glyphs[glyph_index].offsetX);
} }
maxTextWidth = fmax(maxTextWidth, lineTextWidth); maxTextWidth = fmax(maxTextWidth, lineTextWidth);