From e8be3252531766e0822b46fc5c88cdcec8d98a62 Mon Sep 17 00:00:00 2001 From: dean Date: Sun, 5 Jan 2025 21:07:42 +1100 Subject: [PATCH] lib/term: fix potential issue with modulo --- common/lib/gterm.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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); + } } }