[Libreoffice-commits] core.git: sal/osl

Stephan Bergmann sbergman at redhat.com
Thu Nov 12 04:40:40 PST 2015


 sal/osl/unx/file_url.cxx |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

New commits:
commit 963612613ac95d391ea051f596d24fff6cf3b8d2
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Thu Nov 12 13:16:44 2015 +0100

    Work around Coverity warnings about std::length_error
    
    ...escaping from main or being unexpected, in various places, which started when
    62dbe2e6eb30660f252b4e2c048f4aecf28e41c6 "Clean up osl_getSystemPathFromFileURL
    implementation" made osl_getSystemPathFromFileURL (indirectly) call
    rtl_uString_newConcatAsciiL, which can throw std::length_error.
    
    There is no ideal fix for this.  "The distinguishing characteristic of logic
    errors [i.e., incl. std::length_error] is that they are due to errors in the
    internal logic of the program.  In theory, they are preventable."
    ([std.exceptions])  That means that throwing a logic error is more akin to
    raising an assert than to throwing some other kind or exception that is intended
    to be handled by the program.  Which in turn means that it would generally be
    more useful to cause such errors to cause calls to std::abort (and produce a
    core/backtrace), than to catch and try to somehow handle them.  But there
    appears to be no way to tell Coverity not to emit warnings about uncaught logic
    errors, and it tends to emit quite a number of them for each signle "root
    cause," so be pragmatic for now and catch it close to the root.
    
    Change-Id: Iee71f50e3304954e9e88f326e0fa2167b6051ca2

diff --git a/sal/osl/unx/file_url.cxx b/sal/osl/unx/file_url.cxx
index 839eae2..cc9907a 100644
--- a/sal/osl/unx/file_url.cxx
+++ b/sal/osl/unx/file_url.cxx
@@ -22,6 +22,7 @@
 #include "system.hxx"
 
 #include <cassert>
+#include <stdexcept>
 #include <limits.h>
 #include <errno.h>
 #include <strings.h>
@@ -204,8 +205,13 @@ oslFileError getSystemPathFromFileUrl(
 oslFileError SAL_CALL osl_getSystemPathFromFileURL( rtl_uString *ustrFileURL, rtl_uString **pustrSystemPath )
 {
     OUString path;
-    auto e = getSystemPathFromFileUrl(
-        OUString::unacquired(&ustrFileURL), &path, true);
+    oslFileError e;
+    try {
+        e = getSystemPathFromFileUrl(
+            OUString::unacquired(&ustrFileURL), &path, true);
+    } catch (std::length_error) {
+        e = osl_File_E_RANGE;
+    }
     if (e == osl_File_E_None) {
         rtl_uString_assign(pustrSystemPath, path.pData);
     }


More information about the Libreoffice-commits mailing list