Click here to Skip to main content
15,946,342 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralCSS & Sophocles, more related than you know Pin
raddevus22-Jul-24 12:22
mvaraddevus22-Jul-24 12:22 
GeneralRe: CSS & Sophocles, more related than you know Pin
Jeremy Falcon22-Jul-24 14:19
professionalJeremy Falcon22-Jul-24 14:19 
GeneralRe: CSS & Sophocles, more related than you know Pin
raddevus22hrs 58mins ago
mvaraddevus22hrs 58mins ago 
GeneralRe: CSS & Sophocles, more related than you know Pin
Jeremy Falcon18hrs 55mins ago
professionalJeremy Falcon18hrs 55mins ago 
GeneralRe: CSS & Sophocles, more related than you know Pin
Jeremy Falcon18hrs 40mins ago
professionalJeremy Falcon18hrs 40mins ago 
GeneralRe: CSS & Sophocles, more related than you know Pin
raddevus18hrs 26mins ago
mvaraddevus18hrs 26mins ago 
GeneralRe: CSS & Sophocles, more related than you know Pin
Jeremy Falcon16hrs 29mins ago
professionalJeremy Falcon16hrs 29mins ago 
GeneralRe: CSS & Sophocles, more related than you know Pin
RickZeeland22-Jul-24 19:13
mveRickZeeland22-Jul-24 19:13 
AnswerRe: CSS & Sophocles, more related than you know Pin
raddevus22hrs 59mins ago
mvaraddevus22hrs 59mins ago 
GeneralRe: CSS & Sophocles, more related than you know Pin
Jeremy Falcon18hrs 52mins ago
professionalJeremy Falcon18hrs 52mins ago 
JokeRe: CSS & Sophocles, more related than you know Pin
Peter_in_278022-Jul-24 20:27
professionalPeter_in_278022-Jul-24 20:27 
GeneralRe: CSS & Sophocles, more related than you know Pin
TNCaver15hrs 20mins ago
TNCaver15hrs 20mins ago 
GeneralRe: CSS & Sophocles, more related than you know Pin
Richard Deeming4hrs 17mins ago
mveRichard Deeming4hrs 17mins ago 
GeneralLinux C PreProcessor: Who Knew? Pin
raddevus4-Jul-24 6:26
mvaraddevus4-Jul-24 6:26 
GeneralRe: Linux C PreProcessor: Who Knew? Pin
trønderen4-Jul-24 8:22
trønderen4-Jul-24 8:22 
GeneralRe: Linux C PreProcessor: Who Knew? Pin
Jalapeno Bob4-Jul-24 9:46
professionalJalapeno Bob4-Jul-24 9:46 
GeneralRe: Linux C PreProcessor: Who Knew? Pin
raddevus4-Jul-24 10:14
mvaraddevus4-Jul-24 10:14 
GeneralRe: Linux C PreProcessor: Who Knew? Pin
Dave Kreskowiak4-Jul-24 9:37
mveDave Kreskowiak4-Jul-24 9:37 
GeneralRe: Linux C PreProcessor: Who Knew? Pin
raddevus4-Jul-24 10:16
mvaraddevus4-Jul-24 10:16 
GeneralRe: Linux C PreProcessor: Who Knew? Pin
k50549-Jul-24 3:51
mvek50549-Jul-24 3:51 
GeneralRe: Linux C PreProcessor: Who Knew? Pin
raddevus9-Jul-24 4:51
mvaraddevus9-Jul-24 4:51 
GeneralDoes this scare anyone else? Pin
honey the codewitch4-Jul-24 0:44
mvahoney the codewitch4-Jul-24 0:44 
In LVGL you can set an image source to either be a file path or a structure.

C++
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

C++
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 a void* 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:
C++
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

GeneralRe: Does this scare anyone else? Pin
Peter_in_27804-Jul-24 11:33
professionalPeter_in_27804-Jul-24 11:33 
GeneralRe: Does this scare anyone else? Pin
honey the codewitch4-Jul-24 11:35
mvahoney the codewitch4-Jul-24 11:35 
GeneralWhat the hell GCC, again Pin
k50542-Jul-24 11:32
mvek50542-Jul-24 11:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.