From 19b791f4894efcb6e545a6b51c8147298363358f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 17 Oct 2023 23:37:52 +0000 Subject: use read_all in more places to improve safety `readline' ops may not detect errors on partial reads. This saves us some code to reduce cognitive overhead for readers. We'll also support reusing a destination buffers so it can work more nicely with existing code. --- lib/PublicInbox/ViewVCS.pm | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'lib/PublicInbox/ViewVCS.pm') diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm index 8a90c2d6..86c46e69 100644 --- a/lib/PublicInbox/ViewVCS.pm +++ b/lib/PublicInbox/ViewVCS.pm @@ -17,6 +17,7 @@ use strict; use v5.10.1; use File::Temp 0.19 (); # newdir use PublicInbox::SolverGit; +use PublicInbox::Git qw(read_all); use PublicInbox::GitAsyncCat; use PublicInbox::WwwStream qw(html_oneshot); use PublicInbox::Linkify; @@ -61,12 +62,9 @@ sub dbg_log ($) { warn "seek(log): $!"; return '
debug log seek error
'; } - $log = do { local $/; <$log> } // do { - if (!eof($log)) { - warn "readline(log): $!"; - return '
debug log read error
'; - } - ''; + $log = eval { read_all($log) } // do { + warn "read(log): $@"; + return '
debug log read error
'; }; return '' if $log eq ''; $ctx->{-linkify} //= PublicInbox::Linkify->new; @@ -251,7 +249,7 @@ EOM if (-s $fh > $MAX_SIZE) { print $zfh "---\n patch is too large to show\n"; } else { # prepare flush_diff: - read($fh, $x, -s _); + read_all($fh, -s _, \$x); utf8_maybe($x); $ctx->{-apfx} = $ctx->{-spfx} = $upfx; $x =~ s/\r?\n/\n/gs; -- cgit v1.2.3-24-ge0c7