Skip to content

Commit 31d1a06

Browse files
Fix Windows warning about snprintf
1 parent 2f16b09 commit 31d1a06

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/proxy_protocol.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@
2121
#include <string.h>
2222
#ifdef _WIN32
2323
#include <ws2tcpip.h>
24+
/* Caution: To be used only with fixed length arrays */
25+
#define _sprintf(buffer, format, ...) sprintf_s(buffer, sizeof(buffer), format, __VA_ARGS__)
2426
#else
2527
#include <arpa/inet.h>
28+
/* sprintf() as snprintf does not exist in ANSI C */
29+
#define _sprintf(buffer, format, ...) sprintf(buffer, format, __VA_ARGS__)
2630
#endif
2731

2832
#include "proxy_protocol.h"
@@ -763,8 +767,7 @@ static uint8_t *pp1_create_hdr(const pp_info_t *pp_info, uint16_t *pp1_hdr_len,
763767
char dst_addr[39+1];
764768
memcpy(src_addr, pp_info->src_addr, sizeof(src_addr));
765769
memcpy(dst_addr, pp_info->dst_addr, sizeof(dst_addr));
766-
/* sprintf() as snprintf does not exist in ANSI C */
767-
*pp1_hdr_len = sprintf(block, "PROXY %s %s %s %hu %hu"CRLF, fam, src_addr, dst_addr, pp_info->src_port, pp_info->dst_port);
770+
*pp1_hdr_len = _sprintf(block, "PROXY %s %s %s %hu %hu"CRLF, fam, src_addr, dst_addr, pp_info->src_port, pp_info->dst_port);
768771
}
769772
else
770773
{

0 commit comments

Comments
 (0)