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