Skip to content

Fix count_rows underflow - #3194

Closed
RahejaJi wants to merge 1 commit into
pgRouting:developfrom
RahejaJi:fix-count-rows-underflow
Closed

RahejaJi wants to merge 1 commit into
pgRouting:developfrom
RahejaJi:fix-count-rows-underflow

Conversation

@RahejaJi

@RahejaJi RahejaJi commented Nov 22, 2026 •

Copy link
Copy Markdown

Summary

  • Exclude diagonal matrix elements while counting valid entries.
  • Exclude infinity values from the count.
  • Remove unsigned subtraction to prevent underflow.

Testing

  • git diff --check passed.
  • Full build and automated tests have not been run locally because CMake is not installed.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected matrix row counts to exclude diagonal entries and values set to the maximum representable number. Counts are now accurate when diagonal entries contain other values.

@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

detail::count_rows now counts only off-diagonal matrix entries whose values are not the maximum double value. It no longer subtracts the matrix row count from the total.

Changes

Matrix row counting

Layer / File(s) Summary
Count off-diagonal entries
src/cpp_common/to_postgres.cpp
count_rows increments the count only for non-maximum values outside the diagonal. This replaces counting all non-maximum values and subtracting the matrix row count.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Possibly related issues

  • pgRouting/pgrouting#3192 — The issue reports underflow and underallocation in detail::count_rows. This change addresses its described counting behavior by excluding diagonal entries and maximum values.

Suggested labels: Bug Fix

Suggested reviewers: cvvergara

Merge Risk: Minimal · up to 9f5ca

This change fixes an unsigned underflow when counting valid entries by excluding diagonal and infinite values directly. No concrete risk was found, so it looks safe to merge after normal CI checks.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Fix count_rows underflow" names the function and the bug class that the change addresses. The raw summary says count_rows now counts only off-diagonal entries that are not double's maximum …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Fix count_rows underflow" names the function and the bug class that the change addresses. The raw summary says count_rows now counts only off-diagonal entries that are not double's maximum value, and no longer subtracts the row count. That removes the unsigned subtraction that the objectives describe as the cause of the underflow. The title matches the main change, so the check passes.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit counts the entries in a row,
Skipping the diagonal as it goes.
Maximum values do not join the sum,
The corrected count is neatly done.
Hop, hop, onward through the matrix!

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 5ac49eb8-cd08-47a2-a449-416babd066bf
Commits

Reviewing files that changed from the base of the PR and between 0385ea7 and 9f5ca5f.

Files selected for processing: 1

  • src/cpp_common/to_postgres.cpp

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@RahejaJi RahejaJi left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

.

@cvvergara cvvergara closed this Nov 30, 2026
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.

2 participants