X-Git-Url: http://git.ipfire.org/?p=thirdparty%2Fgit.git;a=blobdiff_plain;f=cache.h;h=04cabaac119540e89f58cd91c46b17ddb30a26ce;hp=1e64b13c90a2e162a819bc289336d35dfa349c0c;hb=da72936f544fec5a335e66432610e4cef4430991;hpb=0b4fae553cdd5aa6713137e42cc03d396ecc1264 diff --git a/cache.h b/cache.h index 1e64b13c90..04cabaac11 100644 --- a/cache.h +++ b/cache.h @@ -748,6 +748,19 @@ struct cache_entry *index_file_exists(struct index_state *istate, const char *na */ int index_name_pos(const struct index_state *, const char *name, int namelen); +/* + * Some functions return the negative complement of an insert position when a + * precise match was not found but a position was found where the entry would + * need to be inserted. This helper protects that logic from any integer + * underflow. + */ +static inline int index_pos_to_insert_pos(uintmax_t pos) +{ + if (pos > INT_MAX) + die("overflow: -1 - %"PRIuMAX, pos); + return -1 - (int)pos; +} + #define ADD_CACHE_OK_TO_ADD 1 /* Ok to add */ #define ADD_CACHE_OK_TO_REPLACE 2 /* Ok to replace file/directory */ #define ADD_CACHE_SKIP_DFCHECK 4 /* Ok to skip DF conflict checks */ @@ -1067,7 +1080,6 @@ const char *repo_find_unique_abbrev(struct repository *r, const struct object_id int repo_find_unique_abbrev_r(struct repository *r, char *hex, const struct object_id *oid, int len); #define find_unique_abbrev_r(hex, oid, len) repo_find_unique_abbrev_r(the_repository, hex, oid, len) -extern const unsigned char null_sha1[GIT_MAX_RAWSZ]; extern const struct object_id null_oid; static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2) @@ -1102,14 +1114,9 @@ static inline int oideq(const struct object_id *oid1, const struct object_id *oi return hasheq(oid1->hash, oid2->hash); } -static inline int is_null_sha1(const unsigned char *sha1) -{ - return hasheq(sha1, null_sha1); -} - static inline int is_null_oid(const struct object_id *oid) { - return hasheq(oid->hash, null_sha1); + return oideq(oid, &null_oid); } static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src)