From 91473d5f1fa4f5e83430127f82ec336551db3f28 Mon Sep 17 00:00:00 2001 From: "Sven M. Hallberg" <pesco@khjk.org> Date: Tue, 28 Mar 2023 17:44:29 +0000 Subject: [PATCH] restore single exit point in parse_xrefs It turns out that this function was in fact meant to always assign a result (NULL/0 on failure), accomplished by having a single exit point. This was changed in 517b81ad for no reason. Reverting. I'm guessing the goto was considered disagreeable, so I'll explain the rationale. The function accumulates its result in the *local* variables xrefs and n. This mainly makes the code nicer to read than writing to the output directly. Having a single exit point, a property that is easy to verify, ensures that no update to the local variables can get lost, i.e. they serve as de-facto aliases for the outputs. --- pdf.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pdf.c b/pdf.c index a193e66..3b28218 100644 --- a/pdf.c +++ b/pdf.c @@ -4909,7 +4909,7 @@ parse_xrefs(struct Env *aux) } if (res == NULL) { log_message(5, "VIOLATION[5]: startxref not found\n"); - return; + goto end; } offset = H_INDEX_UINT(res->ast, 0); @@ -4921,7 +4921,7 @@ parse_xrefs(struct Env *aux) if ( (offset <=0) || (offset >= aux->sz) ) { log_message(5, "VIOLATION[5]: Invalid xref table offset = %ld. Valid range <0, %ld>\n", offset, aux->sz); - return; + goto end; } // XXX try formulating this loop as one parser using h_seek and h_bind @@ -4976,6 +4976,7 @@ parse_xrefs(struct Env *aux) offset = (size_t)tok->sint; } +end: aux->xrefs = xrefs; aux->nxrefs = n; } -- GitLab