Răsfoiți Sursa

fix: lcd,drawLine若x1>x2,或者y1>y2时,会申请一个负数长度的内存块

Wendal Chen 3 luni în urmă
părinte
comite
d39d59a7c7
1 a modificat fișierele cu 12 adăugiri și 0 ștergeri
  1. 12 0
      components/lcd/luat_lcd.c

+ 12 - 0
components/lcd/luat_lcd.c

@@ -566,6 +566,18 @@ int luat_lcd_draw_line(luat_lcd_conf_t* conf,int16_t x1, int16_t y1, int16_t x2,
     int incx, incy, row, col;
     if (x1 == x2 || y1 == y2) // 直线
     {
+        if (x1 > x2)
+        {
+            int16_t tmp = x1;
+            x1 = x2;
+            x2 = tmp;
+        }
+        if (y1 > y2)
+        {
+            int16_t tmp = y1;
+            y1 = y2;
+            y2 = tmp;
+        }
         size_t dots = (x2 - x1 + 1) * (y2 - y1 + 1);//点数量
         luat_color_t* line_buf = (luat_color_t*) luat_heap_malloc(dots * sizeof(luat_color_t));
         if (conf->endianness_swap)