sha1_name: check @{-N} errors sooner

It's trivial to check for them in the @{N} parsing loop. Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ramkumar Ramachandra committed May 7, 2013 at 16:55 UTC 83d16bc7bec92ea3f705f559c5a13589cb7c1f92
1 file changed +4 -5
sha1_name.c
+4 -5
@@ -448,7 +448,10 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
448 if (len && str[len-1] == '}') {
449 for (at = len-4; at >= 0; at--) {
450 if (str[at] == '@' && str[at+1] == '{') {
451 - if (at == 0 && str[2] == '-') {
451 + if (str[at+2] == '-') {
452 + if (at != 0)
453 + /* @{-N} not at start */
454 + return -1;
455 nth_prior = 1;
456 continue;
457 }
@@ -497,10 +500,6 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
500 unsigned long co_time;
501 int co_tz, co_cnt;
502
500 - /* a @{-N} placed anywhere except the start is an error */
501 - if (str[at+2] == '-')
502 - return -1;
503 -
503 /* Is it asking for N-th entry, or approxidate? */
504 for (i = nth = 0; 0 <= nth && i < reflog_len; i++) {
505 char ch = str[at+2+i];