skin_engine: fix div by 0 for %pP tag

rockbox-gerrit-noreply--- via rockbox-cvs <[email protected]> Thu, 30 Jul 2026 06:18:11 -0400
Newsgroups gmane.comp.systems.archos.rockbox.cvs
Message-ID <[email protected]>
commit 3af4e207920c832ec0248c85e84b56a7d49e96ff
Author: Christian Soffke <[email protected]>
Date:   Wed Jul 29 05:57:17 2026 +0200

    skin_engine: fix div by 0 for %pP tag
    
    Fixes possible crash during playback with
    'Auto-Change Directory' setting enabled.
    
    When the currently playing directory changes, the
    skin may be updated on the main thread while the
    playback thread is executing create_and_play_dir
    and has yet to add any indices to the newly created
    playlist.
    
    Introduced in commit 41d5ca3.
    
    Change-Id: I6e930f2db546c7690b362ba8c1a4907d0348ff52

diff --git a/apps/gui/skin_engine/skin_display.c b/apps/gui/skin_engine/skin_display.c
index c2c19b2b8c..abeeef16ff 100644
--- a/apps/gui/skin_engine/skin_display.c
+++ b/apps/gui/skin_engine/skin_display.c
@@ -178,7 +178,7 @@ void draw_progressbar(struct gui_wps *gwps, struct skin_viewport* skin_viewport,
     struct wps_state *state = get_wps_state();
     struct mp3entry *id3 = state->id3;
     int x = pb->x, y = pb->y, width = pb->width, height = pb->height;
-    unsigned long length, end;
+    unsigned long end, length = 0;
     int flags = HORIZONTAL;
 
     if (height < 0)
@@ -221,11 +221,6 @@ void draw_progressbar(struct gui_wps *gwps, struct skin_viewport* skin_viewport,
             length = pl_total;
             end = pl_elapsed;
         }
-        else
-        {
-            length = 1;
-            end = 0;
-        }
     }
     else if (pb->type == SKIN_TOKEN_PEAKMETER_LEFTBAR ||
              pb->type == SKIN_TOKEN_PEAKMETER_RIGHTBAR)
@@ -281,7 +276,8 @@ void draw_progressbar(struct gui_wps *gwps, struct skin_viewport* skin_viewport,
         length = id3->length;
         end = id3->elapsed + state->ff_rewind_count;
     }
-    else
+
+    if (length <= 0)
     {
         length = 1;
         end = 0;
diff --git a/apps/gui/skin_engine/skin_tokens.c b/apps/gui/skin_engine/skin_tokens.c
index 32daf5dc00..cab4385bb9 100644
--- a/apps/gui/skin_engine/skin_tokens.c
+++ b/apps/gui/skin_engine/skin_tokens.c
@@ -1354,6 +1354,8 @@ const char *get_token_value(struct gui_wps *gwps,
         case SKIN_TOKEN_PLAYLIST_PERCENT:
         {
             int playlist_amt = playlist_amount();
+            if (playlist_amt <= 0)
+                return NULL;
             int current_pos = playlist_get_display_index() + offset;
             int percentage = current_pos * 100 / playlist_amt;
 
-- 
rockbox-cvs mailing list
[email protected]
https://lists.haxx.se/mailman/listinfo/rockbox-cvs