Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions builtin/push.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ static int push_url_of_remote(struct remote *remote, const char ***url_p)
return remote->url_nr;
Comment thread
dscho marked this conversation as resolved.
}

static NORETURN int die_push_simple(struct branch *branch,
struct remote *remote)
static NORETURN void die_push_simple(struct branch *branch,
struct remote *remote)
{
/*
* There's no point in using shorten_unambiguous_ref here,
Expand Down
13 changes: 13 additions & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,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 */
Expand Down
2 changes: 1 addition & 1 deletion compat/winansi.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ static HANDLE swap_osfhnd(int fd, HANDLE new_handle)
typedef struct _OBJECT_NAME_INFORMATION
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the Git mailing list, Alban Gruin wrote (reply to this):

Hi Johannes,

Le 04/10/2019 à 17:09, Johannes Schindelin via GitGitGadget a écrit :
> From: Johannes Schindelin <johannes.schindelin@gmx.de>
> 
> MSVC would complain thusly:
> 
>     C4200: nonstandard extension used: zero-sized array in struct/union
> 
> Let's just use the `FLEX_ARRAY` constant that we introduced for exactly
> this type of scenario.

Perhaps this is a good candidate for a semantic patch?

Cheers,
Alban

{
UNICODE_STRING Name;
WCHAR NameBuffer[0];
WCHAR NameBuffer[FLEX_ARRAY];
} OBJECT_NAME_INFORMATION, *POBJECT_NAME_INFORMATION;

#define ObjectNameInformation 1
Expand Down
4 changes: 2 additions & 2 deletions read-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,7 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e
*/
Comment thread
dscho marked this conversation as resolved.
if (istate->cache_nr > 0 &&
strcmp(ce->name, istate->cache[istate->cache_nr - 1]->name) > 0)
pos = -istate->cache_nr - 1;
pos = index_pos_to_insert_pos(istate->cache_nr);
else
pos = index_name_stage_pos(istate, ce->name, ce_namelen(ce), ce_stage(ce));

Expand Down Expand Up @@ -1894,7 +1894,7 @@ static size_t estimate_cache_size(size_t ondisk_size, unsigned int entries)
/*
* Account for potential alignment differences.
*/
per_entry += align_padding_size(sizeof(struct cache_entry), -sizeof(struct ondisk_cache_entry));
per_entry += align_padding_size(per_entry, 0);
return ondisk_size + entries * per_entry;
}

Expand Down
4 changes: 2 additions & 2 deletions sha1-lookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int sha1_pos(const unsigned char *sha1, void *table, size_t nr,
if (miv < lov)
return -1;
if (hiv < miv)
return -1 - nr;
return index_pos_to_insert_pos(nr);
if (lov != hiv) {
/*
* At this point miv could be equal
Expand All @@ -97,7 +97,7 @@ int sha1_pos(const unsigned char *sha1, void *table, size_t nr,
lo = mi + 1;
mi = lo + (hi - lo) / 2;
} while (lo < hi);
return -lo-1;
return index_pos_to_insert_pos(lo);
}

int bsearch_hash(const unsigned char *sha1, const uint32_t *fanout_nbo,
Expand Down