Kaydet (Commit) 96361261 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Work around Coverity warnings about std::length_error

...escaping from main or being unexpected, in various places, which started when
62dbe2e6 "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
üst 0943adb2
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment