lvgl / lv_demos

Examples, tutorials and applications for the LVGL embedded GUI library
https://lvgl.io
488 stars 366 forks source link

Eliminate lv_snprintf into possibly invalid/short text buffers. #139

Closed cmumford closed 2 years ago

cmumford commented 2 years ago

lv_obj_draw_part_dsc_t::text is a const char * which is modifiable. My "modifiable" the pointer value may be changed - not that it points to a modifiable buffer. At present LVGL seems to only set text to a local variable, so it will be either NULL, or a dangling pointer. Furthermore lv_snprintf was using sizeof(dsc->test) to determine the buffer size. This would always use a size of 4.

This change avoids the unnecessary call to lv_snprintf, since no formatting is being done, by using static const variables.

This may fix a memory corruption bug.

cmumford commented 2 years ago

I see there is a merge conflict because this has been addressed somewhat in master already. I'm going to close this PR. Might resubmit if still an issue.