From e1d957b90ae8df1aaf8693150f9a77fb118524aa Mon Sep 17 00:00:00 2001
From: "Sven M. Hallberg" <pesco@khjk.org>
Date: Tue, 14 Mar 2023 17:02:45 +0000
Subject: [PATCH] no need to check for presence of trailer dictionary

The parser does this for us, duh (rule xr_td): If there is an xref
section, it is composed of xref entries and a trailer dictionary.
We can use the H_INDEX() macro to access it and cast to the desired
token type, which also includes all appropriate assertions.
---
 pdf.c | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/pdf.c b/pdf.c
index 72d1ed3..6502f70 100644
--- a/pdf.c
+++ b/pdf.c
@@ -4360,24 +4360,15 @@ parse_catalog(struct Env *aux, const HParsedToken *root)
 void
 process_page_content(struct Env *aux)
 {
-	const HParsedToken *tok, *xref;
+	const HParsedToken *tok;
 	Dict *trailer;
 	size_t Size;
 
-	/* use the last xref section */
+	/* find the last trailer dictionary */
 	if (aux->nxrefs == 0)
 		return;
-	xref = aux->xrefs[aux->nxrefs - 1];
-
-	/* make sure we parsed a valid trailer dictionary */
-	tok = H_INDEX_TOKEN(xref, 1);
-	trailer = H_CAST(Dict, tok);
-	if (trailer == NULL) {
-		// XXX this cannot actually happen (rule xr_td)
-		log_message(7, "VIOLATION[7]: Invalid Trailer Section "
-		    "or Trailer Section not found\n");
-		return;
-	}
+	tok = aux->xrefs[aux->nxrefs - 1];	/* last xref section */
+	trailer = H_INDEX(Dict, tok, 1);
 
 	/* fetch Size (a required field) from the trailer dictionary */
 	tok = dictentry(trailer, "Size");
-- 
GitLab