From 3ec3b469b8d091837a1d1309ac0cdffa6a76e1d4 Mon Sep 17 00:00:00 2001 From: Leon George Date: Sun, 23 Oct 2022 13:47:23 +0200 Subject: [PATCH] ws: fix compile error on centos 7 - very old compiler (#1359) * http: fix typo * ws: fix comile error On CentOS: CC ws.lo ws.c: In function 'get_ws_frame': ws.c:244:3: error: 'for' loop initial declarations are only allowed in C99 mode for (int i = 0; i < payload_len; i++) { ^ ws.c:244:3: note: use option -std=c99 or -std=gnu99 to compile your code --- http.c | 2 +- test/regress_ws.c | 6 ++++-- ws.c | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/http.c b/http.c index bd975656..aeeab4ac 100644 --- a/http.c +++ b/http.c @@ -741,7 +741,7 @@ evhttp_connection_incoming_fail(struct evhttp_request *req, * case may happen when a browser keeps a persistent * connection open and we timeout on the read. when * the request is still being used for sending, we - * need to disassociated it from the connection here. + * need to disassociate it from the connection here. */ if (!req->userdone) { /* remove it so that it will not be freed */ diff --git a/test/regress_ws.c b/test/regress_ws.c index 29850be8..df4a84e7 100644 --- a/test/regress_ws.c +++ b/test/regress_ws.c @@ -144,6 +144,7 @@ receive_ws_msg(struct evbuffer *buf, size_t *out_len, unsigned *options) const unsigned char *mask_key; char *out_buf = NULL; size_t data_len = evbuffer_get_length(buf); + size_t i; data = evbuffer_pullup(buf, data_len); @@ -177,7 +178,7 @@ receive_ws_msg(struct evbuffer *buf, size_t *out_len, unsigned *options) return NULL; mask_key = data + header_len - 4; - for (size_t i = 0; mask && i < payload_len; i++) + for (i = 0; mask && i < payload_len; i++) data[header_len + i] ^= mask_key[i % 4]; *out_len = payload_len; @@ -205,6 +206,7 @@ send_ws_msg(struct evbuffer *buf, const char *msg, bool final) uint8_t a = 0, b = 0, c = 0, d = 0; uint8_t mask_key[4] = {1, 2, 3, 4}; /* should be random */ uint8_t m; + size_t i; if (final) a |= 1 << 7; /* fin */ @@ -233,7 +235,7 @@ send_ws_msg(struct evbuffer *buf, const char *msg, bool final) evbuffer_add(buf, &mask_key, 4); - for (size_t i = 0; i < len; i++) { + for (i = 0; i < len; i++) { m = msg[i] ^ mask_key[i % 4]; evbuffer_add(buf, &m, 1); } diff --git a/ws.c b/ws.c index de5cf6de..5acaf783 100644 --- a/ws.c +++ b/ws.c @@ -236,13 +236,14 @@ get_ws_frame(unsigned char *in_buffer, int buf_len, unsigned char **payload_ptr, */ if (masked) { unsigned char *c; + int i; mask = *((unsigned int *)(in_buffer + pos)); pos += 4; /* unmask data */ c = in_buffer + pos; - for (int i = 0; i < payload_len; i++) { + for (i = 0; i < payload_len; i++) { c[i] = c[i] ^ ((unsigned char *)(&mask))[i % 4]; } }