summaryrefslogtreecommitdiffhomepage
path: root/src/rtext.c
diff options
context:
space:
mode:
authorMurlocohol <[email protected]>2023-10-11 06:15:40 -0400
committerGitHub <[email protected]>2023-10-11 12:15:40 +0200
commit28fb58f0ea11f0b30b8aaf79d7bb148491ed8775 (patch)
tree197fb4565db31b1707c0b9b4b01f840b3e029933 /src/rtext.c
parentda9c2894feee6d64780d9cfe161255c4db91decc (diff)
downloadraylib-28fb58f0ea11f0b30b8aaf79d7bb148491ed8775.tar.gz
raylib-28fb58f0ea11f0b30b8aaf79d7bb148491ed8775.zip
[rtext] TextFormat() warn user if buffer overflow occured. (#3399)
* [rtext] TextFormat now alerts user to truncation. * Update rtext.c * Update rcore.c * Update rtext.c
Diffstat (limited to 'src/rtext.c')
-rw-r--r--src/rtext.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/rtext.c b/src/rtext.c
index fb844013..16b65507 100644
--- a/src/rtext.c
+++ b/src/rtext.c
@@ -1371,15 +1371,24 @@ const char *TextFormat(const char *text, ...)
va_list args;
va_start(args, text);
- vsnprintf(currentBuffer, MAX_TEXT_BUFFER_LENGTH, text, args);
+ int charCountRequired = vsnprintf(currentBuffer, MAX_TEXT_BUFFER_LENGTH, text, args);
va_end(args);
+ // If charCountRequired is larger than the MAX_TEXT_BUFFER_LENGTH, then overflow occured
+ if(charCountRequired > MAX_TEXT_BUFFER_LENGTH)
+ {
+ // We are going to insert [TRUN] at the end of the string so the user knows what happened
+ char *truncBuffer = buffers[index] + MAX_TEXT_BUFFER_LENGTH - 7; // 7 = six letters + '\0'
+ sprintf(truncBuffer, "[TRUN]");
+ }
+
index += 1; // Move to next buffer for next function call
if (index >= MAX_TEXTFORMAT_BUFFERS) index = 0;
return currentBuffer;
}
+
// Get integer value from text
// NOTE: This function replaces atoi() [stdlib.h]
int TextToInteger(const char *text)