apply: use COPY_ARRAY and MOVE_ARRAY in update_image()

Simplify the code by using the helper macros COPY_ARRAY and MOVE_ARRAY, which also makes them more robust in the case we copy or move no lines, as they allow using NULL points in that case, while memcpy(3) and memmove(3) don't. Found with Clang's UBSan. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Jul 15, 2017 at 22:20 UTC 177366415b95fb72bc2c37d55a936ff101986285
1 file changed +4 -7
apply.c
+4 -7
@@ -2809,13 +2809,10 @@ static void update_image(struct apply_state *state,
2809 img->line_allocated = img->line;
2810 }
2811 if (preimage_limit != postimage->nr)
2812 - memmove(img->line + applied_pos + postimage->nr,
2813 - img->line + applied_pos + preimage_limit,
2814 - (img->nr - (applied_pos + preimage_limit)) *
2815 - sizeof(*img->line));
2816 - memcpy(img->line + applied_pos,
2817 - postimage->line,
2818 - postimage->nr * sizeof(*img->line));
2812 + MOVE_ARRAY(img->line + applied_pos + postimage->nr,
2813 + img->line + applied_pos + preimage_limit,
2814 + img->nr - (applied_pos + preimage_limit));
2815 + COPY_ARRAY(img->line + applied_pos, postimage->line, postimage->nr);
2816 if (!state->allow_overlap)
2817 for (i = 0; i < postimage->nr; i++)
2818 img->line[applied_pos + i].flag |= LINE_PATCHED;