Skip to content

Commit 83d16bc

Browse files
artagnongitster
authored andcommitted
sha1_name: check @{-N} errors sooner
It's trivial to check for them in the @{N} parsing loop. Signed-off-by: Ramkumar Ramachandra <[email protected]> Signed-off-by: Felipe Contreras <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 128fd54 commit 83d16bc

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

sha1_name.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,10 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
448448
if (len && str[len-1] == '}') {
449449
for (at = len-4; at >= 0; at--) {
450450
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;
452455
nth_prior = 1;
453456
continue;
454457
}
@@ -497,10 +500,6 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
497500
unsigned long co_time;
498501
int co_tz, co_cnt;
499502

500-
/* a @{-N} placed anywhere except the start is an error */
501-
if (str[at+2] == '-')
502-
return -1;
503-
504503
/* Is it asking for N-th entry, or approxidate? */
505504
for (i = nth = 0; 0 <= nth && i < reflog_len; i++) {
506505
char ch = str[at+2+i];

0 commit comments

Comments
 (0)