[Libreoffice-commits] core.git: filter/source
Stephan Bergmann
sbergman at redhat.com
Tue Mar 21 08:18:11 UTC 2017
filter/source/msfilter/msvbahelper.cxx | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
New commits:
commit d8ce3f60bad3ebaa0888b35f85ab1a211714bb14
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Tue Mar 21 09:12:25 2017 +0100
Fix ooo::vba::parseKeyEvent
Use rtl::isAscii* functions (correctly operating on OUString elements) instead
of truncating OUString elements to char and then using <ctype.h> is* functions
(which, in addition, for one can cause UB for char arguments when char is
singed, and for another can be locale-dependent).
(Found when auditing uses of <ctype.h> is* functions.)
Change-Id: I826aec92b18bd5dba72ceb69ff88c477d6ebd44c
diff --git a/filter/source/msfilter/msvbahelper.cxx b/filter/source/msfilter/msvbahelper.cxx
index d3830b93fa21..ed3eb18ebe03 100644
--- a/filter/source/msfilter/msvbahelper.cxx
+++ b/filter/source/msfilter/msvbahelper.cxx
@@ -600,7 +600,7 @@ OUString SAL_CALL VBAMacroResolver::resolveScriptURLtoVBAMacro( const OUString&
throw uno::RuntimeException();
}
-bool getModifier( char c, sal_uInt16& mod )
+bool getModifier( sal_Unicode c, sal_uInt16& mod )
{
if ( c == '+' ) {
mod |= KEY_SHIFT;
@@ -616,17 +616,17 @@ bool getModifier( char c, sal_uInt16& mod )
}
/// @throws uno::RuntimeException
-sal_uInt16 parseChar( char c )
+sal_uInt16 parseChar( sal_Unicode c )
{
sal_uInt16 nVclKey = 0;
- // do we care about locale here for isupper etc. ? probably not
- if ( isalpha( c ) )
+ // do we care about locale here for letters/digits? probably not
+ if ( rtl::isAsciiAlpha( c ) )
{
nVclKey |= ( rtl::toAsciiUpperCase( c ) - 'A' ) + KEY_A;
if ( rtl::isAsciiUpperCase( c ) )
nVclKey |= KEY_SHIFT;
}
- else if ( isdigit( c ) )
+ else if ( rtl::isAsciiDigit( c ) )
nVclKey |= ( c - '0' ) + KEY_0;
else if ( c == '~' ) // special case
nVclKey = KEY_RETURN;
@@ -707,8 +707,7 @@ awt::KeyEvent parseKeyEvent( const OUString& Key )
// else it should be just one char of ( 'a-z,A-Z,0-9' )
if ( sKeyCode.getLength() == 1 ) // ( a single char )
{
- char c = (char)( sKeyCode[ 0 ] );
- nVclKey |= parseChar( c );
+ nVclKey |= parseChar( sKeyCode[ 0 ] );
}
else // key should be enclosed in '{}'
{
@@ -718,7 +717,7 @@ awt::KeyEvent parseKeyEvent( const OUString& Key )
sKeyCode = sKeyCode.copy(1, sKeyCode.getLength() - 2 );
if ( sKeyCode.getLength() == 1 )
- nVclKey |= parseChar( (char)( sKeyCode[ 0 ] ) );
+ nVclKey |= parseChar( sKeyCode[ 0 ] );
else
{
auto it = s_KeyCodes.find( sKeyCode );
More information about the Libreoffice-commits
mailing list