diff options
author | DomB <dominik952b@gmail.com> | 2024-01-08 08:26:58 +0100 |
---|---|---|
committer | Andy Green <andy@warmcat.com> | 2024-01-08 09:18:32 +0000 |
commit | 881a0ac34a7d7d48ab00dc21ac39db10f6036942 (patch) | |
tree | 133bb12191315a82bc6646866b32908ef40299fa | |
parent | be473054bd06c3aae7c7258d2a2d282fa657e1c0 (diff) | |
download | libwebsockets-881a0ac34a7d7d48ab00dc21ac39db10f6036942.tar.gz |
lecp: fix format_scan function for numeric longer than 2 digits and negative numbers
-rw-r--r-- | lib/misc/lecp.c | 3 | ||||
-rw-r--r-- | minimal-examples/api-tests/api-test-lecp/main.c | 52 |
2 files changed, 52 insertions, 3 deletions
diff --git a/lib/misc/lecp.c b/lib/misc/lecp.c index 4783241a..eedc4813 100644 --- a/lib/misc/lecp.c +++ b/lib/misc/lecp.c @@ -985,7 +985,7 @@ format_scan(const char *fmt) } if (numeric) { - if (*fmt >= '0' && *fmt <= '9') + while (*fmt >= '0' && *fmt <= '9') fmt++; numeric = 0; if (*fmt != '(') @@ -1119,6 +1119,7 @@ pop: return count[0]; + case '-': case '0': case '1': case '2': diff --git a/minimal-examples/api-tests/api-test-lecp/main.c b/minimal-examples/api-tests/api-test-lecp/main.c index 89133d70..6599ed30 100644 --- a/minimal-examples/api-tests/api-test-lecp/main.c +++ b/minimal-examples/api-tests/api-test-lecp/main.c @@ -4477,7 +4477,11 @@ static const uint8_t w26[] = { 0xF9, 0x3E, 0x00 }, w27[] = { 0xFB, 0x3F, 0xF1, 0xF7, 0xCE, 0xD9, 0x16, 0x87, 0x2B }, w28[] = { 0xA2, 0x61, 0x61, 0x01, 0x61, 0x62, 0x82, 0x02, 0x03 }, - w29[] = { 0x7F, 0x65, 0x68, 0x65, 0x6C, 0x6C, 0x6F, 0xFF + w29[] = { 0x7F, 0x65, 0x68, 0x65, 0x6C, 0x6C, 0x6F, 0xFF }, + w30[] = { 0xA2, 0x63, 0x67, 0x68, 0x69, 0x18, 0x7B, 0x63, 0x6A, 0x6B, 0x6C, 0x02 }, + w31[] = { 0x82, 0x18, 0x81, 0x19, 0x04, 0x00 }, + w32[] = { 0xA2, 0x63, 0x67, 0x68, 0x69, 0x38, 0x7A, 0x63, 0x6A, 0x6B, 0x6C, 0x02 }, + w33[] = { 0x82, 0x38, 0x80, 0x39, 0x03, 0xFF } ; @@ -4604,7 +4608,7 @@ int main(int argc, const char **argv) { int n, m, e = 0, logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE, expected = (int)LWS_ARRAY_SIZE(cbor_tests) + - 29 /* <-- how many write tests */; + 33 /* <-- how many write tests */; struct lecp_ctx ctx; const char *p; @@ -5000,6 +5004,50 @@ int main(int argc, const char **argv) e++; } else pass++; + + lwsl_user("%s: test30\n", __func__); + lws_lec_setbuf(&ctx, buf, sizeof(buf)); + + if (lws_lec_printf(&ctx, "{'ghi':123,'jkl':2}") != + LWS_LECPCTX_RET_FINISHED || + ctx.used != sizeof(w30) || memcmp(w30, buf, ctx.used)) { + lwsl_hexdump_notice(ctx.start, ctx.used); + e++; + } else + pass++; + + lwsl_user("%s: test31\n", __func__); + lws_lec_setbuf(&ctx, buf, sizeof(buf)); + + if (lws_lec_printf(&ctx, "[129,1024]") != + LWS_LECPCTX_RET_FINISHED || + ctx.used != sizeof(w31) || memcmp(w31, buf, ctx.used)) { + lwsl_hexdump_notice(ctx.start, ctx.used); + e++; + } else + pass++; + + lwsl_user("%s: test32\n", __func__); + lws_lec_setbuf(&ctx, buf, sizeof(buf)); + + if (lws_lec_printf(&ctx, "{'ghi':-123,'jkl':2}") != + LWS_LECPCTX_RET_FINISHED || + ctx.used != sizeof(w32) || memcmp(w32, buf, ctx.used)) { + lwsl_hexdump_notice(ctx.start, ctx.used); + e++; + } else + pass++; + + lwsl_user("%s: test33\n", __func__); + lws_lec_setbuf(&ctx, buf, sizeof(buf)); + + if (lws_lec_printf(&ctx, "[-129,-1024]") != + LWS_LECPCTX_RET_FINISHED || + ctx.used != sizeof(w33) || memcmp(w33, buf, ctx.used)) { + lwsl_hexdump_notice(ctx.start, ctx.used); + e++; + } else + pass++; } if (e) |