From 30668a131bb2c93127385fbbbba34d47f7bf80e3 Mon Sep 17 00:00:00 2001 From: Bertram Date: Mon, 8 Mar 2010 23:23:42 +0100 Subject: Fix crash with incorrect wallpaper names. (From 4144) Reviewed-by: Bertram --- src/resources/wallpaper.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'src/resources/wallpaper.cpp') diff --git a/src/resources/wallpaper.cpp b/src/resources/wallpaper.cpp index 1f423508..f57f429d 100644 --- a/src/resources/wallpaper.cpp +++ b/src/resources/wallpaper.cpp @@ -73,20 +73,25 @@ void Wallpaper::loadWallpapers() // First, get the base filename of the image: std::string filename = *i; - int separator = filename.rfind("_"); + unsigned int separator = filename.rfind("_"); filename = filename.substr(0, separator); - // Then, append the width and height search mask. - filename.append("_%dx%d.png"); - - if (sscanf(*i, filename.c_str(), &width, &height) == 2) + // Check that the base filename doesn't have any '%' markers. + separator = filename.find("%"); + if (separator == std::string::npos) { - WallpaperData wp; - wp.filename = WALLPAPER_FOLDER; - wp.filename.append(*i); - wp.width = width; - wp.height = height; - wallpaperData.push_back(wp); + // Then, append the width and height search mask. + filename.append("_%dx%d.png"); + + if (sscanf(*i, filename.c_str(), &width, &height) == 2) + { + WallpaperData wp; + wp.filename = WALLPAPER_FOLDER; + wp.filename.append(*i); + wp.width = width; + wp.height = height; + wallpaperData.push_back(wp); + } } } -- cgit v1.2.3-60-g2f50