diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2017-03-21 09:12:25 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2017-03-21 09:12:25 +0100 |
commit | d8ce3f60bad3ebaa0888b35f85ab1a211714bb14 (patch) | |
tree | c228c8c6e359f33985172791d916b50cd39596ea /filter | |
parent | e6ce64b1d7d7a0e451af567360cdaf27079258c9 (diff) |
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
Diffstat (limited to 'filter')
-rw-r--r-- | filter/source/msfilter/msvbahelper.cxx | 15 |
1 files changed, 7 insertions, 8 deletions
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 ); |