Skip to content

Compute container sizes in size_t - #12

Merged
sobolevnrm merged 1 commit into
masterfrom
fix/size-multiplication-overflow
Oct 25, 2026
Merged

sobolevnrm merged 1 commit into
masterfrom
fix/size-multiplication-overflow

Conversation

@sobolevnrm

Copy link
Copy Markdown
Member

Resolves the 5 open CodeQL cpp/integer-multiplication-cast-to-long alerts.

reserve/resize sizes were multiplied in int before being widened to size_t:

  • pbam/src/PhysCalcAM.cpp: dimer_.reserve(N_*N_) and trimer_.reserve(N_*N_*N_).
    The trimer size overflows int at about 1,300 molecules, so reserve throws std::length_error instead of succeeding.
  • pbsam/src/TMatrix.cpp: T_.reserve(total_spheres*total_spheres).
  • pb_shared/src/readutil.h: p*p*p*p and p*p (multipole order; included for consistency).

Each product is now computed in size_t. No behavior change for inputs that did not overflow.

Validation

macOS (Apple BLAS, PBAM + PBSAM, testing on, -DCMAKE_POLICY_VERSION_MINIMUM=3.5 per #11): builds cleanly; pbamtest 160 passed, pbsamtest 102 passed.

Products such as N_*N_*N_ were evaluated in int before widening, which
overflows at about 1,300 molecules for trimer_.reserve.

Resolves CodeQL cpp/integer-multiplication-cast-to-long alerts.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 3eaf20ea-3ac0-4701-958f-28527bf641fc
@sobolevnrm
sobolevnrm merged commit a43c3f6 into master Oct 25, 2026
5 of 7 checks passed
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.

1 participant