SF Bug Tracker id 3499781 - msvc doesn't have snprintf
Submitted: Yoichi NAKAYAMA ( yoichi ) - 2012-03-08 10:18:39 PST
97a17ff5ad commit breaks build on
windows/msvc since there is no snprintf.
Note:
* Some existing sources use _snprintf when WIN32 is defined, but its
behavior is a bit different from C99 snprintf.
* snprintf does terminate the buffer, so the commit (use buffer size
minus 1 as argument) changes the behavior at the boundary.
* Truncation might be better than crash in some cases. But it may
result in not good.
This commit is contained in:
@@ -59,6 +59,7 @@
|
||||
|
||||
#ifdef WIN32
|
||||
#include <string.h>
|
||||
#define snprintf _snprintf
|
||||
#endif /* WIN32 */
|
||||
|
||||
/*!
|
||||
@@ -323,23 +324,22 @@ static void CreateClientRequestPacket(
|
||||
strcpy(RqstBuf, "M-SEARCH * HTTP/1.1\r\n");
|
||||
|
||||
if (AddressFamily == AF_INET) {
|
||||
snprintf(TempBuf, sizeof(TempBuf) - 1, "HOST: %s:%d\r\n",
|
||||
SSDP_IP, SSDP_PORT);
|
||||
snprintf(TempBuf, sizeof(TempBuf), "HOST: %s:%d\r\n", SSDP_IP,
|
||||
SSDP_PORT);
|
||||
} else if (AddressFamily == AF_INET6) {
|
||||
snprintf(TempBuf, sizeof(TempBuf) - 1, "HOST: [%s]:%d\r\n",
|
||||
snprintf(TempBuf, sizeof(TempBuf), "HOST: [%s]:%d\r\n",
|
||||
SSDP_IPV6_LINKLOCAL, SSDP_PORT);
|
||||
}
|
||||
strcat(RqstBuf, TempBuf);
|
||||
strcat(RqstBuf, "MAN: \"ssdp:discover\"\r\n");
|
||||
|
||||
if (Mx > 0) {
|
||||
snprintf(TempBuf, sizeof(TempBuf) - 1, "MX: %d\r\n", Mx);
|
||||
snprintf(TempBuf, sizeof(TempBuf), "MX: %d\r\n", Mx);
|
||||
strcat(RqstBuf, TempBuf);
|
||||
}
|
||||
|
||||
if (SearchTarget != NULL) {
|
||||
snprintf(TempBuf, sizeof(TempBuf) - 1, "ST: %s\r\n",
|
||||
SearchTarget);
|
||||
snprintf(TempBuf, sizeof(TempBuf), "ST: %s\r\n", SearchTarget);
|
||||
strcat(RqstBuf, TempBuf);
|
||||
}
|
||||
strcat(RqstBuf, "\r\n");
|
||||
@@ -363,21 +363,20 @@ static void CreateClientRequestPacketUlaGua(
|
||||
memset(TempBuf, 0, sizeof(TempBuf));
|
||||
strcpy(RqstBuf, "M-SEARCH * HTTP/1.1\r\n");
|
||||
if (AddressFamily == AF_INET) {
|
||||
snprintf(TempBuf, sizeof(TempBuf) - 1, "HOST: %s:%d\r\n",
|
||||
SSDP_IP, SSDP_PORT);
|
||||
snprintf(TempBuf, sizeof(TempBuf), "HOST: %s:%d\r\n", SSDP_IP,
|
||||
SSDP_PORT);
|
||||
} else if (AddressFamily == AF_INET6) {
|
||||
snprintf(TempBuf, sizeof(TempBuf) - 1, "HOST: [%s]:%d\r\n",
|
||||
snprintf(TempBuf, sizeof(TempBuf), "HOST: [%s]:%d\r\n",
|
||||
SSDP_IPV6_SITELOCAL, SSDP_PORT);
|
||||
}
|
||||
strcat(RqstBuf, TempBuf);
|
||||
strcat(RqstBuf, "MAN: \"ssdp:discover\"\r\n");
|
||||
if (Mx > 0) {
|
||||
snprintf(TempBuf, sizeof(TempBuf) - 1, "MX: %d\r\n", Mx);
|
||||
snprintf(TempBuf, sizeof(TempBuf), "MX: %d\r\n", Mx);
|
||||
strcat(RqstBuf, TempBuf);
|
||||
}
|
||||
if (SearchTarget) {
|
||||
snprintf(TempBuf, sizeof(TempBuf) - 1, "ST: %s\r\n",
|
||||
SearchTarget);
|
||||
snprintf(TempBuf, sizeof(TempBuf), "ST: %s\r\n", SearchTarget);
|
||||
strcat(RqstBuf, TempBuf);
|
||||
}
|
||||
strcat(RqstBuf, "\r\n");
|
||||
|
||||
Reference in New Issue
Block a user