drivers bugfix index bounds check

This commit is contained in:
silverqx
2024-03-27 11:16:07 +01:00
parent ad1db88f01
commit 4638db2cac
3 changed files with 9 additions and 9 deletions

View File

@@ -89,7 +89,7 @@ namespace Orm::Drivers::MySql
QVariant getValueForPrepared(ResultFieldsSizeType index) const;
/*! Throw an exception if an index for result fields vector is out of bounds. */
void throwIfBadResultFieldsIndex(ResultFieldsSizeType index) const;
void throwIfBadResultFieldsIndex(size_type index) const;
/* Data members */
/* Common for both */

View File

@@ -419,10 +419,10 @@ QVariant MySqlResult::data(const size_type index) const
{
Q_D(const MySqlResult);
const auto idx = static_cast<MySqlResultPrivate::ResultFieldsSizeType>(index);
// Throw an exception if an index for result fields vector is out of bounds
d->throwIfBadResultFieldsIndex(idx);
d->throwIfBadResultFieldsIndex(index);
const auto idx = static_cast<MySqlResultPrivate::ResultFieldsSizeType>(index);
if (d->preparedQuery)
return d->getValueForPrepared(idx);
@@ -434,10 +434,10 @@ bool MySqlResult::isNull(const size_type index) const
{
Q_D(const MySqlResult);
const auto idx = static_cast<MySqlResultPrivate::ResultFieldsSizeType>(index);
// Throw an exception if an index for result fields vector is out of bounds
d->throwIfBadResultFieldsIndex(idx);
d->throwIfBadResultFieldsIndex(index);
const auto idx = static_cast<MySqlResultPrivate::ResultFieldsSizeType>(index);
/* MyField::isNull is populated for prepared statements only.
The row/result set/data must be fetched first to obtain the correct result. ❗ */

View File

@@ -368,12 +368,12 @@ QVariant MySqlResultPrivate::getValueForPrepared(const ResultFieldsSizeType inde
}
void
MySqlResultPrivate::throwIfBadResultFieldsIndex(const ResultFieldsSizeType index) const
MySqlResultPrivate::throwIfBadResultFieldsIndex(const size_type index) const
{
const auto fieldsCount = resultFields.size();
// Nothing to do
if (index >= 0 || index < fieldsCount)
if (index >= 0 || index < static_cast<size_type>(fieldsCount))
return;
throw Exceptions::OutOfRangeError(