From 91d17d9f489868523d3578d1a7633091b99d6d5f Mon Sep 17 00:00:00 2001 From: OrbisAI Security Date: Tue, 26 May 2026 02:16:49 +0530 Subject: [PATCH] perf: right-size (#2093) --- lib/OpdsParser/OpdsParser.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/OpdsParser/OpdsParser.cpp b/lib/OpdsParser/OpdsParser.cpp index af619d1c..26cdaed8 100644 --- a/lib/OpdsParser/OpdsParser.cpp +++ b/lib/OpdsParser/OpdsParser.cpp @@ -29,7 +29,8 @@ size_t OpdsParser::write(const uint8_t* xmlData, const size_t length) { constexpr size_t chunkSize = 1024; while (remaining > 0) { - void* const buf = XML_GetBuffer(parser, chunkSize); + const size_t toRead = remaining < chunkSize ? remaining : chunkSize; + void* const buf = XML_GetBuffer(parser, toRead); if (!buf) { errorOccured = true; LOG_DBG("OPDS", "Couldn't allocate memory for buffer"); @@ -37,7 +38,6 @@ size_t OpdsParser::write(const uint8_t* xmlData, const size_t length) { return length; } - const size_t toRead = remaining < chunkSize ? remaining : chunkSize; memcpy(buf, currentPos, toRead); if (XML_ParseBuffer(parser, static_cast(toRead), 0) == XML_STATUS_ERROR) {