Skip to content

Commit a7a2e12

Browse files
committed
Merge branch 'jk/clang-sanitizer-fixes' into maint
C pedantry ;-) fix. * jk/clang-sanitizer-fixes: obstack: avoid computing offsets from NULL pointer xdiff: avoid computing non-zero offset from NULL pointer avoid computing zero offsets from NULL pointer merge-recursive: use subtraction to flip stage merge-recursive: silence -Wxor-used-as-pow warning
2 parents 93d0892 + cf82bff commit a7a2e12

File tree

5 files changed

+29
-15
lines changed

5 files changed

+29
-15
lines changed

compat/obstack.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,10 @@ extern "C" {
135135
alignment relative to 0. */
136136

137137
#define __PTR_ALIGN(B, P, A) \
138-
__BPTR_ALIGN (sizeof (PTR_INT_TYPE) < sizeof (void *) ? (B) : (char *) 0, \
139-
P, A)
138+
(sizeof (PTR_INT_TYPE) < sizeof(void *) ? \
139+
__BPTR_ALIGN((B), (P), (A)) : \
140+
(void *)__BPTR_ALIGN((PTR_INT_TYPE)(void *)0, (PTR_INT_TYPE)(P), (A)) \
141+
)
140142

141143
#include <string.h>
142144

merge-recursive.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,6 +1712,14 @@ static char *find_path_for_conflict(struct merge_options *opt,
17121712
return new_path;
17131713
}
17141714

1715+
/*
1716+
* Toggle the stage number between "ours" and "theirs" (2 and 3).
1717+
*/
1718+
static inline int flip_stage(int stage)
1719+
{
1720+
return (2 + 3) - stage;
1721+
}
1722+
17151723
static int handle_rename_rename_1to2(struct merge_options *opt,
17161724
struct rename_conflict_info *ci)
17171725
{
@@ -1756,14 +1764,14 @@ static int handle_rename_rename_1to2(struct merge_options *opt,
17561764
* such cases, we should keep the added file around,
17571765
* resolving the conflict at that path in its favor.
17581766
*/
1759-
add = &ci->ren1->dst_entry->stages[2 ^ 1];
1767+
add = &ci->ren1->dst_entry->stages[flip_stage(2)];
17601768
if (is_valid(add)) {
17611769
if (update_file(opt, 0, add, a->path))
17621770
return -1;
17631771
}
17641772
else
17651773
remove_file_from_index(opt->repo->index, a->path);
1766-
add = &ci->ren2->dst_entry->stages[3 ^ 1];
1774+
add = &ci->ren2->dst_entry->stages[flip_stage(3)];
17671775
if (is_valid(add)) {
17681776
if (update_file(opt, 0, add, b->path))
17691777
return -1;
@@ -1776,7 +1784,7 @@ static int handle_rename_rename_1to2(struct merge_options *opt,
17761784
* rename/add collision. If not, we can write the file out
17771785
* to the specified location.
17781786
*/
1779-
add = &ci->ren1->dst_entry->stages[2 ^ 1];
1787+
add = &ci->ren1->dst_entry->stages[flip_stage(2)];
17801788
if (is_valid(add)) {
17811789
add->path = mfi.blob.path = a->path;
17821790
if (handle_file_collision(opt, a->path,
@@ -1797,7 +1805,7 @@ static int handle_rename_rename_1to2(struct merge_options *opt,
17971805
return -1;
17981806
}
17991807

1800-
add = &ci->ren2->dst_entry->stages[3 ^ 1];
1808+
add = &ci->ren2->dst_entry->stages[flip_stage(3)];
18011809
if (is_valid(add)) {
18021810
add->path = mfi.blob.path = b->path;
18031811
if (handle_file_collision(opt, b->path,
@@ -1846,7 +1854,7 @@ static int handle_rename_rename_2to1(struct merge_options *opt,
18461854
path_side_1_desc = xstrfmt("version of %s from %s", path, a->path);
18471855
path_side_2_desc = xstrfmt("version of %s from %s", path, b->path);
18481856
ostage1 = ci->ren1->branch == opt->branch1 ? 3 : 2;
1849-
ostage2 = ostage1 ^ 1;
1857+
ostage2 = flip_stage(ostage1);
18501858
ci->ren1->src_entry->stages[ostage1].path = a->path;
18511859
ci->ren2->src_entry->stages[ostage2].path = b->path;
18521860
if (merge_mode_and_contents(opt, a, c1,

sequencer.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ static int do_recursive_merge(struct repository *r,
588588
struct merge_options o;
589589
struct tree *next_tree, *base_tree, *head_tree;
590590
int clean;
591-
char **xopt;
591+
int i;
592592
struct lock_file index_lock = LOCK_INIT;
593593

594594
if (repo_hold_locked_index(r, &index_lock, LOCK_REPORT_ON_ERROR) < 0)
@@ -608,8 +608,8 @@ static int do_recursive_merge(struct repository *r,
608608
next_tree = next ? get_commit_tree(next) : empty_tree(r);
609609
base_tree = base ? get_commit_tree(base) : empty_tree(r);
610610

611-
for (xopt = opts->xopts; xopt != opts->xopts + opts->xopts_nr; xopt++)
612-
parse_merge_opt(&o, *xopt);
611+
for (i = 0; i < opts->xopts_nr; i++)
612+
parse_merge_opt(&o, opts->xopts[i]);
613613

614614
clean = merge_trees(&o,
615615
head_tree,

unpack-trees.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@ static int clear_ce_flags_1(struct index_state *istate,
13501350
enum pattern_match_result default_match,
13511351
int progress_nr)
13521352
{
1353-
struct cache_entry **cache_end = cache + nr;
1353+
struct cache_entry **cache_end = nr ? cache + nr : cache;
13541354

13551355
/*
13561356
* Process all entries that have the given prefix and meet

xdiff-interface.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ static void trim_common_tail(mmfile_t *a, mmfile_t *b)
8484
{
8585
const int blk = 1024;
8686
long trimmed = 0, recovered = 0;
87-
char *ap = a->ptr + a->size;
88-
char *bp = b->ptr + b->size;
87+
char *ap = a->size ? a->ptr + a->size : a->ptr;
88+
char *bp = b->size ? b->ptr + b->size : b->ptr;
8989
long smaller = (a->size < b->size) ? a->size : b->size;
9090

9191
while (blk + trimmed <= smaller && !memcmp(ap - blk, bp - blk, blk)) {
@@ -250,9 +250,13 @@ void xdiff_set_find_func(xdemitconf_t *xecfg, const char *value, int cflags)
250250
ALLOC_ARRAY(regs->array, regs->nr);
251251
for (i = 0; i < regs->nr; i++) {
252252
struct ff_reg *reg = regs->array + i;
253-
const char *ep = strchr(value, '\n'), *expression;
253+
const char *ep, *expression;
254254
char *buffer = NULL;
255255

256+
if (!value)
257+
BUG("mismatch between line count and parsing");
258+
ep = strchr(value, '\n');
259+
256260
reg->negate = (*value == '!');
257261
if (reg->negate && i == regs->nr - 1)
258262
die("Last expression must not be negated: %s", value);
@@ -265,7 +269,7 @@ void xdiff_set_find_func(xdemitconf_t *xecfg, const char *value, int cflags)
265269
if (regcomp(&reg->re, expression, cflags))
266270
die("Invalid regexp to look for hunk header: %s", expression);
267271
free(buffer);
268-
value = ep + 1;
272+
value = ep ? ep + 1 : NULL;
269273
}
270274
}
271275

0 commit comments

Comments
 (0)