From 8ad7f3d261619d168ee0bf0e54824f9f354d2970 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Mon, 31 Mar 2014 00:44:37 +0200 Subject: imageicon: clean up unnecessary file existance check introduced in rev 12263. Could theoretically lead to uninitialized value use (of "info" struct) same for filedialogimpl-gtkmm (bzr r13240) --- src/ui/widget/imageicon.cpp | 55 +++++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 34 deletions(-) (limited to 'src/ui/widget/imageicon.cpp') diff --git a/src/ui/widget/imageicon.cpp b/src/ui/widget/imageicon.cpp index cf41a16a4..22abd04ba 100644 --- a/src/ui/widget/imageicon.cpp +++ b/src/ui/widget/imageicon.cpp @@ -369,60 +369,47 @@ isValidImageIconFile(const Glib::ustring &fileName) return false; } +/// \fixme This function is almost an exact duplicate of SVGPreview::set() in ui/dialog/filedialogimpl-gtkmm.cpp. bool ImageIcon::show(const Glib::ustring &fileName) { - - if (!Glib::file_test(fileName, Glib::FILE_TEST_EXISTS)) + if (!Glib::file_test(fileName, Glib::FILE_TEST_EXISTS)) { + showBrokenImage("File does not exist"); return false; + } - gchar *fName = const_cast(fileName.c_str()); - //g_message("fname:%s\n", fName); - - - if (Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)) - { + if (Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)) { + gchar *fName = const_cast(fileName.c_str()); // this const-cast seems not necessary, was it put there because of older sys/stat.h version? struct stat info; - if (g_file_test (fName, G_FILE_TEST_EXISTS) && stat(fName, &info)) - { - Glib::ustring err = "cannot get file info"; - showBrokenImage(err); + if (stat(fName, &info)) // stat returns 0 upon success + { + showBrokenImage("Cannot get file info"); return false; - } - long fileLen = info.st_size; - if (fileLen > 0x150000L) - { - Glib::ustring err = "File too large"; - showBrokenImage(err); + } + if (info.st_size > 0x150000L) { + showBrokenImage("File too large"); return false; - } } + } Glib::ustring svg = ".svg"; Glib::ustring svgz = ".svgz"; - if (hasSuffix(fileName, svg) || hasSuffix(fileName, svgz) ) - { - if (!showSvgFile(fileName)) - { + if (hasSuffix(fileName, svg) || hasSuffix(fileName, svgz)) { + if (!showSvgFile(fileName)) { showBrokenImage(bitmapError); return false; - } - return true; } - else if (isValidImageIconFile(fileName)) - { - if (!showBitmap(fileName)) - { + return true; + } else if (isValidImageIconFile(fileName)) { + if (!showBitmap(fileName)) { showBrokenImage(bitmapError); return false; - } - return true; } - else - { + return true; + } else { showBrokenImage("unsupported file type"); return false; - } + } } -- cgit v1.2.3