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>
This commit is contained in:
Junio C Hamano 2008-07-03 00:25:23 -07:00
Родитель 6cbf8b00fb
Коммит 6991357513
2 изменённых файлов: 6 добавлений и 9 удалений

Просмотреть файл

@ -379,19 +379,19 @@ static void export_marks(char *file)
if (!f) if (!f)
error("Unable to open marks file %s for writing", file); error("Unable to open marks file %s for writing", file);
for (i = 0; i < idnums.size; ++i) { for (i = 0; i < idnums.size; i++) {
deco++; if (deco->base && deco->base->type == 1) {
if (deco && deco->base && deco->base->type == 1) {
mark = ptr_to_mark(deco->decoration); mark = ptr_to_mark(deco->decoration);
fprintf(f, ":%u %s\n", mark, sha1_to_hex(deco->base->sha1)); fprintf(f, ":%u %s\n", mark, sha1_to_hex(deco->base->sha1));
} }
deco++;
} }
if (ferror(f) || fclose(f)) if (ferror(f) || fclose(f))
error("Unable to write marks file %s.", file); 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]; char line[512];
FILE *f = fopen(input_file, "r"); FILE *f = fopen(input_file, "r");
@ -407,7 +407,7 @@ static void import_marks(char * input_file)
line_end = strchr(line, '\n'); line_end = strchr(line, '\n');
if (line[0] != ':' || !line_end) if (line[0] != ':' || !line_end)
die("corrupt mark line: %s", line); die("corrupt mark line: %s", line);
*line_end = 0; *line_end = '\0';
mark = strtoumax(line + 1, &mark_end, 10); mark = strtoumax(line + 1, &mark_end, 10);
if (!mark || mark_end == line + 1 if (!mark || mark_end == line + 1

Просмотреть файл

@ -37,10 +37,7 @@ static void grow_decoration(struct decoration *n)
{ {
int i; int i;
int old_size = n->size; int old_size = n->size;
struct object_decoration *old_hash; struct object_decoration *old_hash = n->hash;
old_size = n->size;
old_hash = n->hash;
n->size = (old_size + 1000) * 3 / 2; n->size = (old_size + 1000) * 3 / 2;
n->hash = xcalloc(n->size, sizeof(struct object_decoration)); n->hash = xcalloc(n->size, sizeof(struct object_decoration));