include/i18nlangtag/lang.h | 9 +++++++++ linguistic/source/spelldsp.cxx | 6 +++--- sw/source/filter/ww8/ww8scan.cxx | 8 ++++---- unotools/source/config/lingucfg.cxx | 2 +- 4 files changed, 17 insertions(+), 8 deletions(-)
New commits: commit 2e5e92eed940ea1992f7962b43b6bfcea0daf08b Author: Michael Stahl <mst...@redhat.com> Date: Tue Jun 6 23:04:49 2017 +0200 tdf#108349: fix LanguageType conversions from UNO "short" The bugdoc uses LANGUAGE_USER_LATIN_VATICAN LanguageType(0x8076). The UNO API uses signed "short" for these in various interfaces, and so the LanguageType constructor complains about out-of-(short)-range values. Avoid this by deleting the problematic constructor, so that the places that currently call it with API parameters can be changed to first cast the parameter to unsigned. (Yes, we need to write "template<>" twice in a row. Don't ask me why, i just work here. sberg says we also need to omit the explict <short>.) Change-Id: I2443a89bc8d579504fc707ded3d145f9a625597a Reviewed-on: https://gerrit.libreoffice.org/38473 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Michael Stahl <mst...@redhat.com> (cherry picked from commit 93a41b20538f18344eb1b8c23b1eae134212b141) Reviewed-on: https://gerrit.libreoffice.org/38499 Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/include/i18nlangtag/lang.h b/include/i18nlangtag/lang.h index 3e37953868cc..e5d4a1f42b3f 100644 --- a/include/i18nlangtag/lang.h +++ b/include/i18nlangtag/lang.h @@ -95,6 +95,15 @@ struct LanguageTypeTag {}; typedef o3tl::strong_int<sal_uInt16, LanguageTypeTag> LanguageType; inline std::ostream& operator<<(std::ostream& os, LanguageType const & lt) { os << sal_uInt16(lt); return os; } constexpr LanguageType primary(LanguageType lt) { return LanguageType(sal_uInt16(lt) & 0x03ff); } + +namespace o3tl +{ + // delete "sal_Int16" constructor via specialization: values > 0x7FFF are + // actually used, and unfortunately passed around in the API as signed + // "short", so use this to find all places where casts must be inserted + template<> template<> constexpr strong_int<unsigned short,LanguageTypeTag>::strong_int(short, std::enable_if<std::is_integral<short>::value, int>::type) = delete; +} + #endif #define LANGUAGE_MASK_PRIMARY 0x03ff diff --git a/linguistic/source/spelldsp.cxx b/linguistic/source/spelldsp.cxx index d26993cabb5f..cd893ef654ab 100644 --- a/linguistic/source/spelldsp.cxx +++ b/linguistic/source/spelldsp.cxx @@ -756,7 +756,7 @@ sal_Bool SAL_CALL SpellCheckerDispatcher::hasLanguage( sal_Int16 nLanguage ) { MutexGuard aGuard( GetLinguMutex() ); - return hasLocale( LanguageTag::convertToLocale( LanguageType(nLanguage)) ); + return hasLocale( LanguageTag::convertToLocale(LanguageType(static_cast<sal_uInt16>(nLanguage)))); } @@ -766,7 +766,7 @@ sal_Bool SAL_CALL SpellCheckerDispatcher::isValid( const uno::Sequence< beans::PropertyValue >& rProperties ) { MutexGuard aGuard( GetLinguMutex() ); - return isValid( rWord, LanguageTag::convertToLocale( LanguageType(nLanguage) ), rProperties); + return isValid( rWord, LanguageTag::convertToLocale(LanguageType(static_cast<sal_uInt16>(nLanguage))), rProperties); } @@ -776,7 +776,7 @@ uno::Reference< linguistic2::XSpellAlternatives > SAL_CALL SpellCheckerDispatche const uno::Sequence< beans::PropertyValue >& rProperties ) { MutexGuard aGuard( GetLinguMutex() ); - return spell( rWord, LanguageTag::convertToLocale( LanguageType(nLanguage) ), rProperties); + return spell(rWord, LanguageTag::convertToLocale(LanguageType(static_cast<sal_uInt16>(nLanguage))), rProperties); } diff --git a/sw/source/filter/ww8/ww8scan.cxx b/sw/source/filter/ww8/ww8scan.cxx index fabae0651e6e..f71618f56044 100644 --- a/sw/source/filter/ww8/ww8scan.cxx +++ b/sw/source/filter/ww8/ww8scan.cxx @@ -5531,8 +5531,8 @@ WW8Fib::WW8Fib(SvStream& rSt, sal_uInt8 nWantedVersion, sal_uInt32 nOffset) sal_Int16 cpnBtePap_Ver67=0; // read FIB - sal_Int16 nTmpLid = 0; - rSt.ReadInt16( nTmpLid ); + sal_uInt16 nTmpLid = 0; + rSt.ReadUInt16(nTmpLid); m_lid = LanguageType(nTmpLid); rSt.ReadInt16( m_pnNext ); rSt.ReadUChar( aBits1 ); @@ -5579,8 +5579,8 @@ WW8Fib::WW8Fib(SvStream& rSt, sal_uInt8 nWantedVersion, sal_uInt32 nOffset) && (bVer67 || WW8ReadINT16( rSt, pnLvcFirst_W6 )) // 8 && (bVer67 || WW8ReadINT16( rSt, cpnBteLvc_W6 )) // 9 */ - sal_Int16 nTmpFE = 0; - rSt.ReadInt16( nTmpFE ); + sal_uInt16 nTmpFE = 0; + rSt.ReadUInt16(nTmpFE); m_lidFE = LanguageType(nTmpFE); rSt.ReadUInt16( m_clw ); } diff --git a/unotools/source/config/lingucfg.cxx b/unotools/source/config/lingucfg.cxx index 9dfc019b19ac..d11b9c62fd6f 100644 --- a/unotools/source/config/lingucfg.cxx +++ b/unotools/source/config/lingucfg.cxx @@ -524,7 +524,7 @@ bool SvtLinguConfigItem::SetProperty( sal_Int32 nPropertyHandle, const uno::Any { if (nNew != (sal_uInt16)*plVal) { - *plVal = LanguageType(nNew); + *plVal = LanguageType(static_cast<sal_uInt16>(nNew)); bMod = true; } bSucc = true; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits