:: commit e8be3252531766e0822b46fc5c88cdcec8d98a62

dean <dean243@hotmail.com> — 2025-01-05 10:07

parents: 110ac82af5

lib/term: fix potential issue with modulo

diff --git a/common/lib/gterm.c b/common/lib/gterm.c
index 2056f562..09f3d9d0 100644
--- a/common/lib/gterm.c
+++ b/common/lib/gterm.c
@@ -593,12 +593,14 @@ bool gterm_init(struct fb_info **_fbs, size_t *_fbs_count,
         wallpaper_count++;
 
     background = NULL;
-    char *background_path = config_get_value(config, rand32() % wallpaper_count, "WALLPAPER");
-    if (background_path != NULL) {
-        struct file_handle *bg_file;
-        if ((bg_file = uri_open(background_path)) != NULL) {
-            background = image_open(bg_file);
-            fclose(bg_file);
+    if (wallpaper_count > 0) {
+        char *background_path = config_get_value(config, rand32() % wallpaper_count, "WALLPAPER");
+        if (background_path != NULL) {
+            struct file_handle *bg_file;
+            if ((bg_file = uri_open(background_path)) != NULL) {
+                background = image_open(bg_file);
+                fclose(bg_file);
+            }
         }
     }
 
tab: 248 wrap: offon