From f2cd2c9f037174795b6183e62f2fcf6ee9b22739 Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Sun, 16 May 2021 15:47:10 +0200 Subject: [PATCH] WRaster: Properly set file's mtime in the cache when loading an image The library maintains a cache to not reload a file that was previously loaded. In order to still reload an image in case its file would have changed in the meantime, the cache saves the file's modification time. As reported by Coverity (CID #331576) the 'stat' function was not on the execution path the first time an image is loaded, which means the cache information is populated with junk data. This could lead to an image not being reloaded for example. Signed-off-by: Christophe CURIS --- wrlib/load.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/wrlib/load.c b/wrlib/load.c index fb99876d..f71adba6 100644 --- a/wrlib/load.c +++ b/wrlib/load.c @@ -246,6 +246,11 @@ RImage *RLoadImage(RContext *context, const char *file, int index) int oldest_idx = 0; int done = 0; + if (stat(file, &st) != 0) { + /* If we can't get the info, at least use a valid time to reduce risk of problems */ + st.st_mtime = oldest; + } + for (i = 0; i < RImageCacheSize; i++) { if (!RImageCache[i].file) { RImageCache[i].file = malloc(strlen(file) + 1);