浏览代码

Fixed unlikely buffer overrun in InputCharacters (thanks Daniel Collin)

ocornut 11 年之前
父节点
当前提交
9f05a2bb16
共有 2 个文件被更改,包括 2 次插入2 次删除
  1. 1 1
      imgui.cpp
  2. 1 1
      imgui.h

+ 1 - 1
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;

+ 1 - 1
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[]