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
This commit is contained in:
Nick 2022-05-03 13:25:04 +01:00 committed by Andy Green
parent 43ba912b2b
commit 2dc148e3a3
8 changed files with 8 additions and 8 deletions

View File

@ -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;

View File

@ -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) {

View File

@ -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;

View File

@ -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)

View File

@ -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) {

View File

@ -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) {

View File

@ -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;

View File

@ -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;