QSQL/ODBC: fix regression (trailing NUL)

When we fixed the callers of toSQLTCHAR() to use the result's size()
instead of the input's (which differ, if sizeof(SQLTCHAR) != 2), we
exposed callers to the append(0), which changes the size() of the
result QVLA. Callers that don't rely on NUL-termination (all?) now saw
an additional training NUL.

Fix by not NUL-terminating, and changing the only user of SQL_NTS to
use an explicit length.

Amends 4c445ef0ba and
46af1fe49f.

Done-with: Christian Ehrlicher <ch.ehrlicher@gmx.de>
Pick-to: 6.5 6.5.0 6.4 6.2 5.15
Change-Id: I6210b77e9417f46294df94cb32ab4134af8dc4c2
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
bb10
Marc Mutz 2023-03-20 12:33:02 +01:00
parent 29b55dcb83
commit 9020034b3b
1 changed files with 2 additions and 2 deletions

View File

@ -80,7 +80,6 @@ inline static QVarLengthArray<SQLTCHAR> toSQLTCHAR(const QString &input)
result.resize(enc.requiredSpace(input.size()));
const auto end = enc.appendToBuffer(reinterpret_cast<char *>(result.data()), input);
result.resize((end - reinterpret_cast<char *>(result.data())) / sizeof(SQLTCHAR));
result.append(0); // make sure it's null terminated, doesn't matter if it already is, it does if it isn't.
return result;
}
@ -2058,7 +2057,8 @@ void QODBCDriverPrivate::checkUnicode()
"select 'test' from dual"_L1,
};
for (const auto &statement : statements) {
r = SQLExecDirect(hStmt, toSQLTCHAR(statement).data(), SQL_NTS);
auto encoded = toSQLTCHAR(statement);
r = SQLExecDirect(hStmt, encoded.data(), SQLINTEGER(encoded.size()));
if (r == SQL_SUCCESS)
break;
}