From 6991357513bf8bfbb71a4675e271b386cc273476 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 3 Jul 2008 00:25:23 -0700 Subject: [PATCH] fast-export --export-marks: fix off by one error The export_marks() function iterated over a (potentially sparsely populated) hashtable, but it accessed it starting from offset 1 and one element beyond the end. Noticed by SungHyun Nam. Signed-off-by: Junio C Hamano --- builtin-fast-export.c | 10 +++++----- decorate.c | 5 +---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/builtin-fast-export.c b/builtin-fast-export.c index 45786ef1b..170b82e6e 100644 --- a/builtin-fast-export.c +++ b/builtin-fast-export.c @@ -379,19 +379,19 @@ static void export_marks(char *file) if (!f) error("Unable to open marks file %s for writing", file); - for (i = 0; i < idnums.size; ++i) { - deco++; - if (deco && deco->base && deco->base->type == 1) { + for (i = 0; i < idnums.size; i++) { + if (deco->base && deco->base->type == 1) { mark = ptr_to_mark(deco->decoration); fprintf(f, ":%u %s\n", mark, sha1_to_hex(deco->base->sha1)); } + deco++; } if (ferror(f) || fclose(f)) error("Unable to write marks file %s.", file); } -static void import_marks(char * input_file) +static void import_marks(char *input_file) { char line[512]; FILE *f = fopen(input_file, "r"); @@ -407,7 +407,7 @@ static void import_marks(char * input_file) line_end = strchr(line, '\n'); if (line[0] != ':' || !line_end) die("corrupt mark line: %s", line); - *line_end = 0; + *line_end = '\0'; mark = strtoumax(line + 1, &mark_end, 10); if (!mark || mark_end == line + 1 diff --git a/decorate.c b/decorate.c index 23f6b0040..d9668d2ef 100644 --- a/decorate.c +++ b/decorate.c @@ -37,10 +37,7 @@ static void grow_decoration(struct decoration *n) { int i; int old_size = n->size; - struct object_decoration *old_hash; - - old_size = n->size; - old_hash = n->hash; + struct object_decoration *old_hash = n->hash; n->size = (old_size + 1000) * 3 / 2; n->hash = xcalloc(n->size, sizeof(struct object_decoration)); -- 2.30.2