diff --git a/bin/diff b/bin/diff index 10f9282e..88f565eb 100755 --- a/bin/diff +++ b/bin/diff @@ -69,7 +69,7 @@ while ($ARGV[0] =~ /^-/) { my $opt = shift; last if $opt eq '--'; if ($opt =~ /^-C(.*)/) { - $Context_Lines = $1 || shift; + $Context_Lines = checklen($1 || shift); $opt_c = 1; $Diff_Type = "CONTEXT"; } elsif ($opt =~ /^-c$/) { @@ -83,7 +83,7 @@ while ($ARGV[0] =~ /^-/) { $opt_f = 1; $Diff_Type = "REVERSE_ED"; } elsif ($opt =~ /^-U(.*)$/) { - $Context_Lines = $1 || shift; + $Context_Lines = checklen($1 || shift); $opt_u = 1; $Diff_Type = "UNIFIED"; } elsif ($opt =~ /^-u$/) { @@ -193,6 +193,12 @@ sub bag { exit 2; } +sub checklen { + my $n = shift; + return int($n) if ($n =~ m/\A[0-9]+\Z/); + bag("Invalid context length '$n'\n$usage"); +} + ######## # Package Hunk. A Hunk is a group of Blocks which overlap because of the # context surrounding each block. (So if we're not using context, every