Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions pgtap/dijkstra/driving_distance/edge_cases/issue_3091.pg
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* :file: This file is part of the pgRouting project.
:copyright: Copyright (c) 2026 pgRouting developers
:license: Creative Commons Attribution-Share Alike 3.0 https://creativecommons.org/licenses/by-sa/3.0 */

/* Issue #3091: pgr_drivingDistance accepts negative distance without raising an error */

BEGIN;

SELECT plan(2);

-- Negative distance should raise an error, not silently return empty result.
SELECT throws_ok(
$$SELECT * FROM pgr_drivingDistance('SELECT id, source, target, cost, reverse_cost FROM edges', 1, -1.0)$$,
'Negative value found on ''distance''',
'1: pgr_drivingDistance with negative distance raises error'
);

-- Distance of 0 is valid (returns only the origin node).
SELECT ok(
(SELECT count(*) = 1 FROM pgr_drivingDistance('SELECT id, source, target, cost, reverse_cost FROM edges', 1, 0.0)),
'2: pgr_drivingDistance with distance=0 returns only origin'
);

SELECT * FROM finish();
ROLLBACK;
6 changes: 6 additions & 0 deletions src/driving_distance/driving_distance_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ pgr_do_drivingDistance(
pgassert(*return_count == 0);
pgassert((*return_tuples) == NULL);

if (distance < 0) {
*err_msg = to_pg_msg("Negative value found on 'distance'");
*log_msg = to_pg_msg("distance must be non-negative");
return;
}

auto roots = get_intSet(starts);

hint = edges_sql;
Expand Down
6 changes: 6 additions & 0 deletions src/driving_distance/driving_distance_withPoints_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ pgr_do_withPointsDD(
pgassert(!(*return_tuples));
pgassert(*return_count == 0);

if (distance < 0) {
*err_msg = to_pg_msg("Negative value found on 'distance'");
*log_msg = to_pg_msg("distance must be non-negative");
return;
}

auto roots = get_intSet(starts);

hint = points_sql;
Expand Down