BUG OF THE MONTH | Unreachable code
V547 Expression ‘disp’ is always true. lv_disp.c 148
uint32_t lv_disp_get_inactive_time(const lv_disp_t * disp) { if(!disp) disp = lv_disp_get_default(); if(!disp) { LV_LOG_WARN("lv_disp_get_inactive_time: no display registered"); return 0; } if(disp) return lv_tick_elaps(disp->last_activity_time); lv_disp_t * d; uint32_t t = UINT32_MAX; d = lv_disp_get_next(NULL); while(d) { t = LV_MATH_MIN(t, lv_tick_elaps(d->last_activity_time)); d = lv_disp_get_next(d); } return t; }
The function returns if disp is a null pointer. This is followed by an opposite check – whether the disp pointer is non-null (which is always true) – and the function returns all the same.
Because of this logic, part of the code in the function’s body will never get control.
Please click here to see more bugs from this project.