fix(chart): add more error handling in XML

This commit is contained in:
Gabor Kiss-Vamosi
2025-04-17 12:09:11 +02:00
committed by Felipe Neves
parent 671d49d545
commit 7256ba0630
+11 -1
View File
@@ -58,7 +58,14 @@ void lv_xml_chart_apply(lv_xml_parser_state_t * state, const char ** attrs)
const char * name = attrs[i];
const char * value = attrs[i + 1];
if(lv_streq("point_count", name)) lv_chart_set_point_count(item, lv_xml_atoi(value));
if(lv_streq("point_count", name)) {
int32_t cnt = lv_xml_atoi(value);
if(cnt < 0) {
LV_LOG_WARN("chart's point count must can't be negative");
cnt = 0;
}
lv_chart_set_point_count(item, cnt);
}
else if(lv_streq("type", name)) lv_chart_set_type(item, chart_type_to_enum(value));
else if(lv_streq("update_mode", name)) lv_chart_set_update_mode(item, chart_update_mode_to_enum(value));
else if(lv_streq("div_line_count", name)) {
@@ -74,6 +81,9 @@ void * lv_xml_chart_series_create(lv_xml_parser_state_t * state, const char ** a
{
const char * color = lv_xml_get_value_of(attrs, "color");
const char * axis = lv_xml_get_value_of(attrs, "axis");
if(color == NULL) color = "0xff0000";
if(axis == NULL) axis = "primary_y";
void * item = lv_chart_add_series(lv_xml_state_get_parent(state), lv_color_hex(lv_xml_strtol(color, NULL, 16)),
chart_axis_to_enum(axis));
return item;