Skip to content

Commit

Permalink
Revert "[#586] Partially fix SC issue "reinterpret_cast should not be…
Browse files Browse the repository at this point in the history
… used""

This reverts commit 8ca2cf3.
And part of commit 7a85da4.
  • Loading branch information
Mi-La committed Aug 2, 2024
1 parent 826ffeb commit fd54e76
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
8 changes: 4 additions & 4 deletions compiler/extensions/cpp/freemarker/SqlTable.cpp.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ ${name}::Row ${name}::Reader::next()
<#else>
const unsigned char* textValue = sqlite3_column_text(m_stmt.get(), ${field?index});
row.${field.setterName}(${field.typeInfo.typeFullName}(
static_cast<const char*>(static_cast<const void*>(textValue)), get_allocator_ref()));
reinterpret_cast<const char*>(textValue), get_allocator_ref()));
</#if>
}
</#list>
Expand Down Expand Up @@ -671,7 +671,7 @@ bool ${name}::validateField${field.name?cap_first}(::zserio::IValidationObserver
<#else>
const unsigned char* textValue = sqlite3_column_text(statement, ${field?index});
row.${field.setterName}(${field.typeInfo.typeFullName}(
static_cast<const char*>(static_cast<const void*>(textValue)), get_allocator_ref()));
reinterpret_cast<const char*>(textValue), get_allocator_ref()));
</#if>

return true;
Expand Down Expand Up @@ -703,13 +703,13 @@ bool ${name}::validateField${field.name?cap_first}(::zserio::IValidationObserver
rowKeyValuesHolder.emplace_back("BLOB");
<#else>
const unsigned char* strValue${field.name?cap_first} = sqlite3_column_text(statement, ${field?index});
rowKeyValuesHolder.emplace_back(static_cast<const char*>(static_cast<const void*>(strValue${field.name?cap_first})));
rowKeyValuesHolder.emplace_back(reinterpret_cast<const char*>(strValue${field.name?cap_first}));
</#if>
</#if>
</#list>
<#else>
const unsigned char* strValueRowId = sqlite3_column_text(statement, ${fields?size});
rowKeyValuesHolder.emplace_back(static_cast<const char*>(static_cast<const void*>(strValueRowId)));
rowKeyValuesHolder.emplace_back(reinterpret_cast<const char*>(strValueRowId));
</#if>

return rowKeyValuesHolder;
Expand Down
11 changes: 11 additions & 0 deletions compiler/extensions/cpp/runtime/ClangTidySuppressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,17 @@ cppcoreguidelines-pro-type-reinterpret-cast:src/zserio/AnyHolder.h:869
cppcoreguidelines-pro-type-reinterpret-cast:src/zserio/AnyHolder.h:876
cppcoreguidelines-pro-type-reinterpret-cast:src/zserio/OptionalHolder.h:658
cppcoreguidelines-pro-type-reinterpret-cast:src/zserio/OptionalHolder.h:668
# This is necessary for implementation of reading and writing of floats to the binary stream.
cppcoreguidelines-pro-type-reinterpret-cast:src/zserio/FloatUtil.cpp:169
cppcoreguidelines-pro-type-reinterpret-cast:src/zserio/FloatUtil.cpp:176
cppcoreguidelines-pro-type-reinterpret-cast:src/zserio/FloatUtil.cpp:183
cppcoreguidelines-pro-type-reinterpret-cast:src/zserio/FloatUtil.cpp:190
# This is necessary for implementation of reading and writing to the file.
cppcoreguidelines-pro-type-reinterpret-cast:src/zserio/FileUtil.cpp:19
cppcoreguidelines-pro-type-reinterpret-cast:src/zserio/FileUtil.cpp:49
# This is necessary for cast the return value from SQLite3 low level API call (sqlite3_column_text).
cppcoreguidelines-pro-type-reinterpret-cast:src/zserio/ValidationSqliteUtil.h:99
cppcoreguidelines-pro-type-reinterpret-cast:src/zserio/ValidationSqliteUtil.h:100

# This multiple inheritance is intended and we think that to avoid it would mean much more obscure design.
fuchsia-multiple-inheritance:src/zserio/Reflectable.h:2023
Expand Down Expand Up @@ -155,6 +163,9 @@ cppcoreguidelines-pro-bounds-pointer-arithmetic:test/zserio/StringViewTest.cpp:9
cppcoreguidelines-pro-bounds-pointer-arithmetic:test/zserio/StringViewTest.cpp:156
cppcoreguidelines-pro-bounds-pointer-arithmetic:test/zserio/StringViewTest.cpp:209

# Intentional tests.
cppcoreguidelines-pro-type-reinterpret-cast:test/zserio/SqliteConnectionTest.cpp:320

# Intentional tests. It is necessary for readability.
google-build-using-namespace:test/zserio/ReflectableTest.cpp:22

Expand Down
8 changes: 4 additions & 4 deletions compiler/extensions/cpp/runtime/src/zserio/FloatUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,28 +166,28 @@ uint16_t convertFloatToUInt16(float float32)

float convertUInt32ToFloat(uint32_t float32Value)
{
const float* convertedFloat = static_cast<const float*>(static_cast<void*>(&float32Value));
const float* convertedFloat = reinterpret_cast<const float*>(&float32Value);

return *convertedFloat;
}

uint32_t convertFloatToUInt32(float float32)
{
const uint32_t* float32ValuePtr = static_cast<const uint32_t*>(static_cast<void*>(&float32));
const uint32_t* float32ValuePtr = reinterpret_cast<const uint32_t*>(&float32);

return *float32ValuePtr;
}

double convertUInt64ToDouble(uint64_t float64Value)
{
const double* convertedDouble = static_cast<const double*>(static_cast<void*>(&float64Value));
const double* convertedDouble = reinterpret_cast<const double*>(&float64Value);

return *convertedDouble;
}

uint64_t convertDoubleToUInt64(double float64)
{
const uint64_t* float64ValuePtr = static_cast<const uint64_t*>(static_cast<void*>(&float64));
const uint64_t* float64ValuePtr = reinterpret_cast<const uint64_t*>(&float64);

return *float64ValuePtr;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,8 @@ struct ValidationSqliteUtil
int result = SQLITE_OK;
while ((result = sqlite3_step(statement.get())) == SQLITE_ROW)
{
const unsigned char* columnNameText = sqlite3_column_text(statement.get(), 1);
const char* columnName = static_cast<const char*>(static_cast<const void*>(columnNameText));
const unsigned char* columnTypeText = sqlite3_column_text(statement.get(), 2);
const char* columnType = static_cast<const char*>(static_cast<const void*>(columnTypeText));
const char* columnName = reinterpret_cast<const char*>(sqlite3_column_text(statement.get(), 1));
const char* columnType = reinterpret_cast<const char*>(sqlite3_column_text(statement.get(), 2));
tableSchema.emplace(string_type(columnName, allocator),
ColumnDescription{
string_type(columnName, allocator), string_type(columnType, allocator),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,7 @@ TEST(SqliteConnectionTest, prepareStatement)
ASSERT_EQ(SQLITE_ROW, result);

ASSERT_EQ(1, sqlite3_column_count(statement));
const unsigned char* textValue = sqlite3_column_text(statement, 0);
const std::string resultString(static_cast<const char*>(static_cast<const void*>(textValue)));
const std::string resultString(reinterpret_cast<const char*>(sqlite3_column_text(statement, 0)));
ASSERT_EQ("1", resultString);

result = sqlite3_step(statement);
Expand Down

0 comments on commit fd54e76

Please sign in to comment.