X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=delta.h;h=9464f3e9b08b959d11305688ce194867a4017817;hb=e88856b485cd73dfc1f3ef8d4c5b52a2f557e8c8;hp=31d1820f80f2887d51808170fc86585ada42d42e;hpb=c1067050ce58b5b39f528fe634732da858664603;p=git.git diff --git a/delta.h b/delta.h index 31d1820f..9464f3e9 100644 --- a/delta.h +++ b/delta.h @@ -16,17 +16,18 @@ extern void *patch_delta(void *src_buf, unsigned long src_size, * This must be called twice on the delta data buffer, first to get the * expected reference buffer size, and again to get the result buffer size. */ -static inline unsigned long get_delta_hdr_size(const unsigned char **datap) +static inline unsigned long get_delta_hdr_size(const unsigned char **datap, + const unsigned char *top) { const unsigned char *data = *datap; - unsigned char cmd = *data++; - unsigned long size = cmd & ~0x80; - int i = 7; - while (cmd & 0x80) { + unsigned char cmd; + unsigned long size = 0; + int i = 0; + do { cmd = *data++; size |= (cmd & ~0x80) << i; i += 7; - } + } while (cmd & 0x80 && data < top); *datap = data; return size; }