Does this scare anyone else?
-
In LVGL you can set an image source to either be a file path or a structure.
lv_obj_t* ui_img = lv_img_create(ui_screen);
lv_img_dsc_t img_dsc;
img_dsc.header.always_zero = 0;
img_dsc.header.cf = LV_IMG_CF_RAW;
img_dsc.header.w = 800;
img_dsc.header.h = 480;
img_dsc.data_size = 800*480*LV_COLOR_DEPTH/8;
uint8_t *img_mem = (uint8_t*)ps_malloc(img_dsc.data_size);
img_dsc.data = img_mem;
memset(img_mem,0,img_dsc.data_size);
lv_img_set_src(ui_img,&img_dsc);That's one option. Here's another
lv_obj_t* ui_img = lv_img_create(ui_screen);
lv_img_set_src(ui_img,"A:/minou_480.jpg");The
lv_img_set_src()
function takes avoid*
for the second argument and either accepts an instance of a lv_img_dsc_t structure or a string! Worse, there's no lv_img_dsc_init() function to set the struct to a known state (with for example, a magic cookie in it that can be used to flag it as the structure rather than a string) Ultimately here's how it checks:if(u8_p[0] >= 0x20 && u8_p[0] <= 0x7F)
where u8_p[0] is the first byte of the source argument. This is in battle tested production code used in many many devices in the real world.
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
-
In LVGL you can set an image source to either be a file path or a structure.
lv_obj_t* ui_img = lv_img_create(ui_screen);
lv_img_dsc_t img_dsc;
img_dsc.header.always_zero = 0;
img_dsc.header.cf = LV_IMG_CF_RAW;
img_dsc.header.w = 800;
img_dsc.header.h = 480;
img_dsc.data_size = 800*480*LV_COLOR_DEPTH/8;
uint8_t *img_mem = (uint8_t*)ps_malloc(img_dsc.data_size);
img_dsc.data = img_mem;
memset(img_mem,0,img_dsc.data_size);
lv_img_set_src(ui_img,&img_dsc);That's one option. Here's another
lv_obj_t* ui_img = lv_img_create(ui_screen);
lv_img_set_src(ui_img,"A:/minou_480.jpg");The
lv_img_set_src()
function takes avoid*
for the second argument and either accepts an instance of a lv_img_dsc_t structure or a string! Worse, there's no lv_img_dsc_init() function to set the struct to a known state (with for example, a magic cookie in it that can be used to flag it as the structure rather than a string) Ultimately here's how it checks:if(u8_p[0] >= 0x20 && u8_p[0] <= 0x7F)
where u8_p[0] is the first byte of the source argument. This is in battle tested production code used in many many devices in the real world.
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
img_dsc.header.always_zero = 0;
I have no idea of the layout of the struct, but for example if this is at the start, it would discriminate it from a valid string, would it not? Then the range check would separate empty strings from real ones.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
-
img_dsc.header.always_zero = 0;
I have no idea of the layout of the struct, but for example if this is at the start, it would discriminate it from a valid string, would it not? Then the range check would separate empty strings from real ones.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
It is at the beginning of the struct and it is used as a discriminator. And yet it seems extremely accident prone, and I should add the docs do not clarify this. At worst there should be, IMO, a function to initialize the structure. At best, there should actually be two lv_img_set_src() functions - one for paths, and one for lv_img_dsc_t structs.
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix