diff options
author | Junio C Hamano <gitster@pobox.com> | 2008-07-03 00:25:23 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2008-07-03 00:34:59 -0700 |
commit | 6991357513bf8bfbb71a4675e271b386cc273476 (patch) | |
tree | 3369267f2ff1b0da1c9a63768fdd1aa7da49167b | |
parent | git-send-email: Do not attempt to STARTTLS more than once (diff) | |
download | tgif-6991357513bf8bfbb71a4675e271b386cc273476.tar.xz |
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 <gitster@pobox.com>
-rw-r--r-- | builtin-fast-export.c | 10 | ||||
-rw-r--r-- | decorate.c | 5 |
2 files changed, 6 insertions, 9 deletions
diff --git a/builtin-fast-export.c b/builtin-fast-export.c index 45786ef1b7..170b82e6ef 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 23f6b0040f..d9668d2ef9 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)); |