From 351fc9354772b6b9763d1816d70726000b4b2020 Mon Sep 17 00:00:00 2001 From: mikamikasuki <211269698+mikamikasuki@users.noreply.github.com> Date: Fri, 2 Oct 2026 08:04:55 -0700 Subject: [PATCH] Fix the prefix for three-byte ECI assignments --- qrinput.c | 2 +- tests/test_qrinput.c | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/qrinput.c b/qrinput.c index 34bedc2a..e8365392 100644 --- a/qrinput.c +++ b/qrinput.c @@ -800,7 +800,7 @@ static int QRinput_encodeModeECI(QRinput_List *entry, BitStream *bstream) code = 0x8000 + ecinum; } else { words = 3; - code = 0xc0000 + ecinum; + code = 0xc00000 + ecinum; } ret = BitStream_appendNum(bstream, 4, QRSPEC_MODEID_ECI); diff --git a/tests/test_qrinput.c b/tests/test_qrinput.c index b1ac5a98..48c5f03b 100644 --- a/tests/test_qrinput.c +++ b/tests/test_qrinput.c @@ -1047,6 +1047,40 @@ static void test_ECIinvalid(void) testFinish(); } +static void test_encodeECIrange(void) +{ + const struct { + unsigned int ecinum; + char *bits; + } cases[] = { + {0, "0111 00000000"}, + {127, "0111 01111111"}, + {128, "0111 10000000 10000000"}, + {16383, "0111 10111111 11111111"}, + {16384, "0111 11000000 01000000 00000000"}, + {999999, "0111 11001111 01000010 00111111"} + }; + QRinput *input; + BitStream *bstream; + size_t i; + int ret; + + testStart("Encoding ECI headers at assignment range boundaries."); + for(i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) { + input = QRinput_new(); + ret = QRinput_appendECIheader(input, cases[i].ecinum); + assert_zero(ret, "Valid ECI assignment %u rejected.\n", cases[i].ecinum); + bstream = BitStream_new(); + ret = QRinput_mergeBitStream(input, bstream); + assert_zero(ret, "Failed to merge ECI assignment %u.\n", cases[i].ecinum); + ret = cmpBin(cases[i].bits, bstream); + assert_zero(ret, "ECI assignment %u incorrectly encoded.\n", cases[i].ecinum); + BitStream_free(bstream); + QRinput_free(input); + } + testFinish(); +} + static void test_encodeECI(void) { QRinput *input; @@ -1076,7 +1110,7 @@ static void test_encodeECI(void) int main() { - int tests = 42; + int tests = 43; testInit(tests); test_encodeNumeric(); @@ -1121,6 +1155,7 @@ int main() test_textMQR(); test_ECIinvalid(); + test_encodeECIrange(); test_encodeECI(); testReport(tests);