Skip to content

Commit

Permalink
Fix sonar issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mikir committed May 29, 2024
1 parent 37a70ed commit e36c7af
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
9 changes: 7 additions & 2 deletions compiler/extensions/cpp/freemarker/SqlDatabase.cpp.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ ${name}::${name}(const ${types.string.name}& dbFileName, const TRelocationMap& t
m_db.reset(internalConnection, ::zserio::SqliteConnection::INTERNAL_CONNECTION);
if (result != SQLITE_OK)
{
throw ::zserio::SqliteException("${name}::open(): can't open DB ") << dbFileName.c_str() << ": " <<
throw ::zserio::SqliteException("${name}::${name}: can't open DB ") << dbFileName.c_str() << ": " <<
::zserio::SqliteErrorCode(result);
}

Expand All @@ -50,9 +50,14 @@ ${name}::${name}(const ${types.string.name}& dbFileName, const TRelocationMap& t
attachDatabase(fileName, attachedDbName);
attachedDbIt = dbFileNameToAttachedDbNameMap.emplace(fileName, ::std::move(attachedDbName)).first;
}
m_tableToAttachedDbNameRelocationMap.emplace(
auto result2 = m_tableToAttachedDbNameRelocationMap.emplace(
${types.string.name}(tableName, get_allocator_ref()),
${types.string.name}(attachedDbIt->second, get_allocator_ref()));
if (!result2.second)
{
throw ::zserio::SqliteException("${name}::${name}: can't insert ") << tableName.c_str() <<
" into Database Relocation Map!";
}
}

initTables();
Expand Down
8 changes: 7 additions & 1 deletion compiler/extensions/cpp/freemarker/SqlTable.cpp.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,13 @@ void ${name}::write(<#if needsParameterProvider>IParameterProvider& parameterPro
::zserio::SqliteErrorCode(result);
}

sqlite3_clear_bindings(statement.get());
result = sqlite3_clear_bindings(statement.get());
if (result != SQLITE_OK)
{
throw ::zserio::SqliteException("Write: sqlite3_clear_bindings() failed: ") <<
::zserio::SqliteErrorCode(result);
}

result = sqlite3_reset(statement.get());
if (result != SQLITE_OK)
{
Expand Down
2 changes: 1 addition & 1 deletion compiler/extensions/cpp/runtime/ClangTidySuppressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ 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 to the file.
cppcoreguidelines-pro-type-reinterpret-cast:src/zserio/FileUtil.cpp:19
cppcoreguidelines-pro-type-reinterpret-cast:src/zserio/FileUtil.cpp:50
cppcoreguidelines-pro-type-reinterpret-cast:src/zserio/FileUtil.cpp:49

# 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
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ void BitStreamReader::setBitPosition(BitPosType position)
const uint8_t skip = static_cast<uint8_t>(position - m_context.bitIndex);
if (skip != 0)
{
readBits(skip);
(void)readBits(skip);
}
}

Expand All @@ -861,7 +861,7 @@ void BitStreamReader::alignTo(size_t alignment)
if (offset != 0)
{
const uint8_t skip = static_cast<uint8_t>(alignment - offset);
readBits64(skip);
(void)readBits64(skip);
}
}

Expand Down
8 changes: 3 additions & 5 deletions compiler/extensions/cpp/runtime/src/zserio/FileUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ void writeBufferToFile(const uint8_t* buffer, size_t bitSize, BitsTag, const std
}

const size_t byteSize = (bitSize + 7) / 8;
stream.write(reinterpret_cast<const char*>(buffer), static_cast<std::streamsize>(byteSize));
if (!stream)
if (!stream.write(reinterpret_cast<const char*>(buffer), static_cast<std::streamsize>(byteSize)))
{
throw CppRuntimeException("writeBufferToFile: Failed to write '") << fileName << "'!";
}
Expand Down Expand Up @@ -47,9 +46,8 @@ BitBuffer readBufferFromFile(const std::string& fileName)
}

zserio::BitBuffer bitBuffer(static_cast<size_t>(fileSize) * 8);
stream.read(reinterpret_cast<char*>(bitBuffer.getBuffer()),
static_cast<std::streamsize>(bitBuffer.getByteSize()));
if (!stream)
if (!stream.read(reinterpret_cast<char*>(bitBuffer.getBuffer()),
static_cast<std::streamsize>(bitBuffer.getByteSize())))
{
throw CppRuntimeException("readBufferFromFile: Failed to read '") << fileName << "'!";
}
Expand Down

0 comments on commit e36c7af

Please sign in to comment.