]> git.proxmox.com Git - pve-guest-common.git/commitdiff
replication: dont declare variable in post-if scope
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 8 Apr 2020 11:20:02 +0000 (13:20 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 8 Apr 2020 11:20:07 +0000 (13:20 +0200)
If a variable is defined and assigned in a conditional statement, it
is not defined behavior in Perl.

For more information about this behaviour see
https://perldoc.perl.org/perlsyn.html#Statement-Modifiers

> NOTE: The behaviour of a my, state, or our modified with a
> statement modifier conditional or loop construct (for example,
> `my $x if ...`) is undefined.
> The value of the my variable may be undef, any previously assigned
> value, or possibly anything else.
> Don't rely on it. Future versions of perl might do something
> different from the version of perl you try it out on. Here be
> dragons."

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/Replication.pm

index ae1ade4d4fac673d78c43dfe63bc3461e15bbbe3..5e76c5b39214da8330b6cf8ee25e8566dbbf96b8 100644 (file)
@@ -185,7 +185,8 @@ sub replicate_volume {
 
     my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid);
 
-    my $ratelimit_bps = int(1000000*$rate) if $rate;
+    my $ratelimit_bps = $rate ? int(1000000 * $rate) : undef;
+
     PVE::Storage::storage_migrate($storecfg, $volid, $ssh_info, $storeid, $volname,
                                  $base_snapshot, $sync_snapname, $ratelimit_bps, $insecure, 1, $logfunc);
 }