From 9883a543682945509e8b20b5e9444e1b52876a09 Mon Sep 17 00:00:00 2001 From: "Sven M. Hallberg" <pesco@khjk.org> Date: Tue, 28 Mar 2023 17:44:30 +0000 Subject: [PATCH] revert parse_xrefs to its original signature Passing the aux struct by reference may look cleaner, but it was deliberate to keep parse_xrefs() independent of that struct, since the latter is conceptually part of the parser's interface and the former is not. Also, this way parse_xrefs() has a proper return value that signals success or failure. Plus, no ugly indirection or temporary variable is needed to access sz. --- pdf.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pdf.c b/pdf.c index 1761f14..112a0d5 100644 --- a/pdf.c +++ b/pdf.c @@ -4947,13 +4947,13 @@ dumpstream(FILE *f, const HParsedToken *obj) * Allocates and returns an array of HParsedTokens, each containing the result * of a successful 'p_xref' parse. Sets the output parameter 'nxrefs' to the * number of elements. + * + * A return value of NULL indicates an empty result. */ // XXX review changes to this function. see git -L /^parse_xrefs/,/^}/:pdf.c' -void -parse_xrefs(struct Env *aux) +const HParsedToken ** +parse_xrefs(const uint8_t *input, size_t sz, size_t *nxrefs) { - const uint8_t *input = aux->input; - size_t sz = aux->sz; HParseResult *res = NULL; const HParsedToken **xrefs = NULL; /* empty result */ const HParsedToken *tok = NULL; @@ -4978,9 +4978,9 @@ parse_xrefs(struct Env *aux) // verify the offset recovered is bounded to be in the file // XXX this check is already present below by virtue of h_seek() - if ( (offset <=0) || (offset >= aux->sz) ) { + if ( (offset <=0) || (offset >= sz) ) { log_message(5, "VIOLATION[5]: Invalid xref table offset = %ld. Valid range <0, %ld>\n", - offset, aux->sz); + offset, sz); goto end; } @@ -5037,8 +5037,8 @@ parse_xrefs(struct Env *aux) } end: - aux->xrefs = xrefs; - aux->nxrefs = n; + *nxrefs = n; + return xrefs; } int @@ -5139,7 +5139,7 @@ main(int argc, char *argv[]) init_LZW_parser(); /* parse all cross-reference sections and trailer dictionaries */ - parse_xrefs(&aux); + aux.xrefs = parse_xrefs(input, sz, &aux.nxrefs); /* run the main parser */ aux.stmparse = 1; /* parse stream data? */ -- GitLab