Browse Source

remove most compiler warnings on msvc

Julius Pfrommer 10 years ago
parent
commit
4d6801478a
5 changed files with 32 additions and 16 deletions
  1. 1 3
      CMakeLists.txt
  2. 21 5
      examples/networklayer_tcp.c
  3. 2 0
      examples/opcuaServer.c
  4. 3 3
      src/ua_types.c
  5. 5 5
      tools/generate_namespace.py

+ 1 - 3
CMakeLists.txt

@@ -142,9 +142,7 @@ endif()
 
 add_library(open62541-objects OBJECT ${lib_sources}) # static version that exports all symbols
 add_library(open62541 SHARED $<TARGET_OBJECTS:open62541-objects>)
-target_compile_definitions(open62541 INTERFACE
-  $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,SHARED_LIBRARY>:UA_DYNAMIC_LINKING> # the UA_EXPORT macro is different when building the lib or using the lib
-)
+target_compile_definitions(open62541-objects PUBLIC UA_DYNAMIC_LINKING)
 
 ## logging
 set(UA_LOGLEVEL 400 CACHE STRING "Level at which logs shall be reported")

+ 21 - 5
examples/networklayer_tcp.c

@@ -101,6 +101,8 @@ void writeCallback(TCPConnection *handle, UA_ByteStringArray gather_buf);
 static UA_StatusCode NetworkLayerTCP_add(NetworkLayerTCP *layer, UA_Int32 newsockfd) {
     setNonBlocking(newsockfd);
     TCPConnection *c = malloc(sizeof(TCPConnection));
+	if(!c)
+		return UA_STATUSCODE_BADINTERNALERROR;
 	c->sockfd = newsockfd;
     c->layer = layer;
     c->connection.state = UA_CONNECTION_OPENING;
@@ -110,6 +112,10 @@ static UA_StatusCode NetworkLayerTCP_add(NetworkLayerTCP *layer, UA_Int32 newsoc
     c->connection.write = (void (*)(void*, UA_ByteStringArray))writeCallback;
 
     layer->conLinks = realloc(layer->conLinks, sizeof(ConnectionLink)*(layer->conLinksSize+1));
+	if(!layer->conLinks) {
+		free(c);
+		return UA_STATUSCODE_BADINTERNALERROR;
+	}
     layer->conLinks[layer->conLinksSize].connection = c;
     layer->conLinks[layer->conLinksSize].sockfd = newsockfd;
     layer->conLinksSize++;
@@ -119,6 +125,10 @@ static UA_StatusCode NetworkLayerTCP_add(NetworkLayerTCP *layer, UA_Int32 newsoc
 // Takes the linked list of closed connections and returns the work for the server loop
 static UA_UInt32 batchDeleteLinks(NetworkLayerTCP *layer, UA_WorkItem **returnWork) {
     UA_WorkItem *work = malloc(sizeof(UA_WorkItem)*layer->conLinksSize);
+	if (!work) {
+		*returnWork = NULL;
+		return 0;
+	}
 #ifdef UA_MULTITHREADING
     struct deleteLink *d = uatomic_xchg(&layer->deleteLinkList, UA_NULL);
 #else
@@ -170,6 +180,10 @@ void closeConnection(TCPConnection *handle) {
 }
 #else
 void closeConnection(TCPConnection *handle) {
+	struct deleteLink *d = malloc(sizeof(struct deleteLink));
+	if(!d)
+		return;
+
     if(handle->connection.state == UA_CONNECTION_CLOSING)
         return;
     handle->connection.state = UA_CONNECTION_CLOSING;
@@ -179,7 +193,6 @@ void closeConnection(TCPConnection *handle) {
 	CLOSESOCKET(handle->sockfd);
 
     // Remove the link later in the main thread
-    struct deleteLink *d = malloc(sizeof(struct deleteLink));
     d->sockfd = handle->sockfd;
     d->next = handle->layer->deleteLinkList;
     handle->layer->deleteLinkList = d;
@@ -299,13 +312,16 @@ UA_Int32 NetworkLayerTCP_getWork(NetworkLayerTCP *layer, UA_WorkItem **workItems
 
 	// read from established sockets
     UA_Int32 j = itemsCount;
-    UA_ByteString buf = {-1, NULL};
+	UA_ByteString buf = { -1, NULL};
 	for(UA_Int32 i=0;i<layer->conLinksSize && j<itemsCount+resultsize;i++) {
 		if(!(FD_ISSET(layer->conLinks[i].sockfd, &layer->fdset)))
             continue;
 
-        if(buf.data == NULL)
-            buf.data = malloc(layer->conf.recvBufferSize);
+		if(!buf.data) {
+			buf.data = malloc(sizeof(UA_Byte) * layer->conf.recvBufferSize);
+			if(!buf.data)
+				break;
+		}
         
 #ifdef _WIN32
         buf.length = recv(layer->conLinks[i].sockfd, (char *)buf.data,
@@ -325,7 +341,7 @@ UA_Int32 NetworkLayerTCP_getWork(NetworkLayerTCP *layer, UA_WorkItem **workItems
         }
     }
 
-    if(buf.data != NULL)
+    if(buf.data)
         free(buf.data);
 
     if(j == 0) {

+ 2 - 0
examples/opcuaServer.c

@@ -37,6 +37,8 @@ UA_ByteString loadCertificate() {
     fseek(fp, 0, SEEK_END);
     certificate.length = ftell(fp);
     certificate.data = malloc(certificate.length*sizeof(UA_Byte));
+	if(!certificate.data)
+		return certificate;
 
     fseek(fp, 0, SEEK_SET);
     if(fread(certificate.data, sizeof(UA_Byte), certificate.length, fp) < (size_t)certificate.length)

+ 3 - 3
src/ua_types.c

@@ -14,7 +14,7 @@
 #include "ua_util.h"
 
 #ifdef _MSC_VER
-#define RAND(SEED) rand(SEED)
+#define RAND(SEED) rand()
 #else
 #define RAND(SEED) rand_r(SEED)
 #endif
@@ -195,13 +195,13 @@ UA_StatusCode UA_String_copyprintf(char const *fmt, UA_String *dst, ...) {
     char src[UA_STRING_COPYPRINTF_BUFSIZE];
     va_list ap;
     va_start(ap, dst);
-#ifndef __MINGW32__
+#ifndef WIN32
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
 #endif
     // vsnprintf should only take a literal and no variable to be secure
     UA_Int32 len = vsnprintf(src, UA_STRING_COPYPRINTF_BUFSIZE, fmt, ap);
-#ifndef __MINGW32__
+#ifndef WIN32
 #pragma GCC diagnostic pop
 #endif
     va_end(ap);

+ 5 - 5
tools/generate_namespace.py

@@ -185,7 +185,7 @@ for row in rows:
            ",\n.name=(UA_Byte*)&\"%(name)s\"" +
            ",\n.new=(void *(*)())%(name)s_new" +
            ",\n.init=(void(*)(void *))%(name)s_init"+
-           ",\n.copy=(UA_Int32(*)(void const * ,void*))%(name)s_copy" +
+           ",\n.copy=(UA_StatusCode(*)(void const * ,void*))%(name)s_copy" +
            ",\n.delete=(void(*)(void *))%(name)s_delete" +
            ",\n.deleteMembers=(void(*)(void *))%(name)s_deleteMembers" +
            ",\n#ifdef UA_DEBUG //FIXME: seems to be okay atm, however a pointer to a noop function would be more safe" + 
@@ -194,11 +194,11 @@ for row in rows:
            "\n.memSize=" + ("sizeof(%(name)s)" if (name != "UA_InvalidType") else "0") +
            ",\n.dynMembers=" + ("UA_FALSE" if (name in fixed_size) else "UA_TRUE") +
            ",\n.encodings={{.calcSize=(UA_Int32(*)(const void*))%(name)s_calcSizeBinary" +
-           ",\n.encode=(UA_Int32(*)(const void*,UA_ByteString*,UA_UInt32*))%(name)s_encodeBinary" +
-           ",\n.decode=(UA_Int32(*)(const UA_ByteString*,UA_UInt32*,void*))%(name)s_decodeBinary}" +
+           ",\n.encode=(UA_StatusCode(*)(const void*,UA_ByteString*,UA_UInt32*))%(name)s_encodeBinary" +
+           ",\n.decode=(UA_StatusCode(*)(const UA_ByteString*,UA_UInt32*,void*))%(name)s_decodeBinary}" +
            (",\n{.calcSize=(UA_Int32(*)(const void*))%(name)s_calcSizeXml" +
-            ",\n.encode=(UA_Int32(*)(const void*,UA_ByteString*,UA_UInt32*))%(name)s_encodeXml" +
-            ",\n.decode=(UA_Int32(*)(const UA_ByteString*,UA_UInt32*,void*))%(name)s_decodeXml}" if (args.with_xml) else "") +
+            ",\n.encode=(UA_StatusCode(*)(const void*,UA_ByteString*,UA_UInt32*))%(name)s_encodeXml" +
+            ",\n.decode=(UA_StatusCode(*)(const UA_ByteString*,UA_UInt32*,void*))%(name)s_decodeXml}" if (args.with_xml) else "") +
            "}},")
 
 printc('};\n')