From 9f05a2bb1621877976acf7870f9a192178f54458 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 7 Oct 2014 12:15:59 +0100 Subject: [PATCH] Fixed unlikely buffer overrun in InputCharacters (thanks Daniel Collin) --- imgui.cpp | 2 +- imgui.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 2e1a611a..d6722bc8 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -348,7 +348,7 @@ static size_t ImStrlenW(const ImWchar* str); void ImGuiIO::AddInputCharacter(ImWchar c) { const size_t n = ImStrlenW(InputCharacters); - if (n < sizeof(InputCharacters) / sizeof(InputCharacters[0])) + if (n + 1 < sizeof(InputCharacters) / sizeof(InputCharacters[0])) { InputCharacters[n] = c; InputCharacters[n+1] = 0; diff --git a/imgui.h b/imgui.h index 68eecfd1..03dc4ba3 100644 --- a/imgui.h +++ b/imgui.h @@ -456,7 +456,7 @@ struct ImGuiIO bool KeyCtrl; // Keyboard modifier pressed: Control bool KeyShift; // Keyboard modifier pressed: Shift bool KeysDown[512]; // Keyboard keys that are pressed (in whatever order user naturally has access to keyboard data) - ImWchar InputCharacters[16]; // List of characters input (translated by user from keypress+keyboard state). Fill using AddInputCharacter() helper. + ImWchar InputCharacters[16+1]; // List of characters input (translated by user from keypress+keyboard state). Fill using AddInputCharacter() helper. // Function void AddInputCharacter(ImWchar); // Helper to add a new character into InputCharacters[]