Skip to content

Fix unsafe pointer arithmetic/unsigned wrapping - #121

Merged
ayzk merged 1 commit into
masterfrom
fix-unsafe-pointer-arithmetic
Dec 8, 2025
Merged

ayzk merged 1 commit into
masterfrom
fix-unsafe-pointer-arithmetic

Conversation

@ayzk

@ayzk ayzk commented Dec 8, 2025

Copy link
Copy Markdown
Collaborator

Fix unsafe pointer arithmetic/unsigned wrapping in Lorenzo predictor. (#119)

Copilot AI review requested due to automatic review settings December 8, 2025 15:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes unsafe pointer arithmetic and unsigned wrapping issues in the Lorenzo predictor by transforming negative pointer subscript notation to explicit pointer arithmetic with proper parenthesization.

Key Changes:

  • Converted negative subscript notation (ptr[-expr]) to explicit pointer arithmetic with dereference (*(ptr - (expr)))
  • Added parentheses around addition operations to prevent intermediate unsigned wrapping
  • Applied fix consistently across all Lorenzo predictor helper functions

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
include/SZ3/utils/QuantOptimization.hpp Updated lorenzo_predict_3d function to use explicit pointer arithmetic with proper parenthesization for all 7 pointer offset calculations
include/SZ3/predictor/LorenzoPredictor.hpp Updated helper functions prev1, prev2, prev3, and prev4 to use explicit pointer arithmetic with proper parenthesization for safe pointer offset calculations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@juntyr

juntyr commented Dec 8, 2025

Copy link
Copy Markdown
Contributor

@ayzk This PR also fixes #119, so you can go ahead with this one.

@ayzk
ayzk merged commit c9a428b into master Dec 8, 2025
@ayzk
ayzk deleted the fix-unsafe-pointer-arithmetic branch December 8, 2025 15:36
@ayzk ayzk mentioned this pull request Dec 8, 2025
ayzk added a commit that referenced this pull request Apr 26, 2026
Brings in upstream changes that don't touch docs/:

  * HDF5 target export improvements (#125, #126, #128)
    - SZ3::hdf5sz3 target now exposed in build + export trees
    - Cleanups in tools/H5Z-SZ3, mdz, sz3c CMakeLists
  * NixOS support: new default.nix (#129)
  * Lorenzo predictor pointer-arith UB fix (#121)
    - LorenzoPredictor.hpp + QuantOptimization.hpp:
      d[-i] -> *(d - i) to avoid size_t unsigned wrap-around

.gitignore: union merge (master adds sz3_install / sz3_build / test;
fz keeps tmp / .cache / docs/site/html / .claude).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants