From f4147621487c0ac4fca5cbe8447e082f31bd0535 Mon Sep 17 00:00:00 2001 From: smiley Date: Sat, 23 Jul 2022 03:56:44 +0200 Subject: [PATCH] :octocat: QRData::setData(): clear BitBuffer before write --- src/Common/BitBuffer.php | 12 ++++++++++++ src/Data/QRData.php | 3 +++ 2 files changed, 15 insertions(+) diff --git a/src/Common/BitBuffer.php b/src/Common/BitBuffer.php index 26d5c69bb..cd79bd95e 100644 --- a/src/Common/BitBuffer.php +++ b/src/Common/BitBuffer.php @@ -155,4 +155,16 @@ final class BitBuffer{ return $result; } + /** + * Clears the buffer and resets the stats + */ + public function clear():self{ + $this->buffer = []; + $this->length = 0; + $this->bytesRead = 0; + $this->bitsRead = 0; + + return $this; + } + } diff --git a/src/Data/QRData.php b/src/Data/QRData.php index d389cf06f..943433c00 100644 --- a/src/Data/QRData.php +++ b/src/Data/QRData.php @@ -74,6 +74,8 @@ final class QRData{ /** * Sets the data string (internally called by the constructor) + * + * Subsequent calls will overwrite the current state - use the QRCode::add*Segement() method instead */ public function setData(array $dataSegments):self{ $this->dataSegments = $dataSegments; @@ -84,6 +86,7 @@ final class QRData{ $this->version = new Version($version); + $this->bitBuffer->clear(); $this->writeBitBuffer(); return $this;