atharva-potdar opened a new pull request, #55439:
URL: https://github.com/apache/arrow/pull/55439

   ### Rationale for this change
   
   Currently, the slicing constructors for `Buffer` (`src/arrow/buffer.h`) and 
`MutableBuffer` (`src/arrow/buffer.cc`) unconditionally add `offset` to the 
parent buffer's pointer/address. When slicing a null or empty buffer where 
`parent->data_` is `nullptr` or `parent->mutable_address()` is `0`, this 
results in pointer arithmetic on a null pointer, triggering 
`clang-analyzer-core.NullPointerArithm` in `clang-tidy`:
   
       src/arrow/buffer.cc:167:75: warning: Addition of a null pointer and a 
nonzero integer value (from variable 'offset') results in undefined behavior 
[clang-analyzer-core.NullPointerArithm]
   
   ### What changes are included in this PR?
   
   * Guard `Buffer`'s slice constructor in `src/arrow/buffer.h` against null 
`parent->data_` before adding `offset`.
   * Guard `MutableBuffer`'s slice constructor in `src/arrow/buffer.cc` using 
`parent->mutable_address()` (preserving non-CPU device compatibility from 
ARROW-2447) and performing integer addition before casting when non-zero.
   * Add `TestBuffer.SliceNullBuffer` in `src/arrow/buffer_test.cc`.
   
   ### Are these changes tested?
   
   Yes, added `TestBuffer.SliceNullBuffer` in `arrow-buffer-test` and verified 
that `clang-tidy` no longer emits `clang-analyzer-core.NullPointerArithm`.
   
   ### Are there any user-facing changes?
   
   No.
   
   ### Was AI used for this PR?
   
   In accordance to the [AI generation 
guidelines](https://arrow.apache.org/docs/dev/developers/overview.html#ai-generated-code),
 please disclose below whether and how AI was used in this PR.
   
   **PR code written by:**
   
   - [x] Human
   - [ ] AI
   
   **PR description written by:**
   
   - [ ] Human
   - [x] AI
   
   I asked Gemini 4 Argon to write a PR description after I wrote the test, the 
code, and pasted the clang-tidy and google test logs to it.
   
   **Reviewed before submission by:**
   
   - [x] Human
   - [ ] AI
   - [ ] Not reviewed


-- 
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