Преглед изворни кода

remove bugs found by clang static analysis

Julius Pfrommer пре 10 година
родитељ
комит
e75dac31e1
5 измењених фајлова са 8 додато и 5 уклоњено
  1. 2 2
      src/ua_securechannel.c
  2. 3 3
      src/ua_session.c
  3. 1 0
      src/ua_transport.c
  4. 1 0
      src/ua_types_encoding_binary.c
  5. 1 0
      tools/generate_builtin.py

+ 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: