diff options
author | Caolán McNamara <caolanm@redhat.com> | 2014-08-31 14:29:20 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2014-09-02 12:14:45 +0100 |
commit | 3101a60751a220f4192f0d0e3df4096217f4a16c (patch) | |
tree | 1b1f7de20b2c4e5ba632c094d869e7e1cb27fbd7 /vcl | |
parent | 54ceedfb4d3c0e6df67b86fb422ec3209582fbfa (diff) |
coverity#1233506 Use of untrusted scalar value
Change-Id: I843f688b47489db90edcdb75a15403c66aad55af
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/window/keycod.cxx | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/vcl/source/window/keycod.cxx b/vcl/source/window/keycod.cxx index 8cb9909d6a59..dd111f66de35 100644 --- a/vcl/source/window/keycod.cxx +++ b/vcl/source/window/keycod.cxx @@ -49,14 +49,23 @@ static const sal_uInt16 aImplKeyFuncTab[(KEYFUNC_FRONT+1)*4] = 0, 0, 0, 0 // KEYFUNC_FRONT }; -void ImplGetKeyCode( KeyFuncType eFunc, sal_uInt16& rCode1, sal_uInt16& rCode2, sal_uInt16& rCode3, sal_uInt16& rCode4 ) +bool ImplGetKeyCode( KeyFuncType eFunc, sal_uInt16& rCode1, sal_uInt16& rCode2, sal_uInt16& rCode3, sal_uInt16& rCode4 ) { - sal_uInt16 nIndex = (sal_uInt16)eFunc; + size_t nIndex = static_cast<size_t>(eFunc); nIndex *= 4; + + assert(nIndex + 3 < SAL_N_ELEMENTS(aImplKeyFuncTab) && "bad key code index"); + if (nIndex + 3 >= SAL_N_ELEMENTS(aImplKeyFuncTab)) + { + rCode1 = rCode2 = rCode3 = rCode4 = 0; + return false; + } + rCode1 = aImplKeyFuncTab[nIndex]; rCode2 = aImplKeyFuncTab[nIndex+1]; rCode3 = aImplKeyFuncTab[nIndex+2]; - rCode4 = aImplKeyFuncTab[nIndex+3]; + rCode4 = aImplKeyFuncTab[nIndex+3]; + return true; } vcl::KeyCode::KeyCode( KeyFuncType eFunction ) @@ -112,7 +121,7 @@ KeyFuncType vcl::KeyCode::GetFunction() const sal_uInt16 nKeyCode1; sal_uInt16 nKeyCode2; sal_uInt16 nKeyCode3; - sal_uInt16 nKeyCode4; + sal_uInt16 nKeyCode4; ImplGetKeyCode( (KeyFuncType)i, nKeyCode1, nKeyCode2, nKeyCode3, nKeyCode4 ); if ( (nCompCode == nKeyCode1) || (nCompCode == nKeyCode2) || (nCompCode == nKeyCode3) || (nCompCode == nKeyCode4) ) return (KeyFuncType)i; |