From 1251312a101f9fe18de9ece6961c9ea7e95a3dfc Mon Sep 17 00:00:00 2001 From: Kamil Kasperczyk <66371704+kkasperczyk-no@users.noreply.github.com> Date: Thu, 19 May 2022 16:55:03 +0200 Subject: [PATCH] [setup_payload] Fixed bug with not reducing span size properly (#18598) Output buffer span is not reduced properly, as subspan is passed to the base38Encode method and changed size doesn't propagate to the outBuffer. Added reducing outBuffer size to the subSpan + prefixLen size. --- src/setup_payload/QRCodeSetupPayloadGenerator.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/setup_payload/QRCodeSetupPayloadGenerator.cpp b/src/setup_payload/QRCodeSetupPayloadGenerator.cpp index c8e7dc7fc1b2ad..976e443afa2c89 100644 --- a/src/setup_payload/QRCodeSetupPayloadGenerator.cpp +++ b/src/setup_payload/QRCodeSetupPayloadGenerator.cpp @@ -196,6 +196,8 @@ static CHIP_ERROR payloadBase38RepresentationWithTLV(PayloadContents & payload, MutableCharSpan subSpan = outBuffer.SubSpan(prefixLen, outBuffer.size() - prefixLen); memcpy(outBuffer.data(), kQRCodePrefix, prefixLen); err = base38Encode(bits, subSpan); + // Reduce output span size to be the size of written data + outBuffer.reduce_size(subSpan.size() + prefixLen); } return err;