afiskon / stm32-ssd1306

STM32 library for working with OLEDs based on SSD1306, SH1106, SH1107 and SSD1309, supports I2C and SPI
https://eax.me/stm32-ssd1306/
MIT License
740 stars 206 forks source link

Possible endless cycle #60

Closed Alex-Trusk closed 1 year ago

Alex-Trusk commented 1 year ago

https://github.com/afiskon/stm32-ssd1306/blob/11c023452e2a9baa69069810fc11f32912daa3d5/ssd1306/ssd1306.c#L541

Hi. If someone tries to draw filled rectangle with coordinates starting with 0,0 (ex. FillRectangle(0,0,10,10,Black), he or she will be surprised. Program gets in an endless cycle.

for (uint8_t y = y2; y >= y1; y--) {
        for (uint8_t x = x2; x >= x1; x--) {
            ssd1306_DrawPixel(x, y, color);
        }
    }

Imagine x1=0 and x is constantly decreasing after each cycle.

  1. x=1, 1>=0 - true
  2. x=0, 0>=0 - true
  3. x=255, 255>=0 -true. "x" is an unsigned var.
    And so on.

By the way, I didn't search for problems in other similar functions. Maybe they should be reconsidered.

afiskon commented 1 year ago

@HeatseekerXXX good catch, thanks for reporting it. Would you like to submit a fix?

Alex-Trusk commented 1 year ago

Made some changes in FillRectangle func that fixed issue. Also allowing to draw rect in any direction.