Browse Source

small fixes to make clang analyzer happy

Julius Pfrommer 8 years ago
parent
commit
8c4726b1f9
4 changed files with 17 additions and 10 deletions
  1. 0 1
      examples/server.c
  2. 3 1
      src/server/ua_server_binary.c
  3. 7 5
      src/server/ua_server_worker.c
  4. 7 3
      src/server/ua_subscription.c

+ 0 - 1
examples/server.c

@@ -161,7 +161,6 @@ getMonitoredItems(void *methodHandle, const UA_NodeId objectId,
                   size_t outputSize, UA_Variant *output) {
     UA_String tmp = UA_STRING("Hello World");
     UA_Variant_setScalarCopy(output, &tmp, &UA_TYPES[UA_TYPES_STRING]);
-    printf("getMonitoredItems was called\n");
     return UA_STATUSCODE_GOOD;
 }
 #endif

+ 3 - 1
src/server/ua_server_binary.c

@@ -358,7 +358,6 @@ chunkEntryFromRequestId(UA_SecureChannel *channel, UA_UInt32 requestId) {
             return ch;
         }
     }
-
     return NULL;
 }
 
@@ -565,6 +564,9 @@ processMSG(UA_Connection *connection, UA_Server *server, const UA_ByteString *ms
     UA_LOG_DEBUG(server->config.logger, UA_LOGCATEGORY_SERVER,
                  "Processing a service with type id %u on Session %u",
                  requestType->typeId.identifier.numeric, session->authenticationToken.identifier.numeric);
+    UA_assert(service);
+    UA_assert(requestType);
+    UA_assert(responseType);
     void *response = UA_alloca(responseType->memSize);
     UA_init(response, responseType);
     init_response_header(request, response);

+ 7 - 5
src/server/ua_server_worker.c

@@ -292,8 +292,9 @@ UA_StatusCode UA_Server_addRepeatedJob(UA_Server *server, UA_Job job, UA_UInt32
 
 /* Returns the next datetime when a repeated job is scheduled */
 static UA_DateTime processRepeatedJobs(UA_Server *server, UA_DateTime current) {
-    struct RepeatedJobs *tw = NULL;
-    while((tw = LIST_FIRST(&server->repeatedJobs)) != NULL) {
+    struct RepeatedJobs *tw, *tmp_tw;
+    /* Iterate over the list of elements (sorted according to the next execution timestamp) */
+    LIST_FOREACH_SAFE(tw, &server->repeatedJobs, pointers, tmp_tw) {
         if(tw->nextTime > current)
             break;
 
@@ -318,16 +319,17 @@ static UA_DateTime processRepeatedJobs(UA_Server *server, UA_DateTime current) {
 		if(tw->jobsSize == 0) {
 			LIST_REMOVE(tw, pointers);
 			UA_free(tw);
+            UA_assert(LIST_FIRST(&server->repeatedJobs) != tw); /* Assert for static code checkers */
 			continue;
 		}
 
-        /* set the time for the next execution */
+        /* Set the time for the next execution */
         tw->nextTime += tw->interval;
         if(tw->nextTime < current)
             tw->nextTime = current;
 
-        //start iterating the list from the beginning
-        struct RepeatedJobs *prevTw = LIST_FIRST(&server->repeatedJobs); // after which tw do we insert?
+        /* Reinsert to keep the list sorted */
+        struct RepeatedJobs *prevTw = LIST_FIRST(&server->repeatedJobs);
         while(true) {
             struct RepeatedJobs *n = LIST_NEXT(prevTw, pointers);
             if(!n || n->nextTime > tw->nextTime)

+ 7 - 3
src/server/ua_subscription.c

@@ -311,8 +311,10 @@ void UA_Subscription_publishCallback(UA_Server *server, UA_Subscription *sub) {
     UA_NotificationMessageEntry *nme;
     LIST_FOREACH(nme, &sub->retransmissionQueue, listEntry)
         available++;
-    response->availableSequenceNumbers = UA_malloc(available * sizeof(UA_UInt32));
-    response->availableSequenceNumbersSize = available;
+    if(available > 0) {
+        response->availableSequenceNumbers = UA_alloca(available * sizeof(UA_UInt32));
+        response->availableSequenceNumbersSize = available;
+    }
     size_t i = 0;
     LIST_FOREACH(nme, &sub->retransmissionQueue, listEntry) {
         response->availableSequenceNumbers[i] = nme->message.sequenceNumber;
@@ -324,7 +326,9 @@ void UA_Subscription_publishCallback(UA_Server *server, UA_Subscription *sub) {
                                        &UA_TYPES[UA_TYPES_PUBLISHRESPONSE]);
 
     /* Remove the queued request */
-    UA_NotificationMessage_init(&response->notificationMessage); /* The notification message was put into the queue */
+    UA_NotificationMessage_init(&response->notificationMessage); /* The notification message was put into the queue and is not freed */
+    response->availableSequenceNumbers = NULL; /* stack-allocated */
+    response->availableSequenceNumbersSize = 0;
     UA_PublishResponse_deleteMembers(&pre->response);
     UA_free(pre);