Be a little more careful to handle exceptions from boost::filesystem::file_size
authorCarl Hetherington <cth@carlh.net>
Mon, 29 Nov 2021 23:00:17 +0000 (00:00 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 29 Nov 2021 23:00:17 +0000 (00:00 +0100)
There has been a report of file_size throwing an exception and
crashing DCP-o-matic, but I haven't been able to reproduce it yet
(possibly related to there being missing content files).

src/lib/file_log.cc
src/wx/config_dialog.cc

index 246641cc96c09f187587c8505c52be39ed5d77ab..a9522bad507dc722033074c9a5abd45c7770dcf5 100644 (file)
@@ -69,7 +69,11 @@ FileLog::head_and_tail (int amount) const
 
        uintmax_t head_amount = amount;
        uintmax_t tail_amount = amount;
-       uintmax_t size = boost::filesystem::file_size (_file);
+       boost::system::error_code ec;
+       uintmax_t size = boost::filesystem::file_size (_file, ec);
+       if (size == static_cast<uintmax_t>(-1)) {
+               return "";
+       }
 
        if (size < (head_amount + tail_amount)) {
                head_amount = size;
index 53c67d101d8e611dca2c101fbafe576d7c696686..e0effec53eafb90a25d2ff2e966f9d92f90406d7 100644 (file)
@@ -633,7 +633,7 @@ CertificateChainEditor::import_private_key ()
                        chain->set_key (dcp::file_to_string (p));
                        _set (chain);
                        update_private_key ();
-               } catch (dcp::MiscError& e) {
+               } catch (std::exception& e) {
                        error_dialog (this, _("Could not read certificate file."), std_to_wx(e.what()));
                }
        }