From cd0297314e1bb92d091aa5af38f6c7a32c0aa814 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 8 Apr 2021 21:39:57 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=AE=98=E6=96=B9?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E7=9A=84pr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +++--- README_ZH.md | 6 +++--- src/qrcode.c | 8 +++++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index b200896..1308bb4 100644 --- a/README.md +++ b/README.md @@ -64,9 +64,9 @@ qrcode_initText(&qrcode, qrcodeBytes, DEFAULT_QR_VERSION, ECC_LOW, "HELLO WORLD" The generated two-dimensional code is dot matrix data, 8 dots constitute a Byte. The following codes can be used to display the QR code ```c -for (uint8 y = 0; y bitOffsetOrWidth; for (int8_t i = length - 1; i >= 0; i--, offset++) { - bitBuffer->data[offset >> 3] |= ((val >> i) & 1) << (7 - (offset & 7)); + if (bitBuffer->capacityBytes > offset >> 3) { + bitBuffer->data[offset >> 3] |= ((val >> i) & 1) << (7 - (offset & 7)); + } } bitBuffer->bitOffsetOrWidth = offset; } @@ -739,7 +741,6 @@ uint16_t qrcode_getBufferSize(uint8_t version) { return bb_getGridSizeBytes(4 * version + 17); } -// @TODO: Return error if data is too big. int8_t qrcode_initBytes(QRCode *qrcode, uint8_t *modules, uint8_t version, uint8_t ecc, uint8_t *data, uint16_t length) { uint8_t size = version * 4 + 17; qrcode->version = version; @@ -773,7 +774,8 @@ int8_t qrcode_initBytes(QRCode *qrcode, uint8_t *modules, uint8_t version, uint8 qrcode->mode = mode; // Add terminator and pad up to a byte if applicable - uint32_t padding = (dataCapacity * 8) - codewords.bitOffsetOrWidth; + int32_t padding = (dataCapacity * 8) - codewords.bitOffsetOrWidth; + if (padding < 0) { return -1; } if (padding > 4) { padding = 4; } bb_appendBits(&codewords, 0, padding); bb_appendBits(&codewords, 0, (8 - codewords.bitOffsetOrWidth % 8) % 8); From 8b7f0613f3f6f96d9243abc3745335a789e775d2 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 8 Apr 2021 21:42:01 +0800 Subject: [PATCH 2/2] formatted --- samples/qrcode_sample.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/qrcode_sample.c b/samples/qrcode_sample.c index 655b48a..d5148d5 100644 --- a/samples/qrcode_sample.c +++ b/samples/qrcode_sample.c @@ -53,4 +53,4 @@ static void qrcode(uint8_t argc, char **argv) } } MSH_CMD_EXPORT(qrcode, qrcode generator: qrcode [string]); -#endif /* defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) */ \ No newline at end of file +#endif /* defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) */