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

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
üst 028ef474
......@@ -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
{
......
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