Re: Bug report: "Use of uninitialized value $_ in print"
- From
Jeff King <peff@peff.net>
- Date
- Mar 2, 2018, 16:55 UTC
- Message-ID
- <20180302165543.GA4616@sigill.intra.peff.net>
- In-Reply-To
- <xmqq1sh2e7w1.fsf@gitster-ct.c.googlers.com>
On Fri, Mar 02, 2018 at 08:53:34AM -0800, Junio C Hamano wrote:
Show 28 quoted lines
> Jeff King <peff@peff.net> writes:
>
> > Because the array is full of "undef". See parse_diff(), which does this:
> >
> > my @diff = run_cmd_pipe("git", @diff_cmd, "--", $path);
> > ...
> > @colored = run_cmd_pipe(@display_cmd);
> > ...
> > for (my $i = 0; $i < @diff; $i++) {
> > ...
> > push @{$hunk[-1]{TEXT}}, $diff[$i];
> > push @{$hunk[-1]{DISPLAY}},
> > (@colored ? $colored[$i] : $diff[$i]);
> > }
> >
> > If the @colored output is shorter than the normal @diff output, we'll
> > push a bunch of "undef" onto the DISPLAY array (the ternary there is
> > because sometimes @colored is completely empty if the user did not ask
> > for color).
>
> An obvious sanity check would be to ensure @colored == @diff
>
> push @{$hunk[-1]{DISPLAY}},
> - (@colored ? $colored[$i] : $diff[$i]);
> + (@colored && @colored == @diff ? $colored[$i] : $diff[$i]);
> }
>
> or something like that?That's probably a reasonable sanity check, but I think we need to abort and not just have a too-small DISPLAY array. Because later code like the hunk-splitting is going to assume that there's a 1:1 line correspondence. We definitely don't want to end up in a situation where we show one thing but apply another.
-Peff