Просмотр исходного кода

Fixes segfaults, but behavior errors left

Signed-off-by: CapXilinx <melik-merkumians@acin.tuwien.ac.at>
CapXilinx 8 лет назад
Родитель
Сommit
da4d299529

+ 8 - 7
source/src/cip/appcontype.c

@@ -285,7 +285,7 @@ CipConnectionObject *GetExistingProducerMulticastConnection(
   const EipUint32 input_point) {
   const EipUint32 input_point) {
   DoublyLinkedListNode *node = connection_list.first;
   DoublyLinkedListNode *node = connection_list.first;
 
 
-  while (NULL != node->next) {
+  while (NULL != node) {
   CipConnectionObject *producer_multicast_connection = node->data;
   CipConnectionObject *producer_multicast_connection = node->data;
     if ( (kConnectionObjectInstanceTypeIO
     if ( (kConnectionObjectInstanceTypeIO
           == producer_multicast_connection->instance_type)) {
           == producer_multicast_connection->instance_type)) {
@@ -311,7 +311,7 @@ CipConnectionObject *GetNextNonControlMasterConnection(const EipUint32 input_poi
 {
 {
   DoublyLinkedListNode *node = connection_list.first;
   DoublyLinkedListNode *node = connection_list.first;
 
 
-  while (NULL != node->next) {
+  while (NULL != node) {
   CipConnectionObject *next_non_control_master_connection =
   CipConnectionObject *next_non_control_master_connection =
     node->data;
     node->data;
     if ( (kConnectionObjectInstanceTypeIO
     if ( (kConnectionObjectInstanceTypeIO
@@ -341,7 +341,7 @@ void CloseAllConnectionsForInputWithSameType(const EipUint32 input_point,
 
 
   DoublyLinkedListNode *node = connection_list.first;
   DoublyLinkedListNode *node = connection_list.first;
 
 
-  while (NULL != node->next) {
+  while (NULL != node) {
   CipConnectionObject *connection = node->data;
   CipConnectionObject *connection = node->data;
     if ( (instance_type == connection->instance_type)
     if ( (instance_type == connection->instance_type)
          && (input_point == connection->consumed_path.attribute_id_or_connection_point) ) {
          && (input_point == connection->consumed_path.attribute_id_or_connection_point) ) {
@@ -362,22 +362,23 @@ void CloseAllConnectionsForInputWithSameType(const EipUint32 input_point,
 }
 }
 
 
 void CloseAllConnections(void) {
 void CloseAllConnections(void) {
-  CipConnectionObject *connection = connection_list.first->data;
-  while (NULL != connection) {
+	DoublyLinkedListNode *node = connection_list.first;
+  while (NULL != node) {
+  CipConnectionObject *connection = node->data;
     assert(connection->connection_close_function != NULL);
     assert(connection->connection_close_function != NULL);
     connection->connection_close_function(connection);
     connection->connection_close_function(connection);
     CloseConnection(connection);
     CloseConnection(connection);
     /* Close connection will remove the connection from the list therefore we
     /* Close connection will remove the connection from the list therefore we
      * need to get again the start until there is no connection left
      * need to get again the start until there is no connection left
      */
      */
-    connection = connection_list.first->data;
+    node = connection_list.first;
   }
   }
 }
 }
 
 
 EipBool8 ConnectionWithSameConfigPointExists(const EipUint32 config_point) {
 EipBool8 ConnectionWithSameConfigPointExists(const EipUint32 config_point) {
   DoublyLinkedListNode *node = connection_list.first;
   DoublyLinkedListNode *node = connection_list.first;
 
 
-  while (NULL != node->next) {
+  while (NULL != node) {
   CipConnectionObject *connection = node->data;
   CipConnectionObject *connection = node->data;
     if (config_point == connection->configuration_path.attribute_id_or_connection_point) {
     if (config_point == connection->configuration_path.attribute_id_or_connection_point) {
       return (NULL != connection);
       return (NULL != connection);

+ 6 - 6
source/src/cip/cipconnectionmanager.c

@@ -508,7 +508,7 @@ EipStatus HandleNonNullNonMatchingForwardOpenRequest(
   } else {
   } else {
     OPENER_TRACE_INFO("connection manager: connect succeeded\n");
     OPENER_TRACE_INFO("connection manager: connect succeeded\n");
     /* in case of success the new connection is added at the head of the connection list */
     /* in case of success the new connection is added at the head of the connection list */
-    return AssembleForwardOpenResponse(connection_list.first,
+    return AssembleForwardOpenResponse(connection_list.first->data,
                                        message_router_response,
                                        message_router_response,
                                        kCipErrorSuccess, 0);
                                        kCipErrorSuccess, 0);
   }
   }
@@ -559,7 +559,7 @@ EipStatus ForwardOpen(
   bool is_matching_request = false; /* 1 = Matching Request, 0 = Non-Matching Request  */
   bool is_matching_request = false; /* 1 = Matching Request, 0 = Non-Matching Request  */
 
 
   /*first check if we have already a connection with the given params */
   /*first check if we have already a connection with the given params */
-  ConnectionObjectInitializeFromMessage(message_router_request,
+  ConnectionObjectInitializeFromMessage(message_router_request->data,
                                      &g_dummy_connection_object);
                                      &g_dummy_connection_object);
 
 
   memcpy( &(g_dummy_connection_object.originator_address), originator_address,
   memcpy( &(g_dummy_connection_object.originator_address), originator_address,
@@ -640,7 +640,7 @@ EipStatus ForwardClose(
 
 
   DoublyLinkedListNode *node = connection_list.first;
   DoublyLinkedListNode *node = connection_list.first;
 
 
-  while (NULL != node->next) {
+  while (NULL != node) {
     /* this check should not be necessary as only established connections should be in the active connection list */
     /* this check should not be necessary as only established connections should be in the active connection list */
   CipConnectionObject *connection_object = node->data;
   CipConnectionObject *connection_object = node->data;
     if ( (kConnectionObjectStateEstablished == ConnectionObjectGetState(connection_object))
     if ( (kConnectionObjectStateEstablished == ConnectionObjectGetState(connection_object))
@@ -706,7 +706,7 @@ EipStatus ManageConnections(MilliSeconds elapsed_time) {
 
 
   DoublyLinkedListNode *node = connection_list.first;
   DoublyLinkedListNode *node = connection_list.first;
 
 
-  while (NULL != node->next) {
+  while (NULL != node) {
     //OPENER_TRACE_INFO("Entering Connection Object loop\n");
     //OPENER_TRACE_INFO("Entering Connection Object loop\n");
     CipConnectionObject *connection_object = node->data;
     CipConnectionObject *connection_object = node->data;
     if (kConnectionObjectStateEstablished == ConnectionObjectGetState(connection_object)) {
     if (kConnectionObjectStateEstablished == ConnectionObjectGetState(connection_object)) {
@@ -1004,7 +1004,7 @@ CipConnectionObject *CheckForExistingConnection(
 
 
   DoublyLinkedListNode *iterator = connection_list.first;
   DoublyLinkedListNode *iterator = connection_list.first;
 
 
-    while(NULL != iterator->next) {
+    while(NULL != iterator) {
         if(kConnectionObjectStateEstablished == ConnectionObjectGetState(iterator->data)) {
         if(kConnectionObjectStateEstablished == ConnectionObjectGetState(iterator->data)) {
           if(EqualConnectionTriad(connection_object, iterator->data)){
           if(EqualConnectionTriad(connection_object, iterator->data)){
             return iterator->data;
             return iterator->data;
@@ -1436,7 +1436,7 @@ EipBool8 IsConnectedOutputAssembly(const EipUint32 instance_number) {
 
 
   DoublyLinkedListNode *node = connection_list.first;
   DoublyLinkedListNode *node = connection_list.first;
 
 
-  while (NULL != node->next) {
+  while (NULL != node) {
     CipDword produced_connection_point = ((CipConnectionObject*)node->data)->produced_path.attribute_id_or_connection_point;
     CipDword produced_connection_point = ((CipConnectionObject*)node->data)->produced_path.attribute_id_or_connection_point;
     if (instance_number == produced_connection_point) {
     if (instance_number == produced_connection_point) {
       is_connected = true;
       is_connected = true;

+ 1 - 1
source/src/cip/cipepath.c

@@ -344,7 +344,7 @@ const CipDword CipEpathGetLogicalValue(const EipUint8 **message) {
   }
   }
 }
 }
 
 
-size_t CipEpathSetLogicalValue(const CipDword logical_value, const LogicalSegmentLogicalFormat logical_format, EipUint8 **message) {
+size_t CipEpathSetLogicalValue(const CipDword logical_value, const LogicalSegmentLogicalFormat logical_format, CipOctet **message) {
   switch(logical_value) {
   switch(logical_value) {
     case kLogicalSegmentLogicalFormatEightBit: AddSintToMessage(logical_value, message); return 1; break;
     case kLogicalSegmentLogicalFormatEightBit: AddSintToMessage(logical_value, message); return 1; break;
     case kLogicalSegmentLogicalFormatSixteenBit: MoveMessageNOctets(1, message); AddIntToMessage(logical_value, message); return 3; break;
     case kLogicalSegmentLogicalFormatSixteenBit: MoveMessageNOctets(1, message); AddIntToMessage(logical_value, message); return 3; break;

+ 1 - 1
source/src/cip/cipepath.h

@@ -255,7 +255,7 @@ void SetPathLogicalSegmentLogicalFormat(LogicalSegmentLogicalFormat format, unsi
 
 
 const CipDword CipEpathGetLogicalValue(const EipUint8 **message);
 const CipDword CipEpathGetLogicalValue(const EipUint8 **message);
 
 
-size_t CipEpathSetLogicalValue(const CipDword logical_value, const LogicalSegmentLogicalFormat logical_format, EipUint8 **message);
+size_t CipEpathSetLogicalValue(const CipDword logical_value, const LogicalSegmentLogicalFormat logical_format, CipOctet **message);
 
 
 /** @brief  Gets the Extended Logical Type of a Logical Segment EPath message
 /** @brief  Gets the Extended Logical Type of a Logical Segment EPath message
  *
  *

+ 1 - 1
source/src/cip/cipioconnection.c

@@ -158,7 +158,7 @@ EipUint16 SetupIoConnectionTargetToOriginatorConnectionPoint(
   CipConnectionObject *const RESTRICT connection_object
   CipConnectionObject *const RESTRICT connection_object
   ) {
   ) {
   DoublyLinkedListNode *node = connection_list.first;
   DoublyLinkedListNode *node = connection_list.first;
-  while (NULL != node->next) {
+  while (NULL != node) {
   CipConnectionObject *iterator = node->data;
   CipConnectionObject *iterator = node->data;
     if(io_connection_object->produced_path.attribute_id_or_connection_point ==
     if(io_connection_object->produced_path.attribute_id_or_connection_point ==
        iterator->produced_path.attribute_id_or_connection_point) {
        iterator->produced_path.attribute_id_or_connection_point) {