Copilot commented on code in PR #50757:
URL: https://github.com/apache/arrow/pull/50757#discussion_r3701673221


##########
cpp/src/arrow/flight/sql/odbc/odbc_api.cc:
##########
@@ -642,7 +641,7 @@ SQLRETURN SQLGetDiagRec(SQLSMALLINT handle_type, SQLHANDLE 
handle, SQLSMALLINT r
   }
 
   // Convert from ODBC 1 based record number to internal diagnostics 0 indexed 
storage
-  const size_t record_index = static_cast<size_t>(rec_number - 1);
+  const auto record_index = static_cast<uint32_t>(rec_number - 1);
   if (!diagnostics->HasRecord(record_index)) {
     return SQL_NO_DATA;

Review Comment:
   `SQLGetDiagRec` converts `rec_number` (ODBC 1-based) to a 0-based 
`record_index` without validating `rec_number >= 1`. If the caller passes 0 (or 
a negative value), `rec_number - 1` underflows and is cast to `uint32_t`, 
causing the function to return `SQL_NO_DATA` instead of an error. 
`SQLGetDiagField` already has a guard for this case; this should be consistent.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to