[pve-devel] [PATCH v2 common] tools: file_set_contents: use syswrite instead of print
Thomas Lamprecht
t.lamprecht at proxmox.com
Mon Oct 14 11:26:26 CEST 2024
Am 30/09/2024 um 13:40 schrieb Filip Schauer:
> + $offset += syswrite($fh, $data, $len - $offset, $offset)
> + or die "unable to write '$tmpname' - $!\n";
FYI: Wolfgang noticed something nasty with the subtle difference between
the `or` and `||` operator [0] that introduces a bug w.r.t. error handling
here.
Basically `or` has lower precedence and thus would have made the code
act like:
($offset += syswrite($fh, $data, $len - $offset, $offset))
or die "unable to write '$tmpname' - $!\n";
Thus, never taking the error path once $offset was incresead to something
to non-zero, i.e. after the first round. See my follow-up commit [1] for
more details.
[0]: https://perldoc.perl.org/perlop#Logical-or-and-Exclusive-Or
[1]: https://git.proxmox.com/?p=pve-common.git;a=commitdiff;h=f1fe7a0733570e84343f152e2409b22782feb2d3
More information about the pve-devel
mailing list