resolve_ref_unsafe(): use for loop to count up to MAXDEPTH
The loop's there anyway; we might as well use it. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: David Turner <dturner@twopensource.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Apr 7, 2016 at 15:02 UTC
37da4227b27771cd9947b7393851975a311e6eb9
1 file changed
+6
-7
refs/files-backend.c
+6
-7
@@ -1400,8 +1400,8 @@ static const char *resolve_ref_1(const char *refname,
1400
struct strbuf *sb_path,
1401
struct strbuf *sb_contents)
1402
{
1403
- int depth = MAXDEPTH;
1403
int bad_name = 0;
1404
+ int symref_count;
1405
1406
if (flags)
1407
*flags = 0;
@@ -1425,17 +1425,13 @@ static const char *resolve_ref_1(const char *refname,
1425
*/
1426
bad_name = 1;
1427
}
1428
- for (;;) {
1428
+
1429
+ for (symref_count = 0; symref_count < MAXDEPTH; symref_count++) {
1430
const char *path;
1431
struct stat st;
1432
char *buf;
1433
int fd;
1434
1434
- if (--depth < 0) {
1435
- errno = ELOOP;
1436
- return NULL;
1437
- }
1438
-
1435
strbuf_reset(sb_path);
1436
strbuf_git_path(sb_path, "%s", refname);
1437
path = sb_path->buf;
@@ -1566,6 +1562,9 @@ static const char *resolve_ref_1(const char *refname,
1562
bad_name = 1;
1563
}
1564
}
1565
+
1566
+ errno = ELOOP;
1567
+ return NULL;
1568
}
1569
1570
const char *resolve_ref_unsafe(const char *refname, int resolve_flags,