path: root/diff-delta.c
diff options
authorJeff King <>2019-09-05 22:53:37 (GMT)
committerJunio C Hamano <>2019-09-06 18:03:39 (GMT)
commite4b369069e4a7630233a045784d0b1e2425b0a05 (patch)
treeb8d944e9736c98e4dd6ca7a0c3e0a00bdafa0d6d /diff-delta.c
parent7140414d8bd7ed1a05b83bc34d0d0e76ef8b12bd (diff)
diff-delta: set size out-parameter to 0 for NULL delta
When we cannot generate a delta, we return NULL but leave delta_size untouched. This is generally OK, as callers rely on NULL to decide if the output is usable or not. But it can confuse compilers; in particular, gcc 9.2.1 with "-flto -O3" complains in fast-import's store_object() that delta_len may be used uninitialized. Let's change the diff-delta code to set the size explicitly to 0 for a NULL return. That silences the compiler and makes it easier to reason about the result. Reported-by: Stephan Beyer <> Helped-by: Junio C Hamano <> Signed-off-by: Jeff King <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'diff-delta.c')
1 files changed, 2 insertions, 0 deletions
diff --git a/diff-delta.c b/diff-delta.c
index e496433..77fea08 100644
--- a/diff-delta.c
+++ b/diff-delta.c
@@ -326,6 +326,8 @@ create_delta(const struct delta_index *index,
const unsigned char *ref_data, *ref_top, *data, *top;
unsigned char *out;
+ *delta_size = 0;
if (!trg_buf || !trg_size)
return NULL;