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>
Junio C Hamano committed
Jul 3, 2008 at 00:25 UTC
6991357513bf8bfbb71a4675e271b386cc273476
2 files changed
+6
-9
builtin-fast-export.c
+5
-5
@@ -379,19 +379,19 @@ static void export_marks(char *file)
379
if (!f)
380
error("Unable to open marks file %s for writing", file);
381
382
- for (i = 0; i < idnums.size; ++i) {
383
- deco++;
384
- if (deco && deco->base && deco->base->type == 1) {
382
+ for (i = 0; i < idnums.size; i++) {
383
+ if (deco->base && deco->base->type == 1) {
384
mark = ptr_to_mark(deco->decoration);
385
fprintf(f, ":%u %s\n", mark, sha1_to_hex(deco->base->sha1));
386
}
387
+ deco++;
388
}
389
390
if (ferror(f) || fclose(f))
391
error("Unable to write marks file %s.", file);
392
}
393
394
-static void import_marks(char * input_file)
394
+static void import_marks(char *input_file)
395
{
396
char line[512];
397
FILE *f = fopen(input_file, "r");
@@ -407,7 +407,7 @@ static void import_marks(char * input_file)
407
line_end = strchr(line, '\n');
408
if (line[0] != ':' || !line_end)
409
die("corrupt mark line: %s", line);
410
- *line_end = 0;
410
+ *line_end = '\0';
411
412
mark = strtoumax(line + 1, &mark_end, 10);
413
if (!mark || mark_end == line + 1
decorate.c
+1
-4
@@ -37,10 +37,7 @@ static void grow_decoration(struct decoration *n)
37
{
38
int i;
39
int old_size = n->size;
40
- struct object_decoration *old_hash;
41
-
42
- old_size = n->size;
43
- old_hash = n->hash;
40
+ struct object_decoration *old_hash = n->hash;
41
42
n->size = (old_size + 1000) * 3 / 2;
43
n->hash = xcalloc(n->size, sizeof(struct object_decoration));