Commit f5e02eb5 authored by Markus Steinborn's avatar Markus Steinborn Committed by Bernhard Link

Do not segfault on buggy postscript files, i. e. files

i. e. files where the page number iin DSC comments is missing.

Fixes debian bug #729618: gv: segv on certain blank line
parent 2f0ceb37
......@@ -84,7 +84,9 @@ doc_scanFile(fPP,docP,filename,filename_raw,filename_dscP,cmd_scan_pdf,filename_
ret = d->structured = 1;
if (d->numpages == 1) d->labels_useful=1;
else for (i = 1; i < d->numpages; i++)
if (strcmp(d->pages[i-1].label,d->pages[i].label)) { d->labels_useful = 1; break; }
if (d->pages[i-1].label && d->pages[i].label) {
if (strcmp(d->pages[i-1].label,d->pages[i].label)) { d->labels_useful = 1; break; }
}
}
}
*docP = d;
......
......@@ -995,8 +995,11 @@ setup_ghostview(void)
INFMESSAGE(toc available)
if (doc->labels_useful) {
for (i = 0; i < doc->numpages; i++)
maxlen = max(maxlen, (int)strlen(doc->pages[i].label));
for (i = 0; i < doc->numpages; i++)
if (doc->pages[i].label)
maxlen = max(maxlen, (int)strlen(doc->pages[i].label));
else
maxlen = max(maxlen, log10((double) doc->numpages) + 2);
} else {
double x;
x = doc->numpages;
......@@ -1014,7 +1017,10 @@ setup_ghostview(void)
} else {
j = i;
}
sprintf(tocp, "%*s\n", maxlen, doc->pages[j].label);
if (doc->pages[j].label)
sprintf(tocp, "%*s\n", maxlen, doc->pages[j].label);
else
sprintf(tocp, "?%*d\n", maxlen-1, i+1);
} else {
sprintf(tocp, "%*d\n", maxlen, i+1);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment