From cbaf42c886899e591fa7e21cae959b244a4e5dad Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 31 May 2024 08:03:54 +1000 Subject: [PATCH] Avoid more stdlib functions with FreeType --- .github/actions/notify_failure/action.yml | 1 + src/Platform.h | 6 ++-- src/Platform_Posix.c | 6 ++-- src/Platform_Windows.c | 7 ++-- src/SystemFonts.c | 39 +++++++++++++++++++++++ src/_PlatformConsole.h | 6 ++-- src/freetype/ftstdlib.h | 14 +++++--- 7 files changed, 61 insertions(+), 18 deletions(-) diff --git a/.github/actions/notify_failure/action.yml b/.github/actions/notify_failure/action.yml index d67d0ec28..bb5fc2900 100644 --- a/.github/actions/notify_failure/action.yml +++ b/.github/actions/notify_failure/action.yml @@ -25,5 +25,6 @@ runs: steps: - name: Notify failure shell: sh + if: ${{ inputs.WEBHOOK_URL != '' }} run: | curl ${{ inputs.WEBHOOK_URL }} -H "Accept: application/json" -H "Content-Type:application/json" -X POST --data "{\"username\": \"${{ inputs.BOT_USERNAME }}\", \"avatar_url\": \"${{ inputs.BOT_AVATAR }}\", \"content\": \"${{ inputs.NOTIFY_MESSAGE }}\" }" \ No newline at end of file diff --git a/src/Platform.h b/src/Platform.h index 3501800c3..a2e681f1e 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -152,13 +152,13 @@ CC_API void* Mem_Realloc(void* mem, cc_uint32 numElems, cc_uint32 elemsSize, con CC_API void Mem_Free(void* mem); /* Sets the contents of a block of memory to the given value. */ -void* Mem_Set(void* dst, cc_uint8 value, cc_uint32 numBytes); +void* Mem_Set(void* dst, cc_uint8 value, unsigned numBytes); /* Copies a block of memory to another block of memory. */ /* NOTE: These blocks MUST NOT overlap. */ -void* Mem_Copy(void* dst, const void* src, cc_uint32 numBytes); +void* Mem_Copy(void* dst, const void* src, unsigned numBytes); /* Moves a block of memory to another block of memory. */ /* NOTE: These blocks can overlap. */ -void* Mem_Move(void* dst, const void* src, cc_uint32 numBytes); +void* Mem_Move(void* dst, const void* src, unsigned numBytes); /* Returns non-zero if the two given blocks of memory have equal contents. */ int Mem_Equal(const void* a, const void* b, cc_uint32 numBytes); diff --git a/src/Platform_Posix.c b/src/Platform_Posix.c index eaf6f1a7d..796324fe9 100644 --- a/src/Platform_Posix.c +++ b/src/Platform_Posix.c @@ -73,9 +73,9 @@ cc_bool Platform_SingleProcess; /*########################################################################################################################* *---------------------------------------------------------Memory----------------------------------------------------------* *#########################################################################################################################*/ -void* Mem_Set(void* dst, cc_uint8 value, cc_uint32 numBytes) { return memset( dst, value, numBytes); } -void* Mem_Copy(void* dst, const void* src, cc_uint32 numBytes) { return memcpy( dst, src, numBytes); } -void* Mem_Move(void* dst, const void* src, cc_uint32 numBytes) { return memmove(dst, src, numBytes); } +void* Mem_Set(void* dst, cc_uint8 value, unsigned numBytes) { return memset( dst, value, numBytes); } +void* Mem_Copy(void* dst, const void* src, unsigned numBytes) { return memcpy( dst, src, numBytes); } +void* Mem_Move(void* dst, const void* src, unsigned numBytes) { return memmove(dst, src, numBytes); } void* Mem_TryAlloc(cc_uint32 numElems, cc_uint32 elemsSize) { cc_uint32 size = CalcMemSize(numElems, elemsSize); diff --git a/src/Platform_Windows.c b/src/Platform_Windows.c index a4f324766..c0f6ce2cd 100644 --- a/src/Platform_Windows.c +++ b/src/Platform_Windows.c @@ -43,9 +43,9 @@ cc_bool Platform_SingleProcess; /*########################################################################################################################* *---------------------------------------------------------Memory----------------------------------------------------------* *#########################################################################################################################*/ -void* Mem_Set(void* dst, cc_uint8 value, cc_uint32 numBytes) { return memset( dst, value, numBytes); } -void* Mem_Copy(void* dst, const void* src, cc_uint32 numBytes) { return memcpy( dst, src, numBytes); } -void* Mem_Move(void* dst, const void* src, cc_uint32 numBytes) { return memmove(dst, src, numBytes); } +void* Mem_Set(void* dst, cc_uint8 value, unsigned numBytes) { return memset( dst, value, numBytes); } +void* Mem_Copy(void* dst, const void* src, unsigned numBytes) { return memcpy( dst, src, numBytes); } +void* Mem_Move(void* dst, const void* src, unsigned numBytes) { return memmove(dst, src, numBytes); } void* Mem_TryAlloc(cc_uint32 numElems, cc_uint32 elemsSize) { cc_uint32 size = CalcMemSize(numElems, elemsSize); @@ -749,7 +749,6 @@ const struct UpdaterInfo Updater_Info = { "", 1, { { "Direct3D11", "cc-arm32-d3d #else const struct UpdaterInfo Updater_Info = { "&eCompile latest source code to update", 0 }; #endif -}; cc_bool Updater_Clean(void) { return DeleteFile(UPDATE_TMP) || GetLastError() == ERROR_FILE_NOT_FOUND; diff --git a/src/SystemFonts.c b/src/SystemFonts.c index d9c54dfe5..4f2918828 100644 --- a/src/SystemFonts.c +++ b/src/SystemFonts.c @@ -288,6 +288,45 @@ size_t cc_strlen(const char* a) { return i; } +char* cc_strstr(const char* str, const char* substr) { + const char* a; + const char* b; + if (!substr[0]) return (char*)str; + + for (; *str; str++) + { + /* Definitely not a match */ + if (*str != substr[0]) continue; + + /* It's a possible match */ + if (cc_strcmp(str, substr) == 0) return (char*)str; + } + return NULL; +} + +int cc_memcmp(const void* ptrA, const void* ptrB, size_t num) { + const unsigned char* a = (const unsigned char*)ptrA; + const unsigned char* b = (const unsigned char*)ptrB; + + for (; num > 0; num--, a++, b++) + { + if (*a != *b) return *a - *b; + } + return 0; +} + +void* cc_memchr(const void* ptr, int ch, size_t num) { + const char* a = (const char*)ptr; + + for (; num > 0; num--, a++) + { + if (*a == ch) return a; + } + return NULL; +} + + + static FT_Library ft_lib; static struct FT_MemoryRec_ ft_mem; static struct StringsBuffer font_list; diff --git a/src/_PlatformConsole.h b/src/_PlatformConsole.h index 14550465e..53e90003d 100644 --- a/src/_PlatformConsole.h +++ b/src/_PlatformConsole.h @@ -4,9 +4,9 @@ cc_bool Platform_SingleProcess = true; /*########################################################################################################################* *---------------------------------------------------------Memory----------------------------------------------------------* *#########################################################################################################################*/ -void* Mem_Set(void* dst, cc_uint8 value, cc_uint32 numBytes) { return memset( dst, value, numBytes); } -void* Mem_Copy(void* dst, const void* src, cc_uint32 numBytes) { return memcpy( dst, src, numBytes); } -void* Mem_Move(void* dst, const void* src, cc_uint32 numBytes) { return memmove(dst, src, numBytes); } +void* Mem_Set(void* dst, cc_uint8 value, unsigned numBytes) { return memset( dst, value, numBytes); } +void* Mem_Copy(void* dst, const void* src, unsigned numBytes) { return memcpy( dst, src, numBytes); } +void* Mem_Move(void* dst, const void* src, unsigned numBytes) { return memmove(dst, src, numBytes); } void* Mem_TryAlloc(cc_uint32 numElems, cc_uint32 elemsSize) { cc_uint32 size = CalcMemSize(numElems, elemsSize); diff --git a/src/freetype/ftstdlib.h b/src/freetype/ftstdlib.h index a0ac62639..fc0480e21 100644 --- a/src/freetype/ftstdlib.h +++ b/src/freetype/ftstdlib.h @@ -77,19 +77,23 @@ #include /* ClassiCube functions to avoid stdlib */ -extern int cc_strncmp(const char* a, const char* b, size_t maxCount); -extern int cc_strcmp( const char* a, const char* b); +extern int cc_strncmp(const char* a, const char* b, size_t maxCount); +extern int cc_strcmp(const char* a, const char* b); extern size_t cc_strlen(const char* a); +extern char* cc_strstr(const char* str, const char* substr); -#define ft_memchr memchr -#define ft_memcmp memcmp +extern int cc_memcmp(const void* ptrA, const void* ptrB, size_t num); +extern void* cc_memchr(const void* ptr, int ch, size_t num); + +#define ft_memchr cc_memchr +#define ft_memcmp cc_memcmp #define ft_memcpy memcpy #define ft_memmove memmove #define ft_memset memset #define ft_strcmp cc_strcmp #define ft_strlen cc_strlen #define ft_strncmp cc_strncmp -#define ft_strstr strstr +#define ft_strstr cc_strstr /**********************************************************************/