summaryrefslogtreecommitdiff
path: root/gfx
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-08-22 23:19:10 -0300
committerWerner Almesberger <werner@almesberger.net>2016-08-22 23:19:10 -0300
commit15af44aef6076907cf04ae27cb850f49f3b70ed7 (patch)
tree975cd6df4153c07ce23a38b22248c11ac185dc0b /gfx
parentb1ae4543abd0b5e27aedcb5fa74877b54bff4ee2 (diff)
downloadeeshow-15af44aef6076907cf04ae27cb850f49f3b70ed7.tar.gz
eeshow-15af44aef6076907cf04ae27cb850f49f3b70ed7.tar.bz2
eeshow-15af44aef6076907cf04ae27cb850f49f3b70ed7.zip
eeshow/gfx/pdftoc.c (write_trailer): walking pointer is a bad idea if we realloc
Diffstat (limited to 'gfx')
-rw-r--r--gfx/pdftoc.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/gfx/pdftoc.c b/gfx/pdftoc.c
index c24d0d4..dae3790 100644
--- a/gfx/pdftoc.c
+++ b/gfx/pdftoc.c
@@ -248,9 +248,9 @@ static void write_trailer(struct pdftoc *ctx)
{
unsigned n = ctx->top + 1;
const struct object *obj = ctx->objs;
- const struct object *end = ctx->objs + ctx->top + 1;
const struct title *t;
unsigned outline, tail;
+ int i;
/* Outline root */
@@ -267,10 +267,12 @@ static void write_trailer(struct pdftoc *ctx)
/* Outline items */
n++;
+ i = 0;
for (t = ctx->titles; t; t = t->next) {
- while (!obj->is_page) {
- assert(obj != end);
- obj++;
+ assert(i <= ctx->top);
+ while (!ctx->objs[i].is_page) {
+ i++;
+ assert(i <= ctx->top);
}
add_object(ctx, n, 0, ctx->pos + tail);
tail += fprintf(ctx->file,
@@ -285,11 +287,11 @@ static void write_trailer(struct pdftoc *ctx)
tail += fprintf(ctx->file,
" /Next %u 0 R\n", n + 1);
tail += fprintf(ctx->file,
- " /Dest [%u %u R /Fit]\n"
+ " /Dest [%d %u R /Fit]\n"
">>\nendobj\n",
- (unsigned) (obj - ctx->objs), obj->gen);
+ i, ctx->objs[i].gen);
n++;
- obj++;
+ i++;
}
/* xref table */