make patch_delta() error cases a bit more verbose
It is especially important to distinguish between a malloc() failure from all the other cases. An out of memory condition is much less worrisome than a compatibility/corruption problem. Also make test-delta compilable again. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Nicolas Pitre committed
Dec 18, 2006 at 16:06 UTC
57b73150c4f1dbc26474a0031f433fb34db1c13f
2 files changed
+8
-9
Makefile
+2
-2
@@ -796,8 +796,8 @@ test: all
796
test-date$X: test-date.c date.o ctype.o
797
$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) test-date.c date.o ctype.o
798
799
-test-delta$X: test-delta.c diff-delta.o patch-delta.o
800
- $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $^
799
+test-delta$X: test-delta.o diff-delta.o patch-delta.o $(GITLIBS)
800
+ $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
801
802
test-dump-cache-tree$X: dump-cache-tree.o $(GITLIBS)
803
$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
patch-delta.c
+6
-7
@@ -9,8 +9,7 @@
9
* published by the Free Software Foundation.
10
*/
11
12
-#include <stdlib.h>
13
-#include <string.h>
12
+#include "git-compat-util.h"
13
#include "delta.h"
14
15
void *patch_delta(const void *src_buf, unsigned long src_size,
@@ -34,9 +33,7 @@ void *patch_delta(const void *src_buf, unsigned long src_size,
33
34
/* now the result size */
35
size = get_delta_hdr_size(&data, top);
37
- dst_buf = malloc(size + 1);
38
- if (!dst_buf)
39
- return NULL;
36
+ dst_buf = xmalloc(size + 1);
37
dst_buf[size] = 0;
38
39
out = dst_buf;
@@ -55,13 +52,13 @@ void *patch_delta(const void *src_buf, unsigned long src_size,
52
if (cp_off + cp_size < cp_size ||
53
cp_off + cp_size > src_size ||
54
cp_size > size)
58
- goto bad;
55
+ break;
56
memcpy(out, (char *) src_buf + cp_off, cp_size);
57
out += cp_size;
58
size -= cp_size;
59
} else if (cmd) {
60
if (cmd > size)
64
- goto bad;
61
+ break;
62
memcpy(out, data, cmd);
63
out += cmd;
64
data += cmd;
@@ -72,12 +69,14 @@ void *patch_delta(const void *src_buf, unsigned long src_size,
69
* extensions. In the mean time we must fail when
70
* encountering them (might be data corruption).
71
*/
72
+ error("unexpected delta opcode 0");
73
goto bad;
74
}
75
}
76
77
/* sanity check */
78
if (data != top || size != 0) {
79
+ error("delta replay has gone wild");
80
bad:
81
free(dst_buf);
82
return NULL;