@@ -236,23 +236,21 @@ void Music::RefreshTrackInfo() {
236236
237237void Music::UpdateLength () {
238238 int remaining = std::max (totalLength - currentPosition, 0 );
239+ int range = std::min (totalLength > 0 ? totalLength : 1 , static_cast <int >(std::numeric_limits<int16_t >::max ()));
239240
240241 if (totalLength > (99 * 60 * 60 )) {
241242 lv_label_set_text_static (txtCurrentPosition, " Inf" );
242243 lv_label_set_text_static (txtTrackDuration, " Inf" );
243244 } else if (totalLength > (99 * 60 )) {
244245 lv_label_set_text_fmt (txtCurrentPosition, " %d:%02d" , (currentPosition / (60 * 60 )) % 100 , ((currentPosition % (60 * 60 )) / 60 ) % 100 );
245246 lv_label_set_text_fmt (txtTrackDuration, " -%d:%02d" , (remaining / (60 * 60 )) % 100 , ((remaining % (60 * 60 )) / 60 ) % 100 );
246- // These conversions are narrowing: lv_bar_set_range accepts int16_t args
247- // resolve by normalising?
248- // same for else branch below
249- lv_bar_set_range (barTrackDuration, 0 , totalLength > 0 ? totalLength : 1 );
250- lv_bar_set_value (barTrackDuration, currentPosition, LV_ANIM_OFF);
247+ lv_bar_set_range (barTrackDuration, 0 , range);
248+ lv_bar_set_value (barTrackDuration, std::min (currentPosition, range), LV_ANIM_OFF);
251249 } else {
252250 lv_label_set_text_fmt (txtCurrentPosition, " %d:%02d" , (currentPosition / 60 ) % 100 , (currentPosition % 60 ) % 100 );
253251 lv_label_set_text_fmt (txtTrackDuration, " -%d:%02d" , (remaining / 60 ) % 100 , (remaining % 60 ) % 100 );
254- lv_bar_set_range (barTrackDuration, 0 , totalLength > 0 ? totalLength : 1 );
255- lv_bar_set_value (barTrackDuration, currentPosition, LV_ANIM_OFF);
252+ lv_bar_set_range (barTrackDuration, 0 , range );
253+ lv_bar_set_value (barTrackDuration, std::min ( currentPosition, range) , LV_ANIM_OFF);
256254 }
257255}
258256
0 commit comments