Skip to content

[Fix] Fix off-by-one in Covobs pos bounds check - #288

Merged
fjosw merged 2 commits into
developfrom
fix/covobs_pos_off_by_one
Jul 15, 2026
Merged

[Fix] Fix off-by-one in Covobs pos bounds check#288
fjosw merged 2 commits into
developfrom
fix/covobs_pos_off_by_one

Conversation

@fjosw

@fjosw fjosw commented Jul 15, 2026

Copy link
Copy Markdown
Owner

Follow up to the making exception messages more explicit: This highlighted a small bug that let to a misleading exception message.

@fjosw
fjosw requested a review from s-kuberski as a code owner July 15, 2026 07:25
@fjosw
fjosw requested review from Copilot and removed request for s-kuberski July 15, 2026 07:25

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

Fixes an off-by-one error in Covobs position validation so out-of-range pos indices produce a clear ValueError (instead of later, less-informative indexing errors), and adds a regression test to lock in the behavior.

Changes:

  • Tighten Covobs.__init__ bounds check from pos > N to pos >= N.
  • Add a unit test ensuring pos == N raises ValueError.
  • Add a direct import of Covobs in the test module to exercise the constructor.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
pyerrors/covobs.py Fixes upper-bound validation for pos to prevent out-of-range indexing.
tests/covobs_test.py Adds a regression test for pos being too large.

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

Comment thread pyerrors/covobs.py Outdated
Comment on lines 34 to 35
if pos >= self.N:
raise ValueError(f'pos {pos} too large for covariance matrix with dimension {self.N}x{self.N}!')

@s-kuberski s-kuberski left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Very good, thanks for spotting it!

@fjosw
fjosw merged commit c58467a into develop Jul 15, 2026
10 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.

3 participants