From 54bff64d7dbaefea877b0b2e32323761fc5692f2 Mon Sep 17 00:00:00 2001 From: Michal Klos Date: Tue, 21 Jan 2025 23:30:58 +0100 Subject: [PATCH] fix: sprintf, use snprintf (#447) --- src/raygui.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/raygui.h b/src/raygui.h index b901c8d..bc7032d 100644 --- a/src/raygui.h +++ b/src/raygui.h @@ -1046,7 +1046,7 @@ typedef enum { #if defined(RAYGUI_IMPLEMENTATION) #include // required for: isspace() [GuiTextBox()] -#include // Required for: FILE, fopen(), fclose(), fprintf(), feof(), fscanf(), vsprintf() [GuiLoadStyle(), GuiLoadIcons()] +#include // Required for: FILE, fopen(), fclose(), fprintf(), feof(), fscanf(), snprintf(), vsprintf() [GuiLoadStyle(), GuiLoadIcons()] #include // Required for: malloc(), calloc(), free() [GuiLoadStyle(), GuiLoadIcons()] #include // Required for: strlen() [GuiTextBox(), GuiValueBox()], memset(), memcpy() #include // Required for: va_list, va_start(), vfprintf(), va_end() [TextFormat()] @@ -2905,7 +2905,7 @@ int GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, in GuiState state = guiState; char textValue[RAYGUI_VALUEBOX_MAX_CHARS + 1] = "\0"; - sprintf(textValue, "%i", *value); + snprintf(textValue, sizeof(textValue), "%i", *value); Rectangle textBounds = { 0 }; if (text != NULL) @@ -3021,7 +3021,7 @@ int GuiValueBoxFloat(Rectangle bounds, const char *text, char *textValue, float GuiState state = guiState; //char textValue[RAYGUI_VALUEBOX_MAX_CHARS + 1] = "\0"; - //sprintf(textValue, "%2.2f", *value); + //snprintf(textValue, sizeof(textValue), "%2.2f", *value); Rectangle textBounds = {0}; if (text != NULL) @@ -4354,7 +4354,7 @@ const char *GuiIconText(int iconId, const char *text) if (text != NULL) { memset(buffer, 0, 1024); - sprintf(buffer, "#%03i#", iconId); + snprintf(buffer, sizeof(buffer), "#%03i#", iconId); for (int i = 5; i < 1024; i++) { @@ -4366,7 +4366,7 @@ const char *GuiIconText(int iconId, const char *text) } else { - sprintf(iconBuffer, "#%03i#", iconId); + snprintf(iconBuffer, sizeof(iconBuffer), "#%03i#", iconId); return iconBuffer; }