Skip to content
  • René Scharfe's avatar
    tag: avoid NULL pointer arithmetic · 7099153e
    René Scharfe authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    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: default avatarRene Scharfe <l.s.r@web.de>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    7099153e