Skip to content

Commit 752f336

Browse files
committed
suppressing false warnings
1 parent 695719d commit 752f336

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

mssql_python/pybind/ddbc_bindings.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2403,7 +2403,9 @@ static py::object FetchLobColumnData(SQLHSTMT hStmt,
24032403
// Wide characters
24042404
size_t wcharSize = sizeof(SQLWCHAR);
24052405
if (bytesRead >= wcharSize) {
2406-
auto sqlwBuf = reinterpret_cast<const SQLWCHAR*>(chunk.data());
2406+
auto sqlwBuf = reinterpret_cast<const SQLWCHAR*>(chunk.data()); // CodeQL [SM02986] This cast is safe because 1. std::vector guarantees proper alignment for its allocations
2407+
// 2. SQLGetData writes complete SQLWCHAR units to the buffer
2408+
// 3. bytesRead is controlled by the ODBC driver to be SQLWCHAR-aligned
24072409
size_t wcharCount = bytesRead / wcharSize;
24082410
while (wcharCount > 0 && sqlwBuf[wcharCount - 1] == 0) {
24092411
--wcharCount;
@@ -2434,13 +2436,17 @@ static py::object FetchLobColumnData(SQLHSTMT hStmt,
24342436
}
24352437
if (isWideChar) {
24362438
#if defined(_WIN32)
2437-
std::wstring wstr(reinterpret_cast<const wchar_t*>(buffer.data()), buffer.size() / sizeof(wchar_t));
2439+
std::wstring wstr(reinterpret_cast<const wchar_t*>(buffer.data()), buffer.size() / sizeof(wchar_t)); // CodeQL [SM02986] This cast is safe because 1. std::vector guarantees proper alignment for its allocations
2440+
// 2. SQLGetData writes complete SQLWCHAR units to the buffer
2441+
// 3. bytesRead is controlled by the ODBC driver to be SQLWCHAR-aligned
24382442
std::string utf8str = WideToUTF8(wstr);
24392443
return py::str(utf8str);
24402444
#else
24412445
// Linux/macOS handling
24422446
size_t wcharCount = buffer.size() / sizeof(SQLWCHAR);
2443-
const SQLWCHAR* sqlwBuf = reinterpret_cast<const SQLWCHAR*>(buffer.data());
2447+
const SQLWCHAR* sqlwBuf = reinterpret_cast<const SQLWCHAR*>(buffer.data()); // CodeQL [SM02986] This cast is safe because 1. std::vector guarantees proper alignment for its allocations
2448+
// 2. SQLGetData writes complete SQLWCHAR units to the buffer
2449+
// 3. bytesRead is controlled by the ODBC driver to be SQLWCHAR-aligned
24442450
std::wstring wstr = SQLWCHARToWString(sqlwBuf, wcharCount);
24452451
std::string utf8str = WideToUTF8(wstr);
24462452
return py::str(utf8str);

0 commit comments

Comments
 (0)