Skip to content

Commit 5a9623a

Browse files
authored
Fix compiler warnings in websocket_to_posix_proxy. NFC (#20256)
1 parent 1618aa6 commit 5a9623a

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

tools/websocket_to_posix_proxy/CMakeLists.txt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ cmake_minimum_required(VERSION 2.8.12)
22

33
project(websocket_to_posix_proxy)
44

5+
if (WIN32)
6+
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
7+
add_compile_options(/wd4200) # "nonstandard extension used: zero-sized array in struct/union"
8+
target_link_libraries(websocket_to_posix_proxy Ws2_32.lib)
9+
else()
10+
add_compile_options(-Werror -Wall)
11+
endif()
12+
513
file(GLOB sourceFiles src/*.cpp src/*.c src/*.h)
614

715
add_executable(websocket_to_posix_proxy ${sourceFiles})
816

917
find_package(Threads)
1018
target_link_libraries(websocket_to_posix_proxy ${CMAKE_THREAD_LIBS_INIT})
11-
12-
if (WIN32)
13-
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
14-
add_definitions(/wd4200) # "nonstandard extension used: zero-sized array in struct/union"
15-
target_link_libraries(websocket_to_posix_proxy Ws2_32.lib)
16-
endif()

tools/websocket_to_posix_proxy/src/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ bool WebSocketValidateMessageSize(uint8_t *data, uint64_t obtainedNumBytes) {
110110
uint64_t expectedNumBytes = WebSocketFullMessageSize(data, obtainedNumBytes);
111111

112112
if (expectedNumBytes != obtainedNumBytes) {
113-
printf("Corrupt WebSocket message size! (got %llu bytes, expected %llu bytes)\n", obtainedNumBytes, expectedNumBytes);
113+
printf("Corrupt WebSocket message size! (got %lu bytes, expected %lu bytes)\n", obtainedNumBytes, expectedNumBytes);
114114
printf("Received data:");
115115
for (size_t i = 0; i < obtainedNumBytes; ++i)
116116
printf(" %02X", data[i]);
@@ -187,14 +187,14 @@ void DumpWebSocketMessage(uint8_t *data, uint64_t numBytes) {
187187
uint64_t payloadLength = WebSocketMessagePayloadLength(data, numBytes);
188188
uint8_t *payload = WebSocketMessageData(data, numBytes);
189189

190-
printf("Received: FIN: %d, opcode: %s, mask: 0x%08X, payload length: %llu bytes, unmasked payload:", header->fin, WebSocketOpcodeToString(header->opcode),
190+
printf("Received: FIN: %d, opcode: %s, mask: 0x%08X, payload length: %lu bytes, unmasked payload:", header->fin, WebSocketOpcodeToString(header->opcode),
191191
WebSocketMessageMaskingKey(data, numBytes), payloadLength);
192192
for (uint64_t i = 0; i < payloadLength; ++i) {
193193
if (i%16 == 0) printf("\n");
194194
if (i%8==0) printf(" ");
195195
printf(" %02X", payload[i]);
196196
if (i >= 63 && payloadLength > 64) {
197-
printf("\n ... (%llu more bytes)", payloadLength-i);
197+
printf("\n ... (%lu more bytes)", payloadLength-i);
198198
break;
199199
}
200200
}

tools/websocket_to_posix_proxy/src/websocket_to_posix_proxy.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ typedef struct SocketCallHeader {
6161
int function;
6262
} SocketCallHeader;
6363

64-
static char buf_temp_str[2048] = {};
65-
64+
#ifdef POSIX_SOCKET_DEBUG
6665
// not thread-safe, but only used for debug prints, so expected not to cause
6766
// trouble
6867
static char *BufferToString(const void *buf, size_t len) {
68+
static char buf_temp_str[2048] = {};
6969
uint8_t *b = (uint8_t *)buf;
7070
if (!b) {
7171
sprintf(buf_temp_str, "(null ptr) (%d bytes)", (int)len);
@@ -78,6 +78,7 @@ static char *BufferToString(const void *buf, size_t len) {
7878
sprintf(buf_temp_str + len*3, " (%d bytes)", (int)len);
7979
return buf_temp_str;
8080
}
81+
#endif
8182

8283
// thread-safe, re-entrant
8384
void WebSocketMessageUnmaskPayload(uint8_t* payload,

0 commit comments

Comments
 (0)