@matheusbsbs / matheus-bagliano / commits / ae86ad6575
Fork 0

git-pickaxe: tighten sanity checks.

When compiled for debugging, make sure that refcnt sanity check code detects underflows in origin reference counting. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Oct 30, 2006 at 14:27 UTC ae86ad65757b857337f10f25ff31cb3348d3943d
1 file changed +10 -5
builtin-pickaxe.c
+10 -5
@@ -973,7 +973,9 @@ static void assign_blame(struct scoreboard *sb, struct rev_info *revs, int opt)
973 if (!cmp_suspect(ent->suspect, suspect))
974 ent->guilty = 1;
975 origin_decref(suspect);
976 - coalesce(sb);
976 +
977 + if (DEBUG) /* sanity */
978 + sanity_check_refcnt(sb);
979 }
980 }
981
@@ -1341,11 +1343,14 @@ static void sanity_check_refcnt(struct scoreboard *sb)
1343 struct blame_entry *ent;
1344
1345 for (ent = sb->ent; ent; ent = ent->next) {
1344 - /* first mark the ones that haven't been checked */
1346 + /* Nobody should have zero or negative refcnt */
1347 + if (ent->suspect->refcnt <= 0)
1348 + baa = 1;
1349 + }
1350 + for (ent = sb->ent; ent; ent = ent->next) {
1351 + /* Mark the ones that haven't been checked */
1352 if (0 < ent->suspect->refcnt)
1353 ent->suspect->refcnt = -ent->suspect->refcnt;
1347 - else if (!ent->suspect->refcnt)
1348 - baa = 1;
1354 }
1355 for (ent = sb->ent; ent; ent = ent->next) {
1356 /* then pick each and see if they have the the
@@ -1357,7 +1362,7 @@ static void sanity_check_refcnt(struct scoreboard *sb)
1362
1363 if (0 < suspect->refcnt)
1364 continue;
1360 - suspect->refcnt = -suspect->refcnt;
1365 + suspect->refcnt = -suspect->refcnt; /* Unmark */
1366 for (found = 0, e = sb->ent; e; e = e->next) {
1367 if (e->suspect != suspect)
1368 continue;