File: no-hash-manipulation-inside-each.patch

package info (click to toggle)
libbio-primerdesigner-perl 0.07-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 252 kB
  • ctags: 69
  • sloc: perl: 1,378; makefile: 84
file content (29 lines) | stat: -rw-r--r-- 1,019 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Description: avoid changing hash keys in an "each %hash" loop
 This leads to undefined behaviour
 Instead, mark what needs to be added/deleted and do it outside of the loop.
Bug-Debian: http://bugs.debian.org/711426
Bug: https://rt.cpan.org/Public/Bug/Display.html?id=85968
Author: Damyan Ivanov <dmn@debian.org>
Forwarded: yes

--- a/lib/Bio/PrimerDesigner/primer3.pm
+++ b/lib/Bio/PrimerDesigner/primer3.pm
@@ -106,12 +106,16 @@ that can be used to call result methods.
     #
     my %aliases = $self->list_aliases;
     my %lookup  = reverse %aliases;
+    my @delete;
+    my %add;
     while ( my ( $k, $v ) = each %$args ) {
         next if exists $aliases{ $k };
         my $alias = $lookup{ $k } or return $self->error("No alias for '$k'");
-        delete $args->{ $k };
-        $args->{ $alias } = $v;
+        push @delete, $k;
+        $add{ $alias } = $v;
     }
+    delete $args->{$_} for @delete;
+    $args->{$_} = $add{$_} for keys %add;
 
     #
     # Check that everything required is present.