Skip to content

Conversation

@KC1706
Copy link

@KC1706 KC1706 commented Dec 26, 2025

Fixes # .

Changes proposed in this pull request:

@pgRouting/admins

Summary by CodeRabbit

  • Refactor

    • Improved variable initialization patterns in core algorithm implementations.
  • Chores

    • Enhanced code quality tooling configuration.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 26, 2025

Walkthrough

This pull request enforces stricter variable initialization practices by enabling the cppcoreguidelines-init-variables clang-tidy rule and updating the dijkstra_driver.cpp file to comply by replacing default-initialization patterns with explicit braced and value-initialization syntax.

Changes

Cohort / File(s) Summary
Clang-tidy Configuration
.clang-tidy
Enabled cppcoreguidelines-init-variables rule in the Checks list to enforce explicit variable initialization across the codebase.
Initialization Pattern Updates
src/dijkstra/dijkstra_driver.cpp
Replaced inline default-initialization and direct default-construction patterns with explicit braced initialization (e.g., n = 0 with braced init, graph{}) to comply with the new linting rule.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

Braces and initializers, now standing so tall, 🐰
Our variables dressed up in their formal apparel,
No more lazy defaults—each value's declared,
The code rabbit's work is complete and well-paired!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main changes: enabling a clang-tidy check and fixing related warnings in the codebase.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5d76cc6 and 3acef50.

📒 Files selected for processing (2)
  • .clang-tidy
  • src/dijkstra/dijkstra_driver.cpp
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2025-04-29T18:59:06.824Z
Learnt from: cvvergara
Repo: pgRouting/pgrouting PR: 2879
File: sql/dijkstra/dijkstra.sql:56-57
Timestamp: 2025-04-29T18:59:06.824Z
Learning: The maintainer prefers not to add inline comments to internal function calls like _pgr_dijkstra, even when they contain multiple boolean and numeric flags.

Applied to files:

  • src/dijkstra/dijkstra_driver.cpp
📚 Learning: 2025-02-27T23:05:28.589Z
Learnt from: cvvergara
Repo: pgRouting/pgrouting PR: 2771
File: sql/common/_checkquery.sql:33-33
Timestamp: 2025-02-27T23:05:28.589Z
Learning: When reviewing PostgreSQL/pgRouting code, respect the maintainer's preference for brevity over additional comments when variable names are descriptive.

Applied to files:

  • src/dijkstra/dijkstra_driver.cpp
📚 Learning: 2025-04-25T00:59:52.580Z
Learnt from: cvvergara
Repo: pgRouting/pgrouting PR: 2868
File: src/contraction/contractionHierarchies_driver.cpp:47-56
Timestamp: 2025-04-25T00:59:52.580Z
Learning: In pgRouting, driver functions like `pgr_contractionHierarchies` assume that callers within the project will pass valid non-null pointers, as these functions are only used internally with well-defined call patterns. Null checks on the pointers themselves (as opposed to their dereferenced values) are considered unnecessary since the caller is guaranteed to pass references to variables.

Applied to files:

  • src/dijkstra/dijkstra_driver.cpp
🧬 Code graph analysis (1)
src/dijkstra/dijkstra_driver.cpp (1)
include/dijkstra/dijkstra.hpp (6)
  • dijkstra (120-148)
  • dijkstra (120-125)
  • dijkstra (157-170)
  • dijkstra (157-161)
  • dijkstra (174-188)
  • dijkstra (174-178)
🪛 Cppcheck (2.19.0)
src/dijkstra/dijkstra_driver.cpp

[style] 169-169: The function 'examine_edge' is never used.

(unusedFunction)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (3)
.clang-tidy (1)

9-10: LGTM! Good addition of initialization safety check.

Enabling cppcoreguidelines-init-variables helps prevent uninitialized variable bugs by enforcing initialization at declaration time.

src/dijkstra/dijkstra_driver.cpp (2)

168-168: Good use of value initialization.

The explicit braced initialization {} is good modern C++ practice and clearly communicates intent.


172-172: Good use of value initialization.

Consistent with the directed graph initialization above. The explicit braced initialization clearly communicates intent.

