Compare commits

...

5 Commits

Author SHA1 Message Date
Shivam7-1
a08a91c985
Merge 63a74a92a8 into 766325c395 2025-02-21 13:20:08 +02:00
mizmar
766325c395
[Core] Fix inverted condition for setting booleanWarnings.maxTextMeasureCacheExceeded (#275)
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-02-20 09:22:35 +13:00
Alex Pedley
5afdf3f8c9
[Core] Make fakeContext use correct value from currentContext (#269) 2025-02-20 09:21:14 +13:00
Shivam7-1
63a74a92a8
Rename fuzzing_target.cc to fuzzing_target.c 2024-12-22 21:10:58 +05:30
Shivam7-1
8d3cadc52e
initial fuzzing support 2024-12-21 17:04:07 +05:30
2 changed files with 26 additions and 2 deletions

4
clay.h
View File

@ -1443,7 +1443,7 @@ Clay__MeasureTextCacheItem *Clay__MeasureTextCached(Clay_String *text, Clay_Text
measured = Clay__MeasureTextCacheItemArray_Get(&context->measureTextHashMapInternal, newItemIndex); measured = Clay__MeasureTextCacheItemArray_Get(&context->measureTextHashMapInternal, newItemIndex);
} else { } else {
if (context->measureTextHashMapInternal.length == context->measureTextHashMapInternal.capacity - 1) { if (context->measureTextHashMapInternal.length == context->measureTextHashMapInternal.capacity - 1) {
if (context->booleanWarnings.maxTextMeasureCacheExceeded) { if (!context->booleanWarnings.maxTextMeasureCacheExceeded) {
context->errorHandler.errorHandlerFunction(CLAY__INIT(Clay_ErrorData) { context->errorHandler.errorHandlerFunction(CLAY__INIT(Clay_ErrorData) {
.errorType = CLAY_ERROR_TYPE_ELEMENTS_CAPACITY_EXCEEDED, .errorType = CLAY_ERROR_TYPE_ELEMENTS_CAPACITY_EXCEEDED,
.errorText = CLAY_STRING("Clay ran out of capacity while attempting to measure text elements. Try using Clay_SetMaxElementCount() with a higher value."), .errorText = CLAY_STRING("Clay ran out of capacity while attempting to measure text elements. Try using Clay_SetMaxElementCount() with a higher value."),
@ -3589,7 +3589,7 @@ uint32_t Clay_MinMemorySize(void) {
Clay_Context* currentContext = Clay_GetCurrentContext(); Clay_Context* currentContext = Clay_GetCurrentContext();
if (currentContext) { if (currentContext) {
fakeContext.maxElementCount = currentContext->maxElementCount; fakeContext.maxElementCount = currentContext->maxElementCount;
fakeContext.maxMeasureTextCacheWordCount = currentContext->maxElementCount; fakeContext.maxMeasureTextCacheWordCount = currentContext->maxMeasureTextCacheWordCount;
} }
// Reserve space in the arena for the context, important for calculating min memory size correctly // Reserve space in the arena for the context, important for calculating min memory size correctly
Clay__Context_Allocate_Arena(&fakeContext.internalArena); Clay__Context_Allocate_Arena(&fakeContext.internalArena);

24
fuzz/fuzzing_target.c Normal file
View File

@ -0,0 +1,24 @@
#include "clay.h"
#include <stdint.h>
#include <stddef.h>
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
if (size < sizeof(Clay_String)) return 0;
Clay_String testString = { .length = size, .chars = (const char *)data };
Clay_Dimensions dimensions = MeasureText(&testString, NULL);
// Call other critical functions
Clay_Arena arena = Clay_CreateArenaWithCapacityAndMemory(1024, (void*)data);
Clay_Initialize(arena, (Clay_Dimensions){1024, 768});
Clay_SetPointerState((Clay_Vector2){0, 0}, false);
Clay_BeginLayout();
Clay_EndLayout();
// Handle pointer state changes
Clay_SetPointerState((Clay_Vector2){1, 1}, true);
Clay_SetPointerState((Clay_Vector2){2, 2}, false);
return 0;
}