Git fork

Merge branch 'jk/clang-sanitizer-fixes'

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

+29 -15
+4 -2
compat/obstack.h
··· 135 alignment relative to 0. */ 136 137 #define __PTR_ALIGN(B, P, A) \ 138 - __BPTR_ALIGN (sizeof (PTR_INT_TYPE) < sizeof (void *) ? (B) : (char *) 0, \ 139 - P, A) 140 141 #include <string.h> 142
··· 135 alignment relative to 0. */ 136 137 #define __PTR_ALIGN(B, 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 + ) 142 143 #include <string.h> 144
+13 -5
merge-recursive.c
··· 1712 return new_path; 1713 } 1714 1715 static int handle_rename_rename_1to2(struct merge_options *opt, 1716 struct rename_conflict_info *ci) 1717 { ··· 1756 * such cases, we should keep the added file around, 1757 * resolving the conflict at that path in its favor. 1758 */ 1759 - add = &ci->ren1->dst_entry->stages[2 ^ 1]; 1760 if (is_valid(add)) { 1761 if (update_file(opt, 0, add, a->path)) 1762 return -1; 1763 } 1764 else 1765 remove_file_from_index(opt->repo->index, a->path); 1766 - add = &ci->ren2->dst_entry->stages[3 ^ 1]; 1767 if (is_valid(add)) { 1768 if (update_file(opt, 0, add, b->path)) 1769 return -1; ··· 1776 * rename/add collision. If not, we can write the file out 1777 * to the specified location. 1778 */ 1779 - add = &ci->ren1->dst_entry->stages[2 ^ 1]; 1780 if (is_valid(add)) { 1781 add->path = mfi.blob.path = a->path; 1782 if (handle_file_collision(opt, a->path, ··· 1797 return -1; 1798 } 1799 1800 - add = &ci->ren2->dst_entry->stages[3 ^ 1]; 1801 if (is_valid(add)) { 1802 add->path = mfi.blob.path = b->path; 1803 if (handle_file_collision(opt, b->path, ··· 1846 path_side_1_desc = xstrfmt("version of %s from %s", path, a->path); 1847 path_side_2_desc = xstrfmt("version of %s from %s", path, b->path); 1848 ostage1 = ci->ren1->branch == opt->branch1 ? 3 : 2; 1849 - ostage2 = ostage1 ^ 1; 1850 ci->ren1->src_entry->stages[ostage1].path = a->path; 1851 ci->ren2->src_entry->stages[ostage2].path = b->path; 1852 if (merge_mode_and_contents(opt, a, c1,
··· 1712 return new_path; 1713 } 1714 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 + 1723 static int handle_rename_rename_1to2(struct merge_options *opt, 1724 struct rename_conflict_info *ci) 1725 { ··· 1764 * such cases, we should keep the added file around, 1765 * resolving the conflict at that path in its favor. 1766 */ 1767 + add = &ci->ren1->dst_entry->stages[flip_stage(2)]; 1768 if (is_valid(add)) { 1769 if (update_file(opt, 0, add, a->path)) 1770 return -1; 1771 } 1772 else 1773 remove_file_from_index(opt->repo->index, a->path); 1774 + add = &ci->ren2->dst_entry->stages[flip_stage(3)]; 1775 if (is_valid(add)) { 1776 if (update_file(opt, 0, add, b->path)) 1777 return -1; ··· 1784 * rename/add collision. If not, we can write the file out 1785 * to the specified location. 1786 */ 1787 + add = &ci->ren1->dst_entry->stages[flip_stage(2)]; 1788 if (is_valid(add)) { 1789 add->path = mfi.blob.path = a->path; 1790 if (handle_file_collision(opt, a->path, ··· 1805 return -1; 1806 } 1807 1808 + add = &ci->ren2->dst_entry->stages[flip_stage(3)]; 1809 if (is_valid(add)) { 1810 add->path = mfi.blob.path = b->path; 1811 if (handle_file_collision(opt, b->path, ··· 1854 path_side_1_desc = xstrfmt("version of %s from %s", path, a->path); 1855 path_side_2_desc = xstrfmt("version of %s from %s", path, b->path); 1856 ostage1 = ci->ren1->branch == opt->branch1 ? 3 : 2; 1857 + ostage2 = flip_stage(ostage1); 1858 ci->ren1->src_entry->stages[ostage1].path = a->path; 1859 ci->ren2->src_entry->stages[ostage2].path = b->path; 1860 if (merge_mode_and_contents(opt, a, c1,
+3 -3
sequencer.c
··· 588 struct merge_options o; 589 struct tree *next_tree, *base_tree, *head_tree; 590 int clean; 591 - char **xopt; 592 struct lock_file index_lock = LOCK_INIT; 593 594 if (repo_hold_locked_index(r, &index_lock, LOCK_REPORT_ON_ERROR) < 0) ··· 608 next_tree = next ? get_commit_tree(next) : empty_tree(r); 609 base_tree = base ? get_commit_tree(base) : empty_tree(r); 610 611 - for (xopt = opts->xopts; xopt != opts->xopts + opts->xopts_nr; xopt++) 612 - parse_merge_opt(&o, *xopt); 613 614 clean = merge_trees(&o, 615 head_tree,
··· 588 struct merge_options o; 589 struct tree *next_tree, *base_tree, *head_tree; 590 int clean; 591 + int i; 592 struct lock_file index_lock = LOCK_INIT; 593 594 if (repo_hold_locked_index(r, &index_lock, LOCK_REPORT_ON_ERROR) < 0) ··· 608 next_tree = next ? get_commit_tree(next) : empty_tree(r); 609 base_tree = base ? get_commit_tree(base) : empty_tree(r); 610 611 + for (i = 0; i < opts->xopts_nr; i++) 612 + parse_merge_opt(&o, opts->xopts[i]); 613 614 clean = merge_trees(&o, 615 head_tree,
+1 -1
unpack-trees.c
··· 1352 enum pattern_match_result default_match, 1353 int progress_nr) 1354 { 1355 - struct cache_entry **cache_end = cache + nr; 1356 1357 /* 1358 * Process all entries that have the given prefix and meet
··· 1352 enum pattern_match_result default_match, 1353 int progress_nr) 1354 { 1355 + struct cache_entry **cache_end = nr ? cache + nr : cache; 1356 1357 /* 1358 * Process all entries that have the given prefix and meet
+8 -4
xdiff-interface.c
··· 84 { 85 const int blk = 1024; 86 long trimmed = 0, recovered = 0; 87 - char *ap = a->ptr + a->size; 88 - char *bp = b->ptr + b->size; 89 long smaller = (a->size < b->size) ? a->size : b->size; 90 91 while (blk + trimmed <= smaller && !memcmp(ap - blk, bp - blk, blk)) { ··· 250 ALLOC_ARRAY(regs->array, regs->nr); 251 for (i = 0; i < regs->nr; i++) { 252 struct ff_reg *reg = regs->array + i; 253 - const char *ep = strchr(value, '\n'), *expression; 254 char *buffer = NULL; 255 256 reg->negate = (*value == '!'); 257 if (reg->negate && i == regs->nr - 1) ··· 265 if (regcomp(&reg->re, expression, cflags)) 266 die("Invalid regexp to look for hunk header: %s", expression); 267 free(buffer); 268 - value = ep + 1; 269 } 270 } 271
··· 84 { 85 const int blk = 1024; 86 long trimmed = 0, recovered = 0; 87 + char *ap = a->size ? a->ptr + a->size : a->ptr; 88 + char *bp = b->size ? b->ptr + b->size : b->ptr; 89 long smaller = (a->size < b->size) ? a->size : b->size; 90 91 while (blk + trimmed <= smaller && !memcmp(ap - blk, bp - blk, blk)) { ··· 250 ALLOC_ARRAY(regs->array, regs->nr); 251 for (i = 0; i < regs->nr; i++) { 252 struct ff_reg *reg = regs->array + i; 253 + const char *ep, *expression; 254 char *buffer = NULL; 255 + 256 + if (!value) 257 + BUG("mismatch between line count and parsing"); 258 + ep = strchr(value, '\n'); 259 260 reg->negate = (*value == '!'); 261 if (reg->negate && i == regs->nr - 1) ··· 269 if (regcomp(&reg->re, expression, cflags)) 270 die("Invalid regexp to look for hunk header: %s", expression); 271 free(buffer); 272 + value = ep ? ep + 1 : NULL; 273 } 274 } 275