Skip to content

Commit

Permalink
drivers mysql removed memset() to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
silverqx committed Jul 26, 2024
1 parent 9b63cc9 commit d540bd4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,6 @@ namespace Orm::Drivers::MySql
static bool wasAllFieldsFetched(uint fieldsCount, uint lastIndex,
QLatin1StringView method);

/*! Allocate memory for prepared bindings that will be sent to the database. */
static void allocateMemoryForBindings(std::unique_ptr<MYSQL_BIND[]> &binds, // NOLINT(modernize-avoid-c-arrays)
std::size_t count) noexcept;
/*! Reserve all vectors for prepared bindings buffer data. */
void reserveVectorsForBindings(
QList<my_bool> &nullVector, QList<QByteArray> &stringVector,
Expand Down
32 changes: 13 additions & 19 deletions drivers/mysql/src/orm/drivers/mysql/mysqlresult_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ bool MySqlResultPrivate::populateFields(MYSQL *const mysql)

/* Prepared queries */

/* All these modernize-avoid-c-arrays suppressions are correct as we only need to allocate
buffers on the heap, nothing else, we don't need access, modify, iterate over, or
anything else, just simple buffers and C arrays are perfect for this.
The std::array can't be used here as we don't know the size and std::vector is too
much. */

bool MySqlResultPrivate::bindResultValues()
{
// Obtain the Result Set metadata (nothing to do if no metadata)
Expand All @@ -80,8 +86,9 @@ bool MySqlResultPrivate::bindResultValues()
/* Prepared queries don't use metadata the same way as normal queries,
it's always RESULTSET_METADATA_NONE. */

// Allocate memory for result sets that will be obtained from the database
allocateMemoryForBindings(resultBinds, fieldsCount);
/* Allocate memory for result sets that will be obtained from the database,
memset() to 0-s isn't needed, std::make_unique<> 0 initializes it. */
resultBinds = std::make_unique<MYSQL_BIND[]>(fieldsCount); // NOLINT(modernize-avoid-c-arrays)

uint index = 0;
const MYSQL_FIELD *fieldInfo = nullptr;
Expand Down Expand Up @@ -184,9 +191,10 @@ void MySqlResultPrivate::bindPreparedBindings(
{
// Reserve all vectors for prepared bindings buffer data
reserveVectorsForBindings(nullVector, stringVector, timeVector);
// Allocate memory for prepared bindings that will be sent to the database
allocateMemoryForBindings(preparedBinds,
static_cast<std::size_t>(boundValues.size()));
/* Allocate memory for prepared bindings that will be sent to the database,
memset() to 0-s isn't needed, std::make_unique<> 0 initializes it. */
preparedBinds = std::make_unique<MYSQL_BIND[]>( // NOLINT(modernize-avoid-c-arrays)
static_cast<std::size_t>(boundValues.size()));

/*! Alias for bound values size type. */
using BoundValuesSizeType = decltype (boundValues)::size_type;
Expand Down Expand Up @@ -419,20 +427,6 @@ bool MySqlResultPrivate::wasAllFieldsFetched(
return false;
}

/* All these modernize-avoid-c-arrays suppressions are correct as we only need to allocate
buffers on the heap, nothing else, we don't need access, modify, iterate over, or
anything else, just simple buffers and C arrays are perfect for this.
The std::array can't be used here as we don't know the size and std::vector is too
much. */

void MySqlResultPrivate::allocateMemoryForBindings(std::unique_ptr<MYSQL_BIND[]> &binds, // NOLINT(modernize-avoid-c-arrays)
const std::size_t count) noexcept
{
binds = std::make_unique<MYSQL_BIND[]>(count); // NOLINT(modernize-avoid-c-arrays)
// Zero the memory storage
memset(binds.get(), 0, sizeof (MYSQL_BIND) * count);
}

void MySqlResultPrivate::reserveVectorsForBindings(
QList<my_bool> &nullVector, QList<QByteArray> &stringVector,
QList<MYSQL_TIME> &timeVector) const
Expand Down

0 comments on commit d540bd4

Please sign in to comment.