[Libreoffice-commits] core.git: basic/source
Stephan Bergmann
sbergman at redhat.com
Mon Mar 20 14:47:14 UTC 2017
basic/source/runtime/methods.cxx | 23 +++++++++--------------
1 file changed, 9 insertions(+), 14 deletions(-)
New commits:
commit 36b4b0fb8c9a3499cfd2f05687ff30c2bfa13706
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Mon Mar 20 15:38:31 2017 +0100
Fix CurDir on Windows
* Allow lowercase argument. (And properly check the sal_Unicode value with
rtl::isAsciiUpperCase instead of with isalpha, which would cause UB for values
outside of unsigned char + EOF).
* Use _wgetdcwd to get a UTF-16 path in the first place (instead of erroneously
converting via createFromAscii and assuming the path only contains 7-bit ASCII
characters).
* At least with a MSVC 2015 Update 3 --enable-dbgutil build, a call like
CurDir("A")
for a non-existent drive A will cause a failure message box
Microsoft Visual C++ Runtime Library
Debug Assertion Failed!
Program: ...\instdir\program\soffice.bin
File: minkernel\crts\ucrt\src\desktopcrt\misc\getcwd.cpp
Line: 225
Expression: ("Invalid Drive", 0)
though, which appears it can't be intercepted---trying with a
_set_thread_local_invalid_parameter_handler around the call to _wgetdcwd
didn't have any effect.
Change-Id: I666f84b0695152c0f2c25de3bae100e58929594a
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx
index 33e4f3640a40..b5746d01427d 100644
--- a/basic/source/runtime/methods.cxx
+++ b/basic/source/runtime/methods.cxx
@@ -31,6 +31,7 @@
#include <vcl/msgbox.hxx>
#include <basic/sbx.hxx>
#include <svl/zforlist.hxx>
+#include <rtl/character.hxx>
#include <rtl/math.hxx>
#include <tools/urlobj.hxx>
#include <osl/time.h>
@@ -405,24 +406,18 @@ RTLFUNC(CurDir)
StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
return;
}
- else
+ auto c = rtl::toAsciiUpperCase(aDrive[0]);
+ if ( !rtl::isAsciiUpperCase( c ) )
{
- nCurDir = (int)aDrive[0];
- if ( !isalpha( nCurDir ) )
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
- }
- else
- {
- nCurDir -= ( 'A' - 1 );
- }
+ StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ return;
}
+ nCurDir = c - 'A' + 1;
}
- char pBuffer[ _MAX_PATH ];
- if ( _getdcwd( nCurDir, pBuffer, _MAX_PATH ) != nullptr )
+ wchar_t pBuffer[ _MAX_PATH ];
+ if ( _wgetdcwd( nCurDir, pBuffer, _MAX_PATH ) != nullptr )
{
- rPar.Get(0)->PutString( OUString::createFromAscii( pBuffer ) );
+ rPar.Get(0)->PutString( OUString( pBuffer ) );
}
else
{
More information about the Libreoffice-commits
mailing list