summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFrancisco Javier AndrĂ©s Casas Barrientos <[email protected]>2021-06-10 14:24:08 -0400
committerGitHub <[email protected]>2021-06-10 20:24:08 +0200
commit4dd56434022d3e850b592fb14a86af1a1199ebaa (patch)
tree48cdbf961b3d5eb7d81554bd2508d36a5182a84b
parent0b8e0f05a75e845b25acaa1d9f63edd5eb6c4902 (diff)
downloadraylib-4dd56434022d3e850b592fb14a86af1a1199ebaa.tar.gz
raylib-4dd56434022d3e850b592fb14a86af1a1199ebaa.zip
Added missing null terminator (#1820)
Added missing null terminator when adding characters to the string, otherwise garbage values are read (often zeros which are equal to '\0', but not every time). This error results in random characters appearing in the text box every one in a while: ``` asdfg??? ll?? ``` It is corrected with the proposed fix. This problem was observed by my student, Gonzalo Rivera Lazo.
-rw-r--r--examples/text/text_input_box.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/examples/text/text_input_box.c b/examples/text/text_input_box.c
index 408a234b..aeea4e15 100644
--- a/examples/text/text_input_box.c
+++ b/examples/text/text_input_box.c
@@ -22,7 +22,7 @@ int main(void)
InitWindow(screenWidth, screenHeight, "raylib [text] example - input box");
- char name[MAX_INPUT_CHARS + 1] = "\0"; // NOTE: One extra space required for line ending char '\0'
+ char name[MAX_INPUT_CHARS + 1] = "\0"; // NOTE: One extra space required for null terminator char '\0'
int letterCount = 0;
Rectangle textBox = { screenWidth/2 - 100, 180, 225, 50 };
@@ -56,6 +56,7 @@ int main(void)
if ((key >= 32) && (key <= 125) && (letterCount < MAX_INPUT_CHARS))
{
name[letterCount] = (char)key;
+ name[letterCount+1] = '\0'; // Add null terminator at the end of the string.
letterCount++;
}