Description
Sometimes a button matrix callback function is passed a NULL object. I’m not strictly certain that this bug is limited to button matrices, but this is the only callback I call frequently. This is for an overlay to allow data-entry via 10-key (I stole inspiration from here).
What MCU/Processor/Board and compiler are you using?
Code::Blocks Simulator
What do you experience?
I originally saw this issue in my embedded application, but I can reproduce this in the Simulator as well. On occasion I am seeing a NULL object passed into my button matrix callback function. I was not originally error-checking for NULL, and this caused seg faults in my application.
What do you expect?
I don’t ever expect a callback to have a NULL object argument.
Code to reproduce
With the code below, I should never be able to hit a breakpoint on the line volatile int x = 0; but after pressing the buttons somewhat rapidly for a short amount of time (< 15s) the debugger halts on this line. It seems to be even faster in my embedded project, but I have a more difficult time debugging that.
static void cb_10key(lv_obj_t *obj, lv_event_t event) {
switch(event) {
case LV_EVENT_VALUE_CHANGED:
if (obj != NULL) {
const char *p = lv_btnm_get_active_btn_text(obj);
if (strcmp(p, "Cancel") == 0) {
// save nothing, go back
} else if (strcmp(p, "Save") == 0) {
if (ip_or_mask == CONF_IP) {
lv_ta_set_text(ta_ipaddr, lv_ta_get_text(ta_cfg));
} else {
lv_ta_set_text(ta_maskaddr, lv_ta_get_text(ta_cfg));
}
// TODO: Save IP/Mask
} else if (strcmp(p, "Bksp") == 0) {
lv_ta_del_char(ta_cfg);
} else {
lv_ta_add_text(ta_cfg, p);
}
} else {
volatile int x = 0;
}
break;
};
}