[PATCH 1/3] ui-patch.c: Use log_tree_commit() to generate diffs

Jason A. Donenfeld Jason at zx2c4.com
Thu Aug 15 20:37:03 CEST 2013


On Thu, Aug 15, 2013 at 11:06 AM, Lukas Fleischer <cgit at cryptocrack.de> wrote:
> +       char rev_range[2 * 20 + 2];>
> +       sprintf(rev_range, "%s..%s", sha1_to_hex(old_sha1), sha1_to_hex(sha1));

If the strings coming out of sha1_to_hex were of length twenty, then
rev_range would have to be of size 2*20+3, not +2, to account for the
null terminator. But in fact sha1_to_hex produces length forty
strings, so rev_range actually needs to be 2*40+3.

        for (i = 0; i < 20; i++) {
                unsigned int val = *sha1++;
                *buf++ = hex[val >> 4];
                *buf++ = hex[val & 0xf];
        }


More information about the CGit mailing list