Explorar o código

remove bugs found by clang static analysis

Julius Pfrommer %!s(int64=10) %!d(string=hai) anos
pai
achega
e75dac31e1

+ 2 - 2
src/ua_securechannel.c

@@ -23,8 +23,8 @@ UA_Int32 UA_SecureChannel_deleteMembers(UA_SecureChannel *channel) {
 }
 UA_Int32 UA_SecureChannel_delete(UA_SecureChannel *channel) {
     UA_Int32 retval = UA_SUCCESS;
-    retval = UA_SecureChannel_deleteMembers(channel);
-    retval = UA_free(channel);
+    retval |= UA_SecureChannel_deleteMembers(channel);
+    retval |= UA_free(channel);
     return retval;
 }
 

+ 3 - 3
src/ua_session.c

@@ -27,9 +27,9 @@ UA_Int32 UA_Session_generateToken(UA_NodeId *newToken) {
     r = rand();
     newToken->identifier.guid.data2 = (UA_UInt16)((r>>16) );
     r = rand();
-    UA_Int32 r1 = (r>>16);
-    UA_Int32 r2 = r1 & 0xFFFF;
-    r2 = r2 * 1;
+    /* UA_Int32 r1 = (r>>16); */
+    /* UA_Int32 r2 = r1 & 0xFFFF; */
+    /* r2 = r2 * 1; */
     newToken->identifier.guid.data3 = (UA_UInt16)((r>>16) );
     for(i = 0;i < 8;i++) {
         r = rand();

+ 1 - 0
src/ua_transport.c

@@ -530,6 +530,7 @@ UA_Int32 UA_SecureConversationMessageFooter_deleteMembers(UA_SecureConversationM
 }
 
 UA_Int32 UA_SecureConversationMessageFooter_init(UA_SecureConversationMessageFooter *p) {
+    if(!p) return UA_ERROR;
     UA_Int32 retval = UA_SUCCESS;
     p->paddingSize = 0;
     p->padding     = UA_NULL;

+ 1 - 0
src/ua_types_encoding_binary.c

@@ -139,6 +139,7 @@ UA_Int32 UA_Array_decodeBinary(const UA_ByteString *src, UA_UInt32 *offset, UA_I
 
 #define UA_TYPE_ENCODEBINARY(TYPE, CODE)                                                    \
     UA_Int32 TYPE##_encodeBinary(TYPE const *src, UA_ByteString * dst, UA_UInt32 *offset) { \
+        if(!src) return UA_ERROR;                                                           \
         UA_Int32 retval = UA_SUCCESS;                                                       \
         if((UA_Int32)(*offset + TYPE##_calcSizeBinary(src)) > dst->length ) {               \
             return UA_ERR_INVALID_VALUE;                                                    \

+ 1 - 0
tools/generate_builtin.py

@@ -232,6 +232,7 @@ UA_TYPE_METHOD_DECODEXML_NOTIMPL(%(name)s)''')
 
     # 10) Init
     printc('''UA_Int32 %(name)s_init(%(name)s *p) {
+    if(!p) return UA_ERROR;
     UA_Int32 retval = UA_SUCCESS;''')
     for n,t in membermap.iteritems():
         if t.find("*") != -1: