Fix crash on getting .txt from a btn object

This commit is contained in:
fvanroie 2021-01-16 16:21:46 +01:00
parent d206ba15a4
commit 106efdba9a

View File

@ -774,7 +774,7 @@ static inline void haspSetLabelText(lv_obj_t * obj, const char * value)
} }
// OK // OK
static bool haspGetLabelText(lv_obj_t * obj, char * text) static bool haspGetLabelText(lv_obj_t * obj, char ** text)
{ {
if(!obj) { if(!obj) {
Log.warning(TAG_ATTR, F("Button not defined")); Log.warning(TAG_ATTR, F("Button not defined"));
@ -785,7 +785,7 @@ static bool haspGetLabelText(lv_obj_t * obj, char * text)
if(label) { if(label) {
#if 1 #if 1
if(check_obj_type(label, LV_HASP_LABEL)) { if(check_obj_type(label, LV_HASP_LABEL)) {
text = lv_label_get_text(label); *text = lv_label_get_text(label);
return true; return true;
} }
#else #else
@ -1356,7 +1356,7 @@ static void hasp_process_obj_attribute_txt(lv_obj_t * obj, const char * attr, co
haspSetLabelText(obj, payload); haspSetLabelText(obj, payload);
} else { } else {
char * text = NULL; char * text = NULL;
if(haspGetLabelText(obj, text)) hasp_out_str(obj, attr, text); if(haspGetLabelText(obj, &text) && text) hasp_out_str(obj, attr, text);
} }
return; return;
} }
@ -1703,7 +1703,9 @@ void hasp_process_obj_attribute(lv_obj_t * obj, const char * attr_p, const char
case ATTR_ALIGN: case ATTR_ALIGN:
if(check_obj_type(obj, LV_HASP_BUTTON)) { if(check_obj_type(obj, LV_HASP_BUTTON)) {
lv_obj_t * label = FindButtonLabel(obj); lv_obj_t * label = FindButtonLabel(obj);
if(label == NULL) goto attribute_not_found; if(label == NULL)
goto attribute_not_found;
else
update ? lv_label_set_align(label, val) : hasp_out_int(obj, attr, lv_label_get_align(label)); update ? lv_label_set_align(label, val) : hasp_out_int(obj, attr, lv_label_get_align(label));
} else if(check_obj_type(obj, LV_HASP_BTNMATRIX)) { } else if(check_obj_type(obj, LV_HASP_BTNMATRIX)) {