summaryrefslogtreecommitdiff
path: root/git-add--interactive.perl
diff options
context:
space:
mode:
authorCarlo Marcelo Arenas Belón <carenas@gmail.com>2021-11-28 17:49:03 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-11-28 23:14:09 (GMT)
commitfc8a8126df822f82ab65135296b5bd569af276c1 (patch)
treeababf89d84babec44302deedcf8927ed187a0e50 /git-add--interactive.perl
parent94f6e3e283f2adfc518b39cfc39291f1c2832ad0 (diff)
downloadgit-fc8a8126df822f82ab65135296b5bd569af276c1.zip
git-fc8a8126df822f82ab65135296b5bd569af276c1.tar.gz
git-fc8a8126df822f82ab65135296b5bd569af276c1.tar.bz2
add -p: avoid use of undefined $key when ReadKey -> EOF
b5cc003253 (add -i: ignore terminal escape sequences, 2011-05-17) add an additional check to the original code to better handle keys for escape sequences, but failed to account for the possibility the first ReadKey call returned undef (ex: stdin closes) and that was being handled fine by the original code in ca6ac7f135 (add -p: prompt for single characters, 2009-02-05) Add a test for undefined and encapsulate the loop and the original print that relied on it within it. After this, the following command (in a suitable repository state) wouldn't print any error: $ git -c interactive.singleKey add -p </dev/null Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-add--interactive.perl')
-rwxr-xr-xgit-add--interactive.perl16
1 files changed, 9 insertions, 7 deletions
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index bc3a1e8..95887fd 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -1175,15 +1175,17 @@ sub prompt_single_character {
ReadMode 'cbreak';
my $key = ReadKey 0;
ReadMode 'restore';
- if ($use_termcap and $key eq "\e") {
- while (!defined $term_escapes{$key}) {
- my $next = ReadKey 0.5;
- last if (!defined $next);
- $key .= $next;
+ if (defined $key) {
+ if ($use_termcap and $key eq "\e") {
+ while (!defined $term_escapes{$key}) {
+ my $next = ReadKey 0.5;
+ last if (!defined $next);
+ $key .= $next;
+ }
+ $key =~ s/\e/^[/;
}
- $key =~ s/\e/^[/;
+ print "$key";
}
- print "$key" if defined $key;
print "\n";
return $key;
} else {