summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d2d434b)
raw | patch | inline | side by side (parent: d2d434b)
author | Junio C Hamano <gitster@pobox.com> | |
Wed, 26 Jan 2011 20:46:55 +0000 (12:46 -0800) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Thu, 27 Jan 2011 20:58:10 +0000 (12:58 -0800) |
Also add comments to seemingly unsafe pointer dereferences, that
are all safe.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
are all safe.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fsck.c | patch | blob | history |
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 6d5ebca7a9bc9333ea8e493057ecce1b4814c252..91409a0069ece772070a9778190456a1c62a9d60 100644 (file)
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
{
struct object *parent = data;
+ /*
+ * The only case data is NULL or type is OBJ_ANY is when
+ * mark_object_reachable() calls us. All the callers of
+ * that function has non-NULL obj hence ...
+ */
if (!obj) {
+ /* ... these references to parent->fld are safe here */
printf("broken link from %7s %s\n",
typename(parent->type), sha1_to_hex(parent->sha1));
printf("broken link from %7s %s\n",
}
if (type != OBJ_ANY && obj->type != type)
+ /* ... and the reference to parent is safe here */
objerror(parent, "wrong object type in link");
if (obj->flags & REACHABLE)
mark_object(obj, OBJ_ANY, NULL);
}
-static int traverse_one_object(struct object *obj, struct object *parent)
+static int traverse_one_object(struct object *obj)
{
int result;
struct tree *tree = NULL;
entry = pending.objects + --pending.nr;
obj = entry->item;
parent = (struct object *) entry->name;
- result |= traverse_one_object(obj, parent);
+ result |= traverse_one_object(obj);
}
return !!result;
}
sha1_to_hex(it->sha1));
return 1;
}
- mark_object_reachable(obj);
obj->used = 1;
+ mark_object_reachable(obj);
if (obj->type != OBJ_TREE)
err |= objerror(obj, "non-tree in cache-tree");
}