diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2016-12-12 15:31:35 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2016-12-12 18:02:57 +0000 |
commit | 385f6240278b38643894158d2eb7001f25fc965b (patch) | |
tree | f971df1481b714bd2f95c06bef997cf49e02243d | |
parent | 8845ccc1d46fe09eae7b37367a6fbc774fd0b7a4 (diff) |
Prevent use of ORowSetValue with sal_Bool as TINYINT
sal_Bool and sal_uInt8 are typedefs for the same underlying type, so any use of
ORowSetValue with sal_Bool instead of bool, apparently intending to treat the
value as a boolean, actually treated it as a TINYINT. (See e.g. recent
7b0c57b2faec875c790051d233d1e9abaed2a3bc "some compilers don't like implicit
bool-to-ORowSetValue conversion".)
Now that there's no way to create a sal_uInt8 ORowSetValue, getUInt8 and the
m_uInt8 union member can probably go away, too.
Change-Id: Ia27554f76e7e9edce6410284b578064573e54fd3
Reviewed-on: https://gerrit.libreoffice.org/31909
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
-rw-r--r-- | compilerplugins/clang/salbool.cxx | 4 | ||||
-rw-r--r-- | connectivity/qa/connectivity/commontools/FValue_test.cxx | 23 | ||||
-rw-r--r-- | connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx | 2 | ||||
-rw-r--r-- | connectivity/source/commontools/FValue.cxx | 14 | ||||
-rw-r--r-- | connectivity/source/drivers/file/FResultSet.cxx | 2 | ||||
-rw-r--r-- | connectivity/source/drivers/firebird/DatabaseMetaData.cxx | 2 | ||||
-rw-r--r-- | connectivity/source/drivers/firebird/ResultSet.cxx | 4 | ||||
-rw-r--r-- | connectivity/source/drivers/odbc/OResultSet.cxx | 2 | ||||
-rw-r--r-- | dbaccess/source/core/api/BookmarkSet.cxx | 2 | ||||
-rw-r--r-- | dbaccess/source/core/api/PrivateRow.cxx | 2 | ||||
-rw-r--r-- | dbaccess/source/core/api/RowSetBase.cxx | 2 | ||||
-rw-r--r-- | include/connectivity/FValue.hxx | 15 |
12 files changed, 15 insertions, 59 deletions
diff --git a/compilerplugins/clang/salbool.cxx b/compilerplugins/clang/salbool.cxx index a443234e779c..2da581111264 100644 --- a/compilerplugins/clang/salbool.cxx +++ b/compilerplugins/clang/salbool.cxx @@ -647,7 +647,9 @@ bool SalBool::VisitFunctionDecl(FunctionDecl const * decl) { if (ignoreLocation(decl)) { return true; } - if (isSalBool(compat::getReturnType(*decl).getNonReferenceType())) { + if (isSalBool(compat::getReturnType(*decl).getNonReferenceType()) + && !(decl->isDeletedAsWritten() && isa<CXXConversionDecl>(decl))) + { FunctionDecl const * f = decl->getCanonicalDecl(); OverrideKind k = getOverrideKind(f); if (k != OverrideKind::YES diff --git a/connectivity/qa/connectivity/commontools/FValue_test.cxx b/connectivity/qa/connectivity/commontools/FValue_test.cxx index c90fa588fa5b..036fbbc3ca5f 100644 --- a/connectivity/qa/connectivity/commontools/FValue_test.cxx +++ b/connectivity/qa/connectivity/commontools/FValue_test.cxx @@ -34,7 +34,6 @@ public: void test_Bool(); void test_Int8(); - void test_uInt8(); void test_Int16(); void test_uInt16(); @@ -58,7 +57,6 @@ public: CPPUNIT_TEST(test_Bool); CPPUNIT_TEST(test_Int8); - CPPUNIT_TEST(test_uInt8); CPPUNIT_TEST(test_Int16); CPPUNIT_TEST(test_uInt16); @@ -120,27 +118,6 @@ void FValueTest::test_Int8() CPPUNIT_ASSERT_EQUAL_MESSAGE("sal_Int8 conversion from Any didn't work", trg_salInt8, src_salInt8); } -void FValueTest::test_uInt8() -{ - sal_uInt8 src_saluInt8 = 255; - ORowSetValue v(src_saluInt8); - sal_uInt8 trg_saluInt8 = v.getUInt8(); - - std::cerr << "src_saluInt8: " << static_cast<short>(src_saluInt8) << std::endl; - std::cerr << "trg_saluInt8: " << static_cast<short>(trg_saluInt8) << std::endl; - - CPPUNIT_ASSERT_EQUAL_MESSAGE("sal_uInt8 conversion to ORowSetValue didn't work", trg_saluInt8, src_saluInt8); - - Any any_uInt8 = v.makeAny(); - ORowSetValue t; - t.fill(any_uInt8); - trg_saluInt8 = t.getUInt8(); - - std::cerr << "trg_saluInt8: " << static_cast<short>(trg_saluInt8) << std::endl; - - CPPUNIT_ASSERT_EQUAL_MESSAGE("sal_uInt8 conversion from Any didn't work", trg_saluInt8, src_saluInt8); -} - void FValueTest::test_Int16() { sal_Int16 src_salInt16 = -10001; diff --git a/connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx b/connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx index 3e68e4a1c8e8..3d89a552a2cc 100644 --- a/connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx +++ b/connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx @@ -206,7 +206,7 @@ Reference< css::io::XInputStream > SAL_CALL ODatabaseMetaDataResultSet::getChara sal_Bool SAL_CALL ODatabaseMetaDataResultSet::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException, std::exception) { - return getValue(columnIndex); + return bool(getValue(columnIndex)); } diff --git a/connectivity/source/commontools/FValue.cxx b/connectivity/source/commontools/FValue.cxx index 974363f8b916..71679b253827 100644 --- a/connectivity/source/commontools/FValue.cxx +++ b/connectivity/source/commontools/FValue.cxx @@ -586,20 +586,6 @@ ORowSetValue& ORowSetValue::operator=(sal_Int8 _rRH) return *this; } - -ORowSetValue& ORowSetValue::operator=(sal_uInt8 _rRH) -{ - if(m_eTypeKind != DataType::TINYINT ) - free(); - - m_aValue.m_uInt8 = _rRH; - m_eTypeKind = DataType::TINYINT; - m_bNull = false; - m_bSigned = false; - return *this; -} - - ORowSetValue& ORowSetValue::operator=(sal_Int16 _rRH) { if(m_eTypeKind != DataType::SMALLINT ) diff --git a/connectivity/source/drivers/file/FResultSet.cxx b/connectivity/source/drivers/file/FResultSet.cxx index f50835c30fc3..fe4341152793 100644 --- a/connectivity/source/drivers/file/FResultSet.cxx +++ b/connectivity/source/drivers/file/FResultSet.cxx @@ -232,7 +232,7 @@ Reference< css::io::XInputStream > SAL_CALL OResultSet::getCharacterStream( sal_ sal_Bool SAL_CALL OResultSet::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException, std::exception) { - return getValue(columnIndex); + return bool(getValue(columnIndex)); } diff --git a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx index 1240fae101a8..f774438e6335 100644 --- a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx +++ b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx @@ -1836,7 +1836,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTablePrivileges( aRow[4] = new ORowSetValueDecorator(xRow->getString(2)); // 4. GRANTOR aRow[5] = new ORowSetValueDecorator(xRow->getString(3)); // 5. GRANTEE aRow[6] = new ORowSetValueDecorator(xRow->getString(4)); // 6. Privilege - aRow[7] = new ORowSetValueDecorator(xRow->getBoolean(5)); // 7. Is Grantable + aRow[7] = new ORowSetValueDecorator(bool(xRow->getBoolean(5))); // 7. Is Grantable aResults.push_back(aRow); } diff --git a/connectivity/source/drivers/firebird/ResultSet.cxx b/connectivity/source/drivers/firebird/ResultSet.cxx index 341a3237cc79..7a939402641b 100644 --- a/connectivity/source/drivers/firebird/ResultSet.cxx +++ b/connectivity/source/drivers/firebird/ResultSet.cxx @@ -482,7 +482,7 @@ ORowSetValue OResultSet::retrieveValue(const sal_Int32 nColumnIndex, const ISC_S return getString(nColumnIndex); return getLong(nColumnIndex); case SQL_BOOLEAN: - return ORowSetValue(getBoolean(nColumnIndex)); + return ORowSetValue(bool(getBoolean(nColumnIndex))); case SQL_BLOB: case SQL_NULL: case SQL_QUAD: @@ -645,7 +645,7 @@ sal_Bool SAL_CALL OResultSet::wasNull() throw(SQLException, RuntimeException, st sal_Bool SAL_CALL OResultSet::getBoolean(sal_Int32 nColumnIndex) throw(SQLException, RuntimeException, std::exception) { - return safelyRetrieveValue< sal_Bool >(nColumnIndex, SQL_BOOLEAN); + return safelyRetrieveValue< bool >(nColumnIndex, SQL_BOOLEAN); } sal_Int8 SAL_CALL OResultSet::getByte(sal_Int32 nColumnIndex) diff --git a/connectivity/source/drivers/odbc/OResultSet.cxx b/connectivity/source/drivers/odbc/OResultSet.cxx index 9318d47979b3..e4e8abac9b7c 100644 --- a/connectivity/source/drivers/odbc/OResultSet.cxx +++ b/connectivity/source/drivers/odbc/OResultSet.cxx @@ -458,7 +458,7 @@ template < typename T > T OResultSet::getValue( sal_Int32 columnIndex ) } sal_Bool SAL_CALL OResultSet::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException, std::exception) { - return getValue<sal_Bool>( columnIndex ); + return getValue<bool>( columnIndex ); } sal_Int8 SAL_CALL OResultSet::getByte( sal_Int32 columnIndex ) throw(SQLException, RuntimeException, std::exception) diff --git a/dbaccess/source/core/api/BookmarkSet.cxx b/dbaccess/source/core/api/BookmarkSet.cxx index 57e685b5519e..d37b285d6fe3 100644 --- a/dbaccess/source/core/api/BookmarkSet.cxx +++ b/dbaccess/source/core/api/BookmarkSet.cxx @@ -153,7 +153,7 @@ void OBookmarkSet::updateColumn(sal_Int32 nPos, const Reference< XRowUpdate >& _ break; case DataType::BIT: case DataType::BOOLEAN: - _xParameter->updateBoolean(nPos,_rValue); + _xParameter->updateBoolean(nPos,bool(_rValue)); break; case DataType::TINYINT: if ( _rValue.isSigned() ) diff --git a/dbaccess/source/core/api/PrivateRow.cxx b/dbaccess/source/core/api/PrivateRow.cxx index cf44a2a3d153..c1b69fb4ffdf 100644 --- a/dbaccess/source/core/api/PrivateRow.cxx +++ b/dbaccess/source/core/api/PrivateRow.cxx @@ -42,7 +42,7 @@ sal_Bool SAL_CALL OPrivateRow::wasNull( ) throw (SQLException, RuntimeException sal_Bool SAL_CALL OPrivateRow::getBoolean( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException, std::exception) { m_nPos = columnIndex; - return m_aRow[m_nPos]; + return bool(m_aRow[m_nPos]); } ::sal_Int8 SAL_CALL OPrivateRow::getByte( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException, std::exception) { diff --git a/dbaccess/source/core/api/RowSetBase.cxx b/dbaccess/source/core/api/RowSetBase.cxx index 74a984ac2756..539557243bb0 100644 --- a/dbaccess/source/core/api/RowSetBase.cxx +++ b/dbaccess/source/core/api/RowSetBase.cxx @@ -256,7 +256,7 @@ OUString SAL_CALL ORowSetBase::getString( sal_Int32 columnIndex ) throw(SQLExcep sal_Bool SAL_CALL ORowSetBase::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException, std::exception) { ::osl::MutexGuard aGuard( *m_pMutex ); - return getValue(columnIndex); + return bool(getValue(columnIndex)); } sal_Int8 SAL_CALL ORowSetBase::getByte( sal_Int32 columnIndex ) throw(SQLException, RuntimeException, std::exception) diff --git a/include/connectivity/FValue.hxx b/include/connectivity/FValue.hxx index aeac0c105371..93b7ec28dd7c 100644 --- a/include/connectivity/FValue.hxx +++ b/include/connectivity/FValue.hxx @@ -153,16 +153,6 @@ namespace connectivity operator=(_rRH); } - ORowSetValue(sal_uInt8 _rRH) - :m_eTypeKind(css::sdbc::DataType::TINYINT) - ,m_bNull(true) - ,m_bBound(true) - ,m_bModified(false) - ,m_bSigned(false) - { - m_aValue.m_pString = nullptr; - operator=(_rRH); - } ORowSetValue(sal_Int16 _rRH) :m_eTypeKind(css::sdbc::DataType::SMALLINT) ,m_bNull(true) @@ -234,6 +224,7 @@ namespace connectivity m_aValue.m_pString = nullptr; operator=(_rRH); } + ORowSetValue(sal_Bool) = delete; // aka sal_uInt8 ORowSetValue(const css::util::Date& _rRH) :m_eTypeKind(css::sdbc::DataType::DATE) @@ -301,9 +292,9 @@ namespace connectivity // simple types ORowSetValue& operator=(bool _rRH); + void operator =(sal_Bool) = delete; // aka sal_uInt8 ORowSetValue& operator=(sal_Int8 _rRH); - ORowSetValue& operator=(sal_uInt8 _rRH); ORowSetValue& operator=(sal_Int16 _rRH); ORowSetValue& operator=(sal_uInt16 _rRH); @@ -329,8 +320,8 @@ namespace connectivity ORowSetValue& operator=(const css::uno::Any& _rAny); operator bool() const { return !isNull() && getBool(); } + operator sal_Bool() const = delete; // aka sal_uInt8 operator sal_Int8() const { return isNull() ? static_cast<sal_Int8>(0) : getInt8(); } - operator sal_uInt8() const { return isNull() ? static_cast<sal_uInt8>(0) : getUInt8(); } operator sal_Int16() const { return isNull() ? static_cast<sal_Int16>(0) : getInt16(); } operator sal_uInt16() const { return isNull() ? static_cast<sal_uInt16>(0) : getUInt16(); } |