Skip to content

Commit

Permalink
ASAN fix
Browse files Browse the repository at this point in the history
Signed-off-by: Eugenio Collado <eugeniocollado@eprosima.com>
  • Loading branch information
EugenioCollado committed Jan 3, 2025
1 parent 85807da commit c285f07
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
51 changes: 27 additions & 24 deletions ddsrecorder/test/blackbox/sql/SqlFileCreationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,39 +91,42 @@ class SqlFileCreationTest : public FileCreationTest
throw std::runtime_error(error_msg);
}

// Guard the statement to ensure it's always finalized
std::unique_ptr<sqlite3_stmt, decltype(&sqlite3_finalize)> stmt_guard(stmt, sqlite3_finalize);

// Bind the values to the statement
for (int i = 0; i < (int) bind_values.size(); i++)
{
const auto bind_ret = sqlite3_bind_text(stmt, i+1, bind_values[i].c_str(), -1, SQLITE_STATIC);

if (bind_ret != SQLITE_OK)
// Guard the statement to ensure it's always finalized
std::unique_ptr<sqlite3_stmt, decltype(&sqlite3_finalize)> stmt_guard(stmt, sqlite3_finalize);

// Bind the values to the statement
for (int i = 0; i < (int) bind_values.size(); i++)
{
const std::string error_msg = utils::Formatter() << "Failed to bind SQL statement to read messages: "
<< sqlite3_errmsg(database);
const auto bind_ret = sqlite3_bind_text(stmt, i+1, bind_values[i].c_str(), -1, SQLITE_STATIC);

logError(DDSREPLAYER_SQL_READER_PARTICIPANT, "FAIL_SQL_READ | " << error_msg);
throw std::runtime_error(error_msg);
if (bind_ret != SQLITE_OK)
{
const std::string error_msg = utils::Formatter() << "Failed to bind SQL statement to read messages: "
<< sqlite3_errmsg(database);

logError(DDSREPLAYER_SQL_READER_PARTICIPANT, "FAIL_SQL_READ | " << error_msg);
throw std::runtime_error(error_msg);
}
}
}

// Step through the statement and process the rows
int step_ret;
// Step through the statement and process the rows
int step_ret;

while ((step_ret = sqlite3_step(stmt)) == SQLITE_ROW)
{
process_row(stmt);
}
while ((step_ret = sqlite3_step(stmt)) == SQLITE_ROW)
{
process_row(stmt);
}

if (step_ret != SQLITE_DONE)
{
const std::string error_msg = utils::Formatter() << "Failed to fetch data: "
<< sqlite3_errmsg(database);
if (step_ret != SQLITE_DONE)
{
const std::string error_msg = utils::Formatter() << "Failed to fetch data: "
<< sqlite3_errmsg(database);

logError(DDSREPLAYER_SQL_READER_PARTICIPANT, "FAIL_SQL_READ | " << error_msg);
throw std::runtime_error(error_msg);
logError(DDSREPLAYER_SQL_READER_PARTICIPANT, "FAIL_SQL_READ | " << error_msg);
throw std::runtime_error(error_msg);
}
}

// Close the database
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ std::unique_ptr<ddspipe::core::types::RtpsPayloadData> BaseReaderParticipant::cr
auto data = std::make_unique<ddspipe::core::types::RtpsPayloadData>();

// Store the raw data in a payload
ddspipe::core::types::Payload payload(raw_data_size);
ddspipe::core::types::Payload payload;
payload.max_size = raw_data_size;
payload.length = raw_data_size;
payload.data = (unsigned char*) reinterpret_cast<const unsigned char*>(raw_data);
Expand Down

0 comments on commit c285f07

Please sign in to comment.