Browse Source

ImDrawList: Fixed AddConvexPolyFilled() undefined behavior when passing points_count smaller than 3, in particular, points_count==0 could lead to a memory stomp if the draw list was previously empty.

omar 6 years ago
parent
commit
5719b23e01
2 changed files with 5 additions and 0 deletions
  1. 2 0
      docs/CHANGELOG.txt
  2. 3 0
      imgui_draw.cpp

+ 2 - 0
docs/CHANGELOG.txt

@@ -47,6 +47,8 @@ Other Changes:
 - DragFloat: Disabled setting a default drag speed when one edge is FLT_MAX. (#2024)
 - DragFloat: Disabled setting a default drag speed when one edge is FLT_MAX. (#2024)
 - BeginMenu(): Fixed menu popup horizontal offset being off the item in the menu bar when WindowPadding=0.0f.
 - BeginMenu(): Fixed menu popup horizontal offset being off the item in the menu bar when WindowPadding=0.0f.
 - ArrowButton(): Fixed arrow shape being horizontally misaligned by (FramePadding.y-FramePadding.x) if they are different.
 - ArrowButton(): Fixed arrow shape being horizontally misaligned by (FramePadding.y-FramePadding.x) if they are different.
+- ImDrawList: Fixed AddConvexPolyFilled() undefined behavior when passing points_count smaller than 3,
+  in particular, points_count==0 could lead to a memory stomp if the draw list was previously empty.
 
 
 
 
 -----------------------------------------------------------------------
 -----------------------------------------------------------------------

+ 3 - 0
imgui_draw.cpp

@@ -822,6 +822,9 @@ void ImDrawList::AddPolyline(const ImVec2* points, const int points_count, ImU32
 
 
 void ImDrawList::AddConvexPolyFilled(const ImVec2* points, const int points_count, ImU32 col)
 void ImDrawList::AddConvexPolyFilled(const ImVec2* points, const int points_count, ImU32 col)
 {
 {
+    if (points_count < 3)
+        return;
+
     const ImVec2 uv = _Data->TexUvWhitePixel;
     const ImVec2 uv = _Data->TexUvWhitePixel;
 
 
     if (Flags & ImDrawListFlags_AntiAliasedFill)
     if (Flags & ImDrawListFlags_AntiAliasedFill)