Invalid cast when setting parameter index in MimerGet/SetXXX

Change the invalid static_cast<std::int16_t>(i)+1
to the correct static_cast<std::int16_t>(i+1).

Change-Id: I5d3e17d29deb2a70fa0d7d7838531a3dc80b4e45
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
This commit is contained in:
Fredrik Ålund 2024-03-27 10:41:12 +01:00
parent ad84754b58
commit 9a92e26dcd

View File

@ -607,7 +607,7 @@ QVariant QMimerSQLResult::data(int i)
genericError, QSqlError::StatementError, nullptr));
return QVariant();
}
mType = MimerParameterType(d->statementhandle, static_cast<std::int16_t>(i) + 1);
mType = MimerParameterType(d->statementhandle, static_cast<std::int16_t>(i + 1));
} else {
if (i >= MimerColumnCount(d->statementhandle)) {
setLastError(qMakeError(
@ -616,18 +616,18 @@ QVariant QMimerSQLResult::data(int i)
genericError, QSqlError::StatementError, nullptr));
return QVariant();
}
mType = MimerColumnType(d->statementhandle, static_cast<std::int16_t>(i) + 1);
mType = MimerColumnType(d->statementhandle, static_cast<std::int16_t>(i + 1));
}
const QMetaType::Type type = qDecodeMSQLType(mType);
const MimerColumnTypes mimDataType = mimerMapColumnTypes(mType);
err = MimerIsNull(d->statementhandle, static_cast<std::int16_t>(i) + 1);
err = MimerIsNull(d->statementhandle, static_cast<std::int16_t>(i + 1));
if (err > 0) {
return QVariant(QMetaType(type), nullptr);
} else {
switch (mimDataType) {
case MimerColumnTypes::Date: {
wchar_t dateString_w[maxDateStringSize + 1];
err = MimerGetString(d->statementhandle, static_cast<std::int16_t>(i) + 1, dateString_w,
err = MimerGetString(d->statementhandle, static_cast<std::int16_t>(i + 1), dateString_w,
sizeof(dateString_w) / sizeof(dateString_w[0]));
if (!MIMER_SUCCEEDED(err)) {
setLastError(qMakeError(msgCouldNotGet("date", i),
@ -638,7 +638,7 @@ QVariant QMimerSQLResult::data(int i)
}
case MimerColumnTypes::Time: {
wchar_t timeString_w[maxTimeStringSize + 1];
err = MimerGetString(d->statementhandle, static_cast<std::int16_t>(i) + 1, timeString_w,
err = MimerGetString(d->statementhandle, static_cast<std::int16_t>(i + 1), timeString_w,
sizeof(timeString_w) / sizeof(timeString_w[0]));
if (!MIMER_SUCCEEDED(err)) {
setLastError(qMakeError(msgCouldNotGet("time", i),
@ -655,7 +655,7 @@ QVariant QMimerSQLResult::data(int i)
}
case MimerColumnTypes::Timestamp: {
wchar_t dateTimeString_w[maxTimestampStringSize + 1];
err = MimerGetString(d->statementhandle, static_cast<std::int16_t>(i) + 1,
err = MimerGetString(d->statementhandle, static_cast<std::int16_t>(i + 1),
dateTimeString_w,
sizeof(dateTimeString_w) / sizeof(dateTimeString_w[0]));
if (!MIMER_SUCCEEDED(err)) {
@ -674,7 +674,7 @@ QVariant QMimerSQLResult::data(int i)
}
case MimerColumnTypes::Int: {
int resInt;
err = MimerGetInt32(d->statementhandle, static_cast<std::int16_t>(i) + 1, &resInt);
err = MimerGetInt32(d->statementhandle, static_cast<std::int16_t>(i + 1), &resInt);
if (!MIMER_SUCCEEDED(err)) {
setLastError(qMakeError(msgCouldNotGet("int32", i),
err, QSqlError::StatementError, d->drv_d_func()));
@ -684,7 +684,7 @@ QVariant QMimerSQLResult::data(int i)
}
case MimerColumnTypes::Long: {
int64_t resLongLong;
err = MimerGetInt64(d->statementhandle, static_cast<std::int16_t>(i) + 1, &resLongLong);
err = MimerGetInt64(d->statementhandle, static_cast<std::int16_t>(i + 1), &resLongLong);
if (!MIMER_SUCCEEDED(err)) {
setLastError(qMakeError(msgCouldNotGet("int64", i),
err, QSqlError::StatementError, d->drv_d_func()));
@ -693,7 +693,7 @@ QVariant QMimerSQLResult::data(int i)
return (qlonglong)resLongLong;
}
case MimerColumnTypes::Boolean: {
err = MimerGetBoolean(d->statementhandle, static_cast<std::int16_t>(i) + 1);
err = MimerGetBoolean(d->statementhandle, static_cast<std::int16_t>(i + 1));
if (!MIMER_SUCCEEDED(err)) {
setLastError(
qMakeError(msgCouldNotGet("boolean", i),
@ -704,7 +704,7 @@ QVariant QMimerSQLResult::data(int i)
}
case MimerColumnTypes::Float: {
float resFloat;
err = MimerGetFloat(d->statementhandle, static_cast<std::int16_t>(i) + 1, &resFloat);
err = MimerGetFloat(d->statementhandle, static_cast<std::int16_t>(i + 1), &resFloat);
if (!MIMER_SUCCEEDED(err)) {
setLastError(qMakeError(msgCouldNotGet("float", i),
err, QSqlError::StatementError, d->drv_d_func()));
@ -714,7 +714,7 @@ QVariant QMimerSQLResult::data(int i)
}
case MimerColumnTypes::Double: {
double resDouble;
err = MimerGetDouble(d->statementhandle, static_cast<std::int16_t>(i) + 1, &resDouble);
err = MimerGetDouble(d->statementhandle, static_cast<std::int16_t>(i + 1), &resDouble);
if (!MIMER_SUCCEEDED(err)) {
setLastError(
qMakeError(msgCouldNotGet("double", i),
@ -736,10 +736,10 @@ QVariant QMimerSQLResult::data(int i)
case MimerColumnTypes::Binary: {
QByteArray byteArray;
// Get size
err = MimerGetBinary(d->statementhandle, static_cast<std::int16_t>(i) + 1, NULL, 0);
err = MimerGetBinary(d->statementhandle, static_cast<std::int16_t>(i + 1), NULL, 0);
if (MIMER_SUCCEEDED(err)) {
byteArray.resize(err);
err = MimerGetBinary(d->statementhandle, static_cast<std::int16_t>(i) + 1,
err = MimerGetBinary(d->statementhandle, static_cast<std::int16_t>(i + 1),
byteArray.data(), err);
}
if (!MIMER_SUCCEEDED(err)) {
@ -753,7 +753,7 @@ QVariant QMimerSQLResult::data(int i)
case MimerColumnTypes::Blob: {
QByteArray byteArray;
size_t size;
err = MimerGetLob(d->statementhandle, static_cast<std::int16_t>(i) + 1, &size,
err = MimerGetLob(d->statementhandle, static_cast<std::int16_t>(i + 1), &size,
&d->lobhandle);
if (MIMER_SUCCEEDED(err)) {
constexpr size_t maxSize = lobChunkMaxSizeFetch;
@ -783,19 +783,19 @@ QVariant QMimerSQLResult::data(int i)
case MimerColumnTypes::String: {
wchar_t resString_w[maxStackStringSize + 1];
// Get size
err = MimerGetString(d->statementhandle, static_cast<std::int16_t>(i) + 1, resString_w,
err = MimerGetString(d->statementhandle, static_cast<std::int16_t>(i + 1), resString_w,
0);
if (MIMER_SUCCEEDED(err)) {
int size = err;
if (err <= maxStackStringSize) { // For smaller strings, use a small buffer for
// efficiency
err = MimerGetString(d->statementhandle, static_cast<std::int16_t>(i) + 1,
err = MimerGetString(d->statementhandle, static_cast<std::int16_t>(i + 1),
resString_w, maxStackStringSize + 1);
if (MIMER_SUCCEEDED(err))
return QString::fromWCharArray(resString_w);
} else { // For larger strings, dynamically allocate memory
QVarLengthArray<wchar_t> largeResString_w(size + 1);
err = MimerGetString(d->statementhandle, static_cast<std::int16_t>(i) + 1,
err = MimerGetString(d->statementhandle, static_cast<std::int16_t>(i + 1),
largeResString_w.data(), size + 1);
if (MIMER_SUCCEEDED(err))
return QString::fromWCharArray(largeResString_w.data());
@ -808,7 +808,7 @@ QVariant QMimerSQLResult::data(int i)
}
case MimerColumnTypes::Clob: {
size_t size;
err = MimerGetLob(d->statementhandle, static_cast<std::int16_t>(i) + 1, &size,
err = MimerGetLob(d->statementhandle, static_cast<std::int16_t>(i + 1), &size,
&d->lobhandle);
if (MIMER_SUCCEEDED(err)) {
constexpr size_t maxSize = lobChunkMaxSizeFetch;
@ -836,7 +836,7 @@ QVariant QMimerSQLResult::data(int i)
}
case MimerColumnTypes::Uuid: {
unsigned char uuidChar[16];
err = MimerGetUUID(d->statementhandle, static_cast<std::int16_t>(i) + 1, uuidChar);
err = MimerGetUUID(d->statementhandle, static_cast<std::int16_t>(i + 1), uuidChar);
if (!MIMER_SUCCEEDED(err)) {
setLastError(qMakeError(msgCouldNotGet("UUID", i),
err, QSqlError::StatementError, d->drv_d_func()));
@ -858,7 +858,7 @@ QVariant QMimerSQLResult::data(int i)
bool QMimerSQLResult::isNull(int index)
{
Q_D(const QMimerSQLResult);
const int32_t rc = MimerIsNull(d->statementhandle, static_cast<std::int16_t>(index) + 1);
const int32_t rc = MimerIsNull(d->statementhandle, static_cast<std::int16_t>(index + 1));
if (!MIMER_SUCCEEDED(rc)) {
setLastError(qMakeError(
QCoreApplication::translate("QMimerSQLResult", "Could not check null, column %1")
@ -911,10 +911,10 @@ QSqlRecord QMimerSQLResult::record() const
const int colSize = MimerColumnCount(d->statementhandle);
for (int i = 0; i < colSize; i++) {
wchar_t colName_w[100];
MimerColumnName(d->statementhandle, static_cast<std::int16_t>(i) + 1, colName_w,
MimerColumnName(d->statementhandle, static_cast<std::int16_t>(i + 1), colName_w,
sizeof(colName_w) / sizeof(colName_w[0]));
field.setName(QString::fromWCharArray(colName_w));
const int32_t mType = MimerColumnType(d->statementhandle, static_cast<std::int16_t>(i) + 1);
const int32_t mType = MimerColumnType(d->statementhandle, static_cast<std::int16_t>(i + 1));
const QMetaType::Type type = qDecodeMSQLType(mType);
field.setMetaType(QMetaType(type));
field.setValue(QVariant(field.metaType()));