From 01eff6bc6bf88f7d71dff76083d4f1c89c1c642d Mon Sep 17 00:00:00 2001 From: Laurens Voerman Date: Wed, 14 Feb 2018 10:38:09 +0100 Subject: [PATCH] fix visual studio compile warnings for ZeroConfDevice project. --- .../ZeroConfDevice/AutoDiscoveryWinImpl.cpp | 2 +- src/osgPlugins/ZeroConfDevice/CMakeLists.txt | 4 ++++ .../ZeroConfDevice/mdns_win/dns-sd.c | 20 ++++++++++--------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/osgPlugins/ZeroConfDevice/AutoDiscoveryWinImpl.cpp b/src/osgPlugins/ZeroConfDevice/AutoDiscoveryWinImpl.cpp index bd65ca7fe..1607be010 100644 --- a/src/osgPlugins/ZeroConfDevice/AutoDiscoveryWinImpl.cpp +++ b/src/osgPlugins/ZeroConfDevice/AutoDiscoveryWinImpl.cpp @@ -38,7 +38,7 @@ static DNSServiceErrorType RegisterService(DNSServiceRef *sdref, { DNSServiceFlags flags = 0; uint16_t PortAsNumber = atoi(port); - Opaque16 registerPort = { { PortAsNumber >> 8, PortAsNumber & 0xFF } }; + Opaque16 registerPort = { (unsigned char)(PortAsNumber >> 8), (unsigned char)(PortAsNumber & 0xFF) }; unsigned char txt[2048] = ""; unsigned char *ptr = txt; diff --git a/src/osgPlugins/ZeroConfDevice/CMakeLists.txt b/src/osgPlugins/ZeroConfDevice/CMakeLists.txt index 5287cfced..03e9e8787 100644 --- a/src/osgPlugins/ZeroConfDevice/CMakeLists.txt +++ b/src/osgPlugins/ZeroConfDevice/CMakeLists.txt @@ -38,3 +38,7 @@ SET(TARGET_ADDED_LIBRARIES osgGA ) #### end var setup ### SETUP_PLUGIN(zeroconf) + +IF(MSVC) + SET_TARGET_PROPERTIES(${TARGET_DEFAULT_PREFIX}zeroconf PROPERTIES LINK_FLAGS "/NODEFAULTLIB:LIBCMT.lib") +ENDIF(MSVC) \ No newline at end of file diff --git a/src/osgPlugins/ZeroConfDevice/mdns_win/dns-sd.c b/src/osgPlugins/ZeroConfDevice/mdns_win/dns-sd.c index 5deabf2e5..cc1e74a6a 100644 --- a/src/osgPlugins/ZeroConfDevice/mdns_win/dns-sd.c +++ b/src/osgPlugins/ZeroConfDevice/mdns_win/dns-sd.c @@ -199,9 +199,9 @@ static DNSServiceRef sc1, sc2, sc3; // DNSServiceRefs for kDNSServiceFlag static int num_printed; static char addtest = 0; static DNSRecordRef record = NULL; -static char myhinfoW[14] = "\002PC\012Windows XP"; -static char myhinfoX[ 9] = "\003Mac\004OS X"; -static char updatetest[3] = "\002AA"; +static char myhinfoW[15] = "\002PC\012Windows XP"; +static char myhinfoX[10] = "\003Mac\004OS X"; +static char updatetest[4] = "\002AA"; static char bigNULL[8192]; // 8K is maximum rdata we support // Note: the select() implementation on Windows (Winsock2) fails with any timeout much larger than this @@ -263,7 +263,7 @@ static uint16_t GetRRType(const char *s) else if (!strcasecmp(s, "MAILB" )) return(kDNSServiceType_MAILB); else if (!strcasecmp(s, "MAILA" )) return(kDNSServiceType_MAILA); else if (!strcasecmp(s, "ANY" )) return(kDNSServiceType_ANY); - else return(atoi(s)); + else return((uint16_t)(atoi(s))); } #if HAS_NAT_PMP_API | HAS_ADDRINFO_API @@ -424,8 +424,10 @@ static void ShowTXTRecord(uint16_t txtLen, const unsigned char *txtRecord) static void DNSSD_API resolve_reply(DNSServiceRef sdref, const DNSServiceFlags flags, uint32_t ifIndex, DNSServiceErrorType errorCode, const char *fullname, const char *hosttarget, uint16_t opaqueport, uint16_t txtLen, const unsigned char *txtRecord, void *context) { - union { uint16_t s; u_char b[2]; } port = { opaqueport }; - uint16_t PortAsNumber = ((uint16_t)port.b[0]) << 8 | port.b[1]; + union { uint16_t s; u_char b[2]; } port; + uint16_t PortAsNumber; + port.s = opaqueport ; + PortAsNumber = ((uint16_t)port.b[0]) << 8 | port.b[1]; (void)sdref; // Unused (void)ifIndex; // Unused @@ -456,11 +458,11 @@ static void myTimerCallBack(void) switch (addtest) { case 0: printf("Adding Test HINFO record\n"); - err = DNSServiceAddRecord(client, &record, 0, kDNSServiceType_HINFO, sizeof(myhinfoW), &myhinfoW[0], 0); + err = DNSServiceAddRecord(client, &record, 0, kDNSServiceType_HINFO, sizeof(myhinfoW)-1, &myhinfoW[0], 0); addtest = 1; break; case 1: printf("Updating Test HINFO record\n"); - err = DNSServiceUpdateRecord(client, record, 0, sizeof(myhinfoX), &myhinfoX[0], 0); + err = DNSServiceUpdateRecord(client, record, 0, sizeof(myhinfoX)-1, &myhinfoX[0], 0); addtest = 2; break; case 2: printf("Removing Test HINFO record\n"); @@ -503,7 +505,7 @@ static void myTimerCallBack(void) // Output the wire-format domainname pointed to by rd -static int snprintd(char *p, int max, const unsigned char **rd) +static size_t snprintd(char *p, size_t max, const unsigned char **rd) { const char *const buf = p; const char *const end = p + max;