mirror of
https://github.com/libgit2/libgit2.git
synced 2026-06-22 06:26:26 +00:00
xdiff: don't try to malloc 0 bytes
For zero byte files, avoid allocation - this avoids undefined behavior around malloc(0) and potentially memcpy(..., NULL, 0).
This commit is contained in:
24
deps/xdiff/xmerge.c
vendored
24
deps/xdiff/xmerge.c
vendored
@@ -709,19 +709,23 @@ int xdl_merge(mmfile_t *orig, mmfile_t *mf1, mmfile_t *mf2,
|
|||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (!xscr1) {
|
if (!xscr1) {
|
||||||
result->ptr = xdl_malloc(mf2->size);
|
if (mf2->size) {
|
||||||
if (!result->ptr)
|
result->ptr = xdl_malloc(mf2->size);
|
||||||
goto out;
|
if (!result->ptr)
|
||||||
|
goto out;
|
||||||
|
memcpy(result->ptr, mf2->ptr, mf2->size);
|
||||||
|
result->size = mf2->size;
|
||||||
|
}
|
||||||
status = 0;
|
status = 0;
|
||||||
memcpy(result->ptr, mf2->ptr, mf2->size);
|
|
||||||
result->size = mf2->size;
|
|
||||||
} else if (!xscr2) {
|
} else if (!xscr2) {
|
||||||
result->ptr = xdl_malloc(mf1->size);
|
if (mf1->size) {
|
||||||
if (!result->ptr)
|
result->ptr = xdl_malloc(mf1->size);
|
||||||
goto out;
|
if (!result->ptr)
|
||||||
|
goto out;
|
||||||
|
memcpy(result->ptr, mf1->ptr, mf1->size);
|
||||||
|
result->size = mf1->size;
|
||||||
|
}
|
||||||
status = 0;
|
status = 0;
|
||||||
memcpy(result->ptr, mf1->ptr, mf1->size);
|
|
||||||
result->size = mf1->size;
|
|
||||||
} else {
|
} else {
|
||||||
status = xdl_do_merge(&xe1, xscr1,
|
status = xdl_do_merge(&xe1, xscr1,
|
||||||
&xe2, xscr2,
|
&xe2, xscr2,
|
||||||
|
|||||||
Reference in New Issue
Block a user