Comment on lines +164 to +165
size_t n{0};
n = (n_goals <= 0) ? (std::numeric_limits<size_t>::max)() : static_cast<size_t>(n_goals);
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Consider combining into single-step initialization.

The two-step initialization (declare with 0, then immediately assign) satisfies the clang-tidy rule but is not idiomatic. The initial value is never used.

🔎 Suggested single-step initialization
-size_t n{0};
-n = (n_goals <= 0) ? (std::numeric_limits<size_t>::max)() : static_cast<size_t>(n_goals);
+size_t n = (n_goals <= 0) ? (std::numeric_limits<size_t>::max)() : static_cast<size_t>(n_goals);

Or with braced initialization:

-size_t n{0};
-n = (n_goals <= 0) ? (std::numeric_limits<size_t>::max)() : static_cast<size_t>(n_goals);
+size_t n{(n_goals <= 0) ? (std::numeric_limits<size_t>::max)() : static_cast<size_t>(n_goals)};
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
size_t n{0};
n = (n_goals <= 0) ? (std::numeric_limits<size_t>::max)() : static_cast<size_t>(n_goals);
size_t n = (n_goals <= 0) ? (std::numeric_limits<size_t>::max)() : static_cast<size_t>(n_goals);
Suggested change
size_t n{0};
n = (n_goals <= 0) ? (std::numeric_limits<size_t>::max)() : static_cast<size_t>(n_goals);
size_t n{(n_goals <= 0) ? (std::numeric_limits<size_t>::max)() : static_cast<size_t>(n_goals)};
🤖 Prompt for AI Agents
In src/dijkstra/dijkstra_driver.cpp around lines 164-165, combine the two-step
declare-and-assign into a single initialization: replace the separate
declaration and assignment with one line that initializes n from the
conditional, e.g. using either classic or braced initialization: size_t n =
(n_goals <= 0) ? std::numeric_limits<size_t>::max() :
static_cast<size_t>(n_goals); or size_t n{ (n_goals <= 0) ?
std::numeric_limits<size_t>::max() : static_cast<size_t>(n_goals) }; ensure you
keep the explicit cast for n_goals and call numeric_limits::max() normally.

Copy link
Member

@cvvergara cvvergara left a comment

Choose a reason for hiding this comment

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

I compiled locally using:

CXX=clang++ CC=clang cmake  -DUSE_CLANG_TIDY=ON  -DBUILD_HTML=OFF -DPOSTGRESQL_BIN=${PGBIN} ..

and these are some of the many warnings I get that are not fixed,

[ 20%] Building CXX object src/trsp/CMakeFiles/trsp.dir/trsp_driver.cpp.o
/home/vicky/pgrouting/pgrouting/cvvergara/include/contraction/contractionGraph.hpp:185:15: warning: variable 'inserted' is not initialized [cppcoreguidelines-init-variables]
  185 |          bool inserted;
      |               ^       
      |                        = false
/home/vicky/pgrouting/pgrouting/cvvergara/include/contraction/contractionGraph.hpp:398:14: warning: variable 'found_e' is not initialized [cppcoreguidelines-init-variables]
  398 |         bool found_e;
      |              ^      
      |                      = false
/home/vicky/pgrouting/pgrouting/cvvergara/include/contraction/contractionGraph.hpp:426:18: warning: variable 'inserted' is not initialized [cppcoreguidelines-init-variables]
  426 |             bool inserted;
      |                  ^       
      |                           = false
/home/vicky/pgrouting/pgrouting/cvvergara/include/contraction/contractionGraph.hpp:437:17: warning: variable 'p_max' is not initialized [cppcoreguidelines-init-variables]
  437 |         int64_t p_max;
      |                 ^    
      |                       = 0
/home/vicky/pgrouting/pgrouting/cvvergara/include/contraction/contractionGraph.hpp:439:14: warning: variable 'found_e' is not initialized [cppcoreguidelines-init-variables]
  439 |         bool found_e;
      |              ^      
      |                      = false

Please fix
the files under max_flow directory

@cvvergara cvvergara marked this pull request as draft December 26, 2025 17:01
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