Microchip-MPLAB-Harmony / gfx

Harmony 3 Graphics library
https://microchip-mplab-harmony.github.io/gfx/
Other
16 stars 15 forks source link

SPI 4 Wire Driver dereferencing a -1 Pointer #32

Open burnin opened 1 year ago

burnin commented 1 year ago

While playing around with the library i found a small bug in the code. I generated code for a ILI9844 display with the "LE SPI 4-Line" + "LE External Controller" Modules. MPLabX 6.05, XC32 v4.21, GFX library v3.12.2 (Latest).

Bug: drv_gfx_external_controller.c - DRV_ILI9488_Update() calls GFX_Disp_Intf_Open() from drv_gfx_disp_intf_spi4.c which normally returns a Pointer of type GFX_Disp_Intf. On failure GFX_Disp_Intf_Open() returns -1. But the DRV_ILI9488_Update() function checks for 0 (NULL) instead of -1. Which later results in a data bus exception when the GFX_Disp_Intf_Write() function dereferences the -1 pointer.

Fix: GFX_Disp_Intf_Open() should return 0 instead of -1 on failure which would be consistent with how invalid pointers are usually handled.

Personal opinion / coding style stuff: The GFX_Disp_Intf type is typedef'd as a uint32_t which might be why it was confused for a handle instead of a pointer. So maybe put a void* or uintptr_t there instead of uint32_t so it is 100% clear that this should be a pointer.

MHGC commented 1 year ago

Thanks for the feedback. We will look into this.