summaryrefslogtreecommitdiff
path: root/tag.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2017-10-01 14:45:13 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-10-02 04:14:33 (GMT)
commit7099153e8d7d0ed228c3a63cb06912c13c1082e5 (patch)
tree8a59660c29f472b60f9c3d31ae2b334faffb2a63 /tag.c
parent4010f1d1b782eb7585e0e0abcefa794bd5ff29a0 (diff)
downloadgit-7099153e8d7d0ed228c3a63cb06912c13c1082e5.zip
git-7099153e8d7d0ed228c3a63cb06912c13c1082e5.tar.gz
git-7099153e8d7d0ed228c3a63cb06912c13c1082e5.tar.bz2
tag: avoid NULL pointer arithmetic
lookup_blob() etc. can return NULL if the referenced object isn't of the expected type. In theory it's wrong to reference the object member in that case. In practice it's OK because it's located at offset 0 for all types, so the pointer arithmetic (NULL + 0) is optimized out by the compiler. The issue is reported by Clang's AddressSanitizer, though. Avoid the ASan error by casting the results of the lookup functions to struct object pointers. That works fine with NULL pointers as well. We already rely on the object member being first in all object types in other places in the code. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'tag.c')
-rw-r--r--tag.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/tag.c b/tag.c
index 47f60ae..a3ffffd 100644
--- a/tag.c
+++ b/tag.c
@@ -142,13 +142,13 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
bufptr = nl + 1;
if (!strcmp(type, blob_type)) {
- item->tagged = &lookup_blob(&oid)->object;
+ item->tagged = (struct object *)lookup_blob(&oid);
} else if (!strcmp(type, tree_type)) {
- item->tagged = &lookup_tree(&oid)->object;
+ item->tagged = (struct object *)lookup_tree(&oid);
} else if (!strcmp(type, commit_type)) {
- item->tagged = &lookup_commit(&oid)->object;
+ item->tagged = (struct object *)lookup_commit(&oid);
} else if (!strcmp(type, tag_type)) {
- item->tagged = &lookup_tag(&oid)->object;
+ item->tagged = (struct object *)lookup_tag(&oid);
} else {
error("Unknown type %s", type);
item->tagged = NULL;