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:
8
deps/xdiff/xmerge.c
vendored
8
deps/xdiff/xmerge.c
vendored
@@ -709,19 +709,23 @@ int xdl_merge(mmfile_t *orig, mmfile_t *mf1, mmfile_t *mf2,
|
||||
goto out;
|
||||
|
||||
if (!xscr1) {
|
||||
if (mf2->size) {
|
||||
result->ptr = xdl_malloc(mf2->size);
|
||||
if (!result->ptr)
|
||||
goto out;
|
||||
status = 0;
|
||||
memcpy(result->ptr, mf2->ptr, mf2->size);
|
||||
result->size = mf2->size;
|
||||
}
|
||||
status = 0;
|
||||
} else if (!xscr2) {
|
||||
if (mf1->size) {
|
||||
result->ptr = xdl_malloc(mf1->size);
|
||||
if (!result->ptr)
|
||||
goto out;
|
||||
status = 0;
|
||||
memcpy(result->ptr, mf1->ptr, mf1->size);
|
||||
result->size = mf1->size;
|
||||
}
|
||||
status = 0;
|
||||
} else {
|
||||
status = xdl_do_merge(&xe1, xscr1,
|
||||
&xe2, xscr2,
|
||||
|
||||
Reference in New Issue
Block a user