Subject: | Warning from Graph.pm |
Date: | Sat, 29 Oct 2016 08:22:58 -0400 |
To: | bug-Graph [...] rt.cpan.org |
From: | Ian Turner <vectro [...] vectro.org> |
Hi Graph maintainers,
I noticed an erroneous warning from the Graph module when Perl is
running with warnings. The problem is in Graph::SP_Dijkstra. Here is a
simple test case:
#!/usr/bin/perl -w
use Graph;
my $g = Graph->new();
$g->add_edge(0,1);
print length($g->SP_Dijkstra(1,0)), "\n";
Which generates output like this:
$ ./graph-testcase.pl
Use of uninitialized value within @path in reverse at /usr/share/perl5/Graph.pm line 3404.
0
The problem is that on line 3404, @path is the empty list. There is
nothing semantically wrong with reversing an empty list but I guess Perl
doesn't like it.
Here is a patch for a simple fix:
--- /usr/share/perl5/Graph.pm 2015-10-23 20:51:56.000000000 -0400
+++ /tmp/Graph.pm 2016-08-05 22:34:15.341393613 -0400
@@ -3400,8 +3400,11 @@
$seen{$p}++;
last if keys %seen == $V || $u eq $v;
}
- @path = () if @path && $path[-1] ne $u;
- return reverse @path;
+ if (@path && $path[-1] ne $u) {
+ return ();
+ } else {
+ return reverse @path;
+ }
}
sub __SPT_Bellman_Ford {
Happy to discuss this more if you think I'm missing something.
Regards,
--Ian