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