Skip to content

Commit

Permalink
Fixed unlikely buffer overrun in InputCharacters (thanks Daniel Collin)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocornut committed Oct 7, 2014
1 parent 48a9448 commit 9f05a2b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down

0 comments on commit 9f05a2b

Please sign in to comment.