]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin/apply.c
use st_add and st_mult for allocation size computation
[thirdparty/git.git] / builtin / apply.c
index deb1364fa81452d236a224109a99b28a034f9a9a..0db6d14cc2eeaf3a08fb08301ab02af1b22fc8f8 100644 (file)
@@ -2632,7 +2632,7 @@ static void update_image(struct image *img,
        insert_count = postimage->len;
 
        /* Adjust the contents */
-       result = xmalloc(img->len + insert_count - remove_count + 1);
+       result = xmalloc(st_add3(st_sub(img->len, remove_count), insert_count, 1));
        memcpy(result, img->buf, applied_at);
        memcpy(result + applied_at, postimage->buf, postimage->len);
        memcpy(result + applied_at + postimage->len,