[Libreoffice-commits] core.git: basic/source
Stephan Bergmann (via logerrit)
logerrit at kemper.freedesktop.org
Fri Dec 6 09:17:35 UTC 2019
basic/source/runtime/methods.cxx | 27 ++++++++++++++++++++++++++-
1 file changed, 26 insertions(+), 1 deletion(-)
New commits:
commit 9235990b4eacbc8a90750da8bdf2fb15f99a9d79
Author: Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Fri Dec 6 08:59:06 2019 +0100
Commit: Stephan Bergmann <sbergman at redhat.com>
CommitDate: Fri Dec 6 10:16:06 2019 +0100
tdf#129136 Call _wgetdcwd with "harmless" invalid parameter handler
The documentation of _getdcwd/_wgetdcwd specifies: "If the specified drive
isn't available, or the kind of drive (for example, removable, fixed, CD-ROM,
RAM disk, or network drive) can't be determined, the invalid-parameter handler
is invoked." (<https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/
getdcwd-wgetdcwd?view=vs-2017>) The default handler terminates the process, so
temporarily install a "harmless" one.
(e30f3bcd25762236eb739584dc71691123527c9f "Revert 'fdo#38913: Prevent invalid
parameter handler crashes'" had removed a global "harmless" handler installed
with _set_invalid_parameter_handler to handle JVM-related issues, but which was
then considered no longer necessary. I assume that for those JVM-related issues
there was no obvious place where to install a temporary
_set_thread_local_invalid_parameter_handler, and that that was the reason for
the global _set_invalid_parameter_handler in sal_detail_initialize. I cannot
find any information that _set_thread_local_invalid_parameter_handler would be
available in fewer versions of Windows than _set_invalid_parameter_handler, and
might even be missing on Windows versions that we target.)
(It appears that at least when building with MSVC 2019 and running on Windows 8,
with an --enable-dbgutil build (presumably due to MSVC_USE_DEBUG_RUNTIME) a
"Microsoft Visual C++ Runtime Library: Debug Assertion Failed!" error dialog
still pops up, which needs to be quit with "Ignore" before our
invalidParameterHandler is called.)
Change-Id: I983d622eb03549873a63305f51bf0869d7fea33a
Reviewed-on: https://gerrit.libreoffice.org/84597
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman at redhat.com>
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx
index 95057cb854c5..4860ec34376d 100644
--- a/basic/source/runtime/methods.cxx
+++ b/basic/source/runtime/methods.cxx
@@ -346,6 +346,25 @@ void SbRtl_ChrW(StarBASIC *, SbxArray & rPar, bool)
implChr( rPar, true/*bChrW*/ );
}
+#if defined _WIN32
+
+namespace {
+
+extern "C" void invalidParameterHandler(
+ wchar_t const * expression, wchar_t const * function, wchar_t const * file, unsigned int line,
+ uintptr_t)
+{
+ SAL_INFO(
+ "basic",
+ "invalid parameter during _wgetdcwd; \"" << (expression ? o3tl::toU(expression) : u"???")
+ << "\" (" << (function ? o3tl::toU(function) : u"???") << ") at "
+ << (file ? o3tl::toU(file) : u"???") << ":" << line);
+}
+
+}
+
+#endif
+
void SbRtl_CurDir(StarBASIC * pBasic, SbxArray & rPar, bool bWrite)
{
(void)pBasic;
@@ -375,7 +394,13 @@ void SbRtl_CurDir(StarBASIC * pBasic, SbxArray & rPar, bool bWrite)
nCurDir = c - 'A' + 1;
}
wchar_t pBuffer[ _MAX_PATH ];
- if ( _wgetdcwd( nCurDir, pBuffer, _MAX_PATH ) != nullptr )
+ // _wgetdcwd calls the C runtime's invalid parameter handler (which by default terminates the
+ // process) if nCurDir does not correspond to an existing drive, so temporarily set a "harmless"
+ // handler:
+ auto const handler = _set_thread_local_invalid_parameter_handler(&invalidParameterHandler);
+ auto const ok = _wgetdcwd( nCurDir, pBuffer, _MAX_PATH ) != nullptr;
+ _set_thread_local_invalid_parameter_handler(handler);
+ if ( ok )
{
rPar.Get(0)->PutString( o3tl::toU(pBuffer) );
}
More information about the Libreoffice-commits
mailing list