Kaydet (Commit) 385f6240 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

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
7b0c57b2 "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/31909Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst 8845ccc1
......@@ -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
......
......@@ -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;
......
......@@ -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));
}
......
......@@ -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 )
......
......@@ -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));
}
......
......@@ -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);
}
......
......@@ -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)
......
......@@ -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)
......
......@@ -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() )
......
......@@ -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)
{
......
......@@ -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)
......
......@@ -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(); }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment