From bfd921df9c79c1b0cf8cf5040ceffdf5fd7d221a Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 3 May 2022 13:25:04 +0100 Subject: [PATCH] clean: remove needless LWS_PRE Several examples trim their buffer with an extra LWS_PRE from the end... actually end should point to end the end of buf without a second LWS_PRE reservation. https://github.com/warmcat/libwebsockets/issues/2629 --- .../minimal-http-client-multi/minimal-http-client-multi.c | 2 +- .../minimal-http-client-post/minimal-http-client-post.c | 2 +- .../minimal-http-server-custom-headers.c | 2 +- .../minimal-http-server-dynamic/minimal-http-server-dynamic.c | 2 +- .../minimal-http-server-h2-long-poll/minimal-http-server.c | 2 +- plugins/acme-client/protocol_lws_acme_client.c | 2 +- plugins/deaddrop/protocol_lws_deaddrop.c | 2 +- plugins/protocol_fulltext_demo.c | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/minimal-examples/http-client/minimal-http-client-multi/minimal-http-client-multi.c b/minimal-examples/http-client/minimal-http-client-multi/minimal-http-client-multi.c index d0d11f3fe..f30ee589b 100644 --- a/minimal-examples/http-client/minimal-http-client-multi/minimal-http-client-multi.c +++ b/minimal-examples/http-client/minimal-http-client-multi/minimal-http-client-multi.c @@ -167,7 +167,7 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len) { char buf[LWS_PRE + 1024], *start = &buf[LWS_PRE], *p = start, - *end = &buf[sizeof(buf) - LWS_PRE - 1]; + *end = &buf[sizeof(buf) - 1]; int n, idx = (int)(intptr_t)lws_get_opaque_user_data(wsi); struct pss *pss = (struct pss *)user; diff --git a/minimal-examples/http-client/minimal-http-client-post/minimal-http-client-post.c b/minimal-examples/http-client/minimal-http-client-post/minimal-http-client-post.c index 3bff115a6..063f8f1cd 100644 --- a/minimal-examples/http-client/minimal-http-client-post/minimal-http-client-post.c +++ b/minimal-examples/http-client/minimal-http-client-post/minimal-http-client-post.c @@ -30,7 +30,7 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason, { struct pss *pss = (struct pss *)user; char buf[LWS_PRE + 1024], *start = &buf[LWS_PRE], *p = start, - *end = &buf[sizeof(buf) - LWS_PRE - 1]; + *end = &buf[sizeof(buf) - 1]; int n; switch (reason) { diff --git a/minimal-examples/http-server/minimal-http-server-custom-headers/minimal-http-server-custom-headers.c b/minimal-examples/http-server/minimal-http-server-custom-headers/minimal-http-server-custom-headers.c index d9a1f31ab..4ffe32c1f 100644 --- a/minimal-examples/http-server/minimal-http-server-custom-headers/minimal-http-server-custom-headers.c +++ b/minimal-examples/http-server/minimal-http-server-custom-headers/minimal-http-server-custom-headers.c @@ -37,7 +37,7 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len) { uint8_t buf[LWS_PRE + 2048], *start = &buf[LWS_PRE], *p = start, - *end = &buf[sizeof(buf) - LWS_PRE - 1]; + *end = &buf[sizeof(buf) - 1]; struct pss *pss = (struct pss *)user; char value[32], *pr = &pss->result[LWS_PRE]; size_t e = sizeof(pss->result) - LWS_PRE; diff --git a/minimal-examples/http-server/minimal-http-server-dynamic/minimal-http-server-dynamic.c b/minimal-examples/http-server/minimal-http-server-dynamic/minimal-http-server-dynamic.c index f919146b3..daade23b7 100644 --- a/minimal-examples/http-server/minimal-http-server-dynamic/minimal-http-server-dynamic.c +++ b/minimal-examples/http-server/minimal-http-server-dynamic/minimal-http-server-dynamic.c @@ -42,7 +42,7 @@ callback_dynamic_http(struct lws *wsi, enum lws_callback_reasons reason, { struct pss *pss = (struct pss *)user; uint8_t buf[LWS_PRE + 2048], *start = &buf[LWS_PRE], *p = start, - *end = &buf[sizeof(buf) - LWS_PRE - 1]; + *end = &buf[sizeof(buf) - 1]; time_t t; int n; #if defined(LWS_HAVE_CTIME_R) diff --git a/minimal-examples/http-server/minimal-http-server-h2-long-poll/minimal-http-server.c b/minimal-examples/http-server/minimal-http-server-h2-long-poll/minimal-http-server.c index c5614e559..a47be0b2a 100644 --- a/minimal-examples/http-server/minimal-http-server-h2-long-poll/minimal-http-server.c +++ b/minimal-examples/http-server/minimal-http-server-h2-long-poll/minimal-http-server.c @@ -57,7 +57,7 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, struct pss * pss = (struct pss *)user; uint8_t buf[LWS_PRE + LWS_RECOMMENDED_MIN_HEADER_SPACE], *start = &buf[LWS_PRE], *p = start, - *end = p + sizeof(buf) - LWS_PRE; + *end = buf + sizeof(buf) - 1; int m, n; switch (reason) { diff --git a/plugins/acme-client/protocol_lws_acme_client.c b/plugins/acme-client/protocol_lws_acme_client.c index f6be2b012..729c4482e 100644 --- a/plugins/acme-client/protocol_lws_acme_client.c +++ b/plugins/acme-client/protocol_lws_acme_client.c @@ -136,7 +136,7 @@ callback_chall_http01(struct lws *wsi, enum lws_callback_reasons reason, struct lws_vhost *vhost = lws_get_vhost(wsi); struct acme_connection *ac = lws_vhost_user(vhost); uint8_t buf[LWS_PRE + 2048], *start = &buf[LWS_PRE], *p = start, - *end = &buf[sizeof(buf) - LWS_PRE - 1]; + *end = &buf[sizeof(buf) - 1]; int n; switch (reason) { diff --git a/plugins/deaddrop/protocol_lws_deaddrop.c b/plugins/deaddrop/protocol_lws_deaddrop.c index 79f736c0a..0e51507b6 100644 --- a/plugins/deaddrop/protocol_lws_deaddrop.c +++ b/plugins/deaddrop/protocol_lws_deaddrop.c @@ -383,7 +383,7 @@ callback_deaddrop(struct lws *wsi, enum lws_callback_reasons reason, struct pss_deaddrop *pss = (struct pss_deaddrop *)user; uint8_t buf[LWS_PRE + LWS_RECOMMENDED_MIN_HEADER_SPACE], *start = &buf[LWS_PRE], *p = start, - *end = &buf[sizeof(buf) - LWS_PRE - 1]; + *end = &buf[sizeof(buf) - 1]; char fname[256], *wp; const char *cp; int n, m, was; diff --git a/plugins/protocol_fulltext_demo.c b/plugins/protocol_fulltext_demo.c index 0d780993b..35d91e196 100644 --- a/plugins/protocol_fulltext_demo.c +++ b/plugins/protocol_fulltext_demo.c @@ -65,7 +65,7 @@ callback_fts(struct lws *wsi, enum lws_callback_reasons reason, void *user, lws_get_protocol(wsi)); struct pss_fts_demo *pss = (struct pss_fts_demo *)user; uint8_t buf[LWS_PRE + 2048], *start = &buf[LWS_PRE], *p = start, - *end = &buf[sizeof(buf) - LWS_PRE - 1]; + *end = &buf[sizeof(buf) - 1]; struct lws_fts_search_params params; const char *ccp = (const char *)in; struct lws_fts_result *result;