Kaynağa Gözat

Cleanup: Unify the use of the OPENER_ASSERT() macro and fixed some invalid uses

The standard C assert() macro is defined without a trailing semicolon. Some
of the OPENER_ASSERT() macro definitions had a trailing semicolon and some
not.

To make all variants of the macro definition interchangeable the definitions
in all opener_user_conf.h have been heavily reworked.

Now all OPENER_ASSERT() macro definitions lack a trailing semicolon. As a
consequence a semicolon had to be added on numerous uses of that macro in
the source.

At some points OPENER_ASSERT() was called with a literal character string
as argument. This failed the intended use completely and was replaced by
an OPENER_TRACE_ERR() call with the literal string followed by an
OPENER_ASSERT(false).

Signed-off-by: Stefan Mätje <stefan.maetje@esd.eu>
Stefan Mätje 6 yıl önce
ebeveyn
işleme
5457ee2daf

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

@@ -435,7 +435,7 @@ bool ConnectionWithSameConfigPointExists(const EipUint32 config_point) {
 
   while (NULL != node) {
     CipConnectionObject *connection = node->data;
-    OPENER_ASSERT(NULL != connection)
+    OPENER_ASSERT(NULL != connection);
     if (config_point == connection->configuration_path.instance_id) {
       return true;
     }

+ 17 - 17
source/src/cip/cipcommon.c

@@ -39,29 +39,29 @@ int EncodeEPath(CipEpath *epath,
 void CipStackInit(const EipUint16 unique_connection_id) {
   /* The message router is the first CIP object be initialized!!! */
   EipStatus eip_status = CipMessageRouterInit();
-  OPENER_ASSERT(kEipStatusOk == eip_status)
+  OPENER_ASSERT(kEipStatusOk == eip_status);
   eip_status = CipIdentityInit();
-  OPENER_ASSERT(kEipStatusOk == eip_status)
+  OPENER_ASSERT(kEipStatusOk == eip_status);
   eip_status = CipTcpIpInterfaceInit();
-  OPENER_ASSERT(kEipStatusOk == eip_status)
+  OPENER_ASSERT(kEipStatusOk == eip_status);
   eip_status = CipEthernetLinkInit();
-  OPENER_ASSERT(kEipStatusOk == eip_status)
+  OPENER_ASSERT(kEipStatusOk == eip_status);
   eip_status = ConnectionManagerInit(unique_connection_id);
-  OPENER_ASSERT(kEipStatusOk == eip_status)
+  OPENER_ASSERT(kEipStatusOk == eip_status);
   eip_status = CipAssemblyInitialize();
-  OPENER_ASSERT(kEipStatusOk == eip_status)
+  OPENER_ASSERT(kEipStatusOk == eip_status);
 #if defined(OPENER_IS_DLR_DEVICE) && 0 != OPENER_IS_DLR_DEVICE
   eip_status = CipDlrInit();
   OPENER_ASSERT(kEipStatusOk == eip_status);
 #endif
   eip_status = CipQoSInit();
-  OPENER_ASSERT(kEipStatusOk == eip_status)
+  OPENER_ASSERT(kEipStatusOk == eip_status);
   /* the application has to be initialized at last */
   eip_status = ApplicationInitialization();
-  OPENER_ASSERT(kEipStatusOk == eip_status)
+  OPENER_ASSERT(kEipStatusOk == eip_status);
 
   /* Shut up compiler warning with traces disabled */
-    (void) eip_status;
+  (void) eip_status;
 }
 
 void ShutdownCipStack(void) {
@@ -103,7 +103,7 @@ EipStatus NotifyClass(const CipClass *RESTRICT const cip_class,
           /* call the service, and return what it returns */
           OPENER_TRACE_INFO("notify: calling %s service\n",
                             service->name);
-          OPENER_ASSERT(NULL != service->service_function)
+          OPENER_ASSERT(NULL != service->service_function);
           return service->service_function(instance,
                                            message_router_request,
                                            message_router_response,
@@ -220,7 +220,7 @@ CipClass *CreateCipClass(const CipUdint class_code,
   OPENER_TRACE_INFO("creating class '%s' with code: 0x%" PRIX32 "\n", name,
                     class_code);
 
-  OPENER_ASSERT(NULL == GetCipClass(class_code))  /* check if an class with the ClassID already exists */
+  OPENER_ASSERT(NULL == GetCipClass(class_code)); /* check if an class with the ClassID already exists */
   /* should never try to redefine a class*/
 
   /* a metaClass is a class that holds the class attributes and services
@@ -329,7 +329,7 @@ void InsertAttribute(CipInstance *const instance,
   CipAttributeStruct *attribute = instance->attributes;
   CipClass *cip_class = instance->cip_class;
 
-  OPENER_ASSERT(NULL != attribute)
+  OPENER_ASSERT(NULL != attribute);
   /* adding a attribute to a class that was not declared to have any attributes is not allowed */
   for (int i = 0; i < instance->cip_class->number_of_attributes; i++) {
     if (attribute->data == NULL) {             /* found non set attribute */
@@ -338,7 +338,7 @@ void InsertAttribute(CipInstance *const instance,
       attribute->attribute_flags = cip_flags;
       attribute->data = data;
 
-      OPENER_ASSERT(attribute_number <= cip_class->highest_attribute_number)
+      OPENER_ASSERT(attribute_number <= cip_class->highest_attribute_number);
 
       size_t index = CalculateIndex(attribute_number);
 
@@ -357,7 +357,7 @@ void InsertAttribute(CipInstance *const instance,
   OPENER_TRACE_ERR(
     "Tried to insert too many attributes into class: %" PRIu32 " '%s', instance %" PRIu32 "\n",
     cip_class->class_code, cip_class->class_name, instance->instance_number);
-  OPENER_ASSERT(0)
+  OPENER_ASSERT(false);
   /* trying to insert too many attributes*/
 }
 
@@ -370,7 +370,7 @@ void InsertService(const CipClass *const cip_class,
   OPENER_TRACE_INFO("%s, number of services:%d, service number:%d\n",
                     cip_class->class_name, cip_class->number_of_services,
                     service_number);
-  OPENER_ASSERT(service != NULL)
+  OPENER_ASSERT(service != NULL);
   /* adding a service to a class that was not declared to have services is not allowed*/
   for (int i = 0; i < cip_class->number_of_services; i++) /* Iterate over all service slots attached to the class */
   {
@@ -384,7 +384,7 @@ void InsertService(const CipClass *const cip_class,
     }
     ++service;
   }
-  OPENER_ASSERT(0)
+  OPENER_ASSERT(false);
   /* adding more services than were declared is a no-no*/
 }
 
@@ -469,7 +469,7 @@ EipStatus GetAttributeSingle(CipInstance *RESTRICT const instance,
         instance->cip_class->PreGetCallback(instance, attribute, message_router_request->service);
       }
 
-      OPENER_ASSERT(NULL != attribute)
+      OPENER_ASSERT(NULL != attribute);
       message_router_response->data_length = EncodeData(attribute->type,
                                                         attribute->data,
                                                         &message);

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

@@ -592,7 +592,7 @@ EipStatus ForwardClose(
            && (connection_object->originator_serial_number
                == originator_serial_number) ) {
         /* found the corresponding connection object -> close it */
-        OPENER_ASSERT(NULL != connection_object->connection_close_function)
+        OPENER_ASSERT(NULL != connection_object->connection_close_function);
         if ( ( (struct sockaddr_in *) originator_address )->sin_addr.s_addr
              == connection_object->originator_address.sin_addr.s_addr ) {
           connection_object->connection_close_function(connection_object);
@@ -660,7 +660,7 @@ EipStatus ManageConnections(MilliSeconds elapsed_time) {
           /* we have a timed out connection perform watchdog time out action*/
           OPENER_TRACE_INFO(">>>>>>>>>>Connection ConnNr: %u timed out\n",
                             connection_object->connection_serial_number);
-          OPENER_ASSERT(NULL != connection_object->connection_timeout_function)
+          OPENER_ASSERT(NULL != connection_object->connection_timeout_function);
           connection_object->connection_timeout_function(connection_object);
         } else {
           connection_object->inactivity_watchdog_timer -= elapsed_time;
@@ -690,7 +690,7 @@ EipStatus ManageConnections(MilliSeconds elapsed_time) {
 
           if (connection_object->transmission_trigger_timer <= elapsed_time) { /* need to send package */
             OPENER_ASSERT(
-              NULL != connection_object->connection_send_data_function)
+              NULL != connection_object->connection_send_data_function);
             EipStatus eip_status = connection_object
                                    ->connection_send_data_function(
               connection_object);

+ 3 - 3
source/src/cip/cipconnectionobject.c

@@ -241,7 +241,7 @@ void ConnectionObjectSetState(CipConnectionObject *const connection_object,
         CIP_CONNECTION_OBJECT_STATE_CLOSING;
       break;
     default:
-      OPENER_ASSERT(false) /* Never get here */
+      OPENER_ASSERT(false);/* Never get here */
       break;
   }
 }
@@ -287,7 +287,7 @@ CipUsint ConnectionObjectGetInstanceTypeForAttribute(
       instance_type = CIP_CONNECTION_OBJECT_INSTANCE_TYPE_CIP_BRIDGED;
       break;
     default:
-      OPENER_ASSERT(false) /* This is a fault case */
+      OPENER_ASSERT(false);/* This is a fault case */
       instance_type = kConnectionObjectInstanceTypeInvalid;
       break;
   }
@@ -727,7 +727,7 @@ ConnectionObjectPriority ConnectionObjectGetPriority(
       kConnectionObjectPriorityScheduled; break;
     case CIP_CONNECTION_OBJECT_PRIORITY_URGENT: result =
       kConnectionObjectPriorityUrgent; break;
-    default: OPENER_ASSERT(false) /* Not possible to get here! */
+    default: OPENER_ASSERT(false);/* Not possible to get here! */
       result = kConnectionObjectPriorityLow;
       break;
   }

+ 48 - 41
source/src/cip/cipepath.c

@@ -103,8 +103,9 @@ SegmentType GetPathSegmentType(const CipOctet *const cip_path) {
       result = kSegmentTypeReserved;
       break;
     default:
-      OPENER_ASSERT(
-        "Invalid Segment type in the message! We should never come here!\n")
+      OPENER_TRACE_ERR(
+        "Invalid Segment type in the message! We should never come here!\n");
+      OPENER_ASSERT(false);
       break;
   }
   return result;
@@ -138,8 +139,9 @@ void SetPathSegmentType(SegmentType segment_type,
       *cip_path = SEGMENT_TYPE_SEGMENT_RESERVED;
       break;
     default:
-      OPENER_ASSERT(
-        "Invalid Segment type chosen! We should never come here!\n")
+      OPENER_TRACE_ERR(
+        "Invalid Segment type chosen! We should never come here!\n");
+      OPENER_ASSERT(false);
       break;
   }
 }
@@ -159,9 +161,10 @@ unsigned int GetPathPortSegmentPortIdentifier(
   const unsigned char *const cip_path) {
   const unsigned int kPortIdentifierMask = 0x0F;
   unsigned int port_identifier = *cip_path & kPortIdentifierMask;
-/*  OPENER_ASSERT(0 != port_identifier, "Use of reserved port identifier 0\n"); */
-  OPENER_ASSERT( kSegmentTypePortSegment == GetPathSegmentType(cip_path) )
-  OPENER_ASSERT(0 != port_identifier)
+
+  OPENER_ASSERT( kSegmentTypePortSegment == GetPathSegmentType(cip_path) );
+  /* Use of reserved port identifier 0 */
+  OPENER_ASSERT(0 != port_identifier);
   return port_identifier;
 }
 
@@ -170,25 +173,25 @@ void SetPathPortSegmentPortIdentifier(const unsigned int port_identifier,
 /* OPENER_ASSERT(
       port_identifier < 16,
       "Port identifier too large for standard port identifier field\n"); */
-  OPENER_ASSERT(port_identifier < 16)
+  OPENER_ASSERT(port_identifier < 16);
     (*cip_path) |= port_identifier;
 }
 
 unsigned int GetPathPortSegmentLinkAddressSize(
   const unsigned char *const cip_path) {
 /*  OPENER_ASSERT(false == GetPathPortSegmentExtendedLinkAddressSizeBit(cip_path),
-                "Call to non existent extended link address size\n") */
+                "Call to non existent extended link address size\n"); */
   OPENER_ASSERT( true ==
-                 GetPathPortSegmentExtendedLinkAddressSizeBit(cip_path) )
+                 GetPathPortSegmentExtendedLinkAddressSizeBit(cip_path) );
   return *(cip_path + 1);
 }
 
 unsigned int GetPathPortSegmentExtendedPortNumber(
   const unsigned char *const cip_path) {
 /*  OPENER_ASSERT(kPortSegmentExtendedPort == GetPathPortSegmentPortIdentifier(cip_path),
-                "There is no extended port available!\n") */
+                "There is no extended port available!\n");*/
   OPENER_ASSERT( kPortSegmentExtendedPort ==
-                 GetPathPortSegmentPortIdentifier(cip_path) )
+                 GetPathPortSegmentPortIdentifier(cip_path) );
   const unsigned int kExtendedPortSegmentPosition =
     GetPathPortSegmentExtendedLinkAddressSizeBit(cip_path) == true ? 2 : 1;
   return cip_path[kExtendedPortSegmentPosition]
@@ -212,7 +215,7 @@ void SetPathPortSegmentExtendedPortIdentifier(
 
 LogicalSegmentLogicalType GetPathLogicalSegmentLogicalType(
   const unsigned char *const cip_path) {
-  OPENER_ASSERT( kSegmentTypeLogicalSegment == GetPathSegmentType(cip_path) )
+  OPENER_ASSERT( kSegmentTypeLogicalSegment == GetPathSegmentType(cip_path) );
   const unsigned int kLogicalTypeMask = 0x1C;
   const unsigned int logical_type = (*cip_path) & kLogicalTypeMask;
   LogicalSegmentLogicalType result = kLogicalSegmentLogicalTypeExtendedLogical;
@@ -242,8 +245,9 @@ LogicalSegmentLogicalType GetPathLogicalSegmentLogicalType(
       result = kLogicalSegmentLogicalTypeExtendedLogical;
       break;
     default:
-      OPENER_ASSERT(
-        "Logical segment/logical type: It is not possible to reach this point!\n")
+      OPENER_TRACE_ERR(
+        "Logical segment/logical type: It is not possible to reach this point!\n");
+      OPENER_ASSERT(false);
       break;
   }
   return result;
@@ -251,7 +255,7 @@ LogicalSegmentLogicalType GetPathLogicalSegmentLogicalType(
 
 void SetPathLogicalSegmentLogicalType(LogicalSegmentLogicalType logical_type,
                                       CipOctet *const cip_path) {
-  OPENER_ASSERT( kSegmentTypeLogicalSegment == GetPathSegmentType(cip_path) )
+  OPENER_ASSERT( kSegmentTypeLogicalSegment == GetPathSegmentType(cip_path) );
   switch (logical_type) {
     case kLogicalSegmentLogicalTypeClassId:
       (*cip_path) |= LOGICAL_SEGMENT_TYPE_CLASS_ID;
@@ -278,15 +282,16 @@ void SetPathLogicalSegmentLogicalType(LogicalSegmentLogicalType logical_type,
       (*cip_path) |= LOGICAL_SEGMENT_TYPE_EXTENDED_LOGICAL;
       break;
     default:
-      OPENER_ASSERT(
+      OPENER_TRACE_ERR(
         "Logical segment/logical type: It is not possible to reach this point!\n");
+      OPENER_ASSERT(false);
       break;
   }
 }
 
 LogicalSegmentLogicalFormat GetPathLogicalSegmentLogicalFormat(
   const unsigned char *const cip_path) {
-  OPENER_ASSERT( kSegmentTypeLogicalSegment == GetPathSegmentType(cip_path) )
+  OPENER_ASSERT( kSegmentTypeLogicalSegment == GetPathSegmentType(cip_path) );
   const unsigned int kLogicalFormatMask = 0x03;
   const unsigned int logical_format = (*cip_path) & kLogicalFormatMask;
   LogicalSegmentLogicalFormat result = kLogicalSegmentLogicalFormatEightBit;
@@ -301,8 +306,9 @@ LogicalSegmentLogicalFormat GetPathLogicalSegmentLogicalFormat(
       result = kLogicalSegmentLogicalFormatThirtyTwoBit;
       break;
     default:
-      OPENER_ASSERT(
-        "Logical segment/logical type: Invalid logical type detected!\n")
+      OPENER_TRACE_ERR(
+        "Logical segment/logical type: Invalid logical type detected!\n");
+      OPENER_ASSERT(false);
       break;
   }
   return result;
@@ -311,7 +317,7 @@ LogicalSegmentLogicalFormat GetPathLogicalSegmentLogicalFormat(
 void SetPathLogicalSegmentLogicalFormat(LogicalSegmentLogicalFormat format,
                                         CipOctet *const cip_path) {
   OPENER_ASSERT( kSegmentTypeLogicalSegment ==
-                 GetPathSegmentType( (const CipOctet *)cip_path ) )
+                 GetPathSegmentType( (const CipOctet *)cip_path ) );
   switch (format) {
     case kLogicalSegmentLogicalFormatEightBit:
       (*cip_path) |= LOGICAL_SEGMENT_FORMAT_EIGHT_BIT;
@@ -323,8 +329,9 @@ void SetPathLogicalSegmentLogicalFormat(LogicalSegmentLogicalFormat format,
       (*cip_path) |= LOGICAL_SEGMENT_FORMAT_THIRTY_TWO_BIT;
       break;
     default:
-      OPENER_ASSERT(
-        "Logical segment/logical type: Invalid logical type detected!\n")
+      OPENER_TRACE_ERR(
+        "Logical segment/logical type: Invalid logical type detected!\n");
+      OPENER_ASSERT(false);
       break;
   }
 }
@@ -347,7 +354,7 @@ CipDword CipEpathGetLogicalValue(const EipUint8 **message) {
       data = GetDintFromMessage(message);
       break;
     default:
-      OPENER_ASSERT(false) /* shall not happen! */
+      OPENER_ASSERT(false);/* shall not happen! */
       break;
   }
   return data;
@@ -370,7 +377,7 @@ size_t CipEpathSetLogicalValue(const CipDword logical_value,
       written_bytes += AddDintToMessage(logical_value, message);
       break;
     default:
-      OPENER_ASSERT(false) /* This should never happen! */
+      OPENER_ASSERT(false);/* This should never happen! */
       written_bytes = 0;
   }
   return written_bytes;
@@ -381,7 +388,7 @@ LogicalSegmentExtendedLogicalType GetPathLogicalSegmentExtendedLogicalType(
 /*  OPENER_ASSERT(LOGICAL_SEGMENT_TYPE_EXTENDED_kLogicalSegmentLogicalTypeExtendedLogicalMessageValue == GetPathLogicalSegmentLogicalType(cip_path),
                 "Trying to extract non-existent extended logical type") */
   OPENER_ASSERT( kLogicalSegmentLogicalTypeExtendedLogical == GetPathLogicalSegmentLogicalType(
-                   cip_path) )
+                   cip_path) );
   const unsigned int extended_logical_type = *(cip_path + 1);
   LogicalSegmentExtendedLogicalType result =
     kLogicalSegmentExtendedLogicalTypeReserved;
@@ -407,9 +414,9 @@ LogicalSegmentSpecialTypeLogicalFormat
 GetPathLogicalSegmentSpecialTypeLogicalType(const unsigned char *const cip_path)
 {
 /*  OPENER_ASSERT(kSegmentTypeLogicalSegment == GetPathSegmentType(cip_path), "Not a logical segment!\n") */
-  OPENER_ASSERT( kSegmentTypeLogicalSegment == GetPathSegmentType(cip_path) )
+  OPENER_ASSERT( kSegmentTypeLogicalSegment == GetPathSegmentType(cip_path) );
   OPENER_ASSERT( kLogicalSegmentLogicalTypeSpecial == GetPathLogicalSegmentLogicalType(
-                   cip_path) )
+                   cip_path) );
   const unsigned int kLogicalFormatMask = 0x03;
   const unsigned int logical_format = (*cip_path) & kLogicalFormatMask;
 
@@ -428,7 +435,7 @@ ElectronicKeySegmentFormat GetPathLogicalSegmentElectronicKeyFormat(
 /*  OPENER_ASSERT(kLogicalSegmentSpecialTypeLogicalFormatElectronicKey ==
       GetPathLogicalSegmentSpecialTypeLogicalType(cip_path), "Not an electronic key!\n") */
   OPENER_ASSERT( kLogicalSegmentSpecialTypeLogicalFormatElectronicKey ==
-                 GetPathLogicalSegmentSpecialTypeLogicalType(cip_path) )
+                 GetPathLogicalSegmentSpecialTypeLogicalType(cip_path) );
   ElectronicKeySegmentFormat result = kElectronicKeySegmentFormatReserved;
   switch( *(cip_path + 1) ) {
     case ELECTRONIC_KEY_SEGMENT_KEY_FORMAT_4: result =
@@ -442,7 +449,7 @@ void GetElectronicKeyFormat4FromMessage(
   const CipOctet **const message,
   ElectronicKeyFormat4 *key) {
   OPENER_ASSERT( kElectronicKeySegmentFormatKeyFormat4 ==
-                 GetPathLogicalSegmentElectronicKeyFormat(*message) )
+                 GetPathLogicalSegmentElectronicKeyFormat(*message) );
 
   MoveMessageNOctets(2, message);
   ElectronicKeyFormat4SetVendorId(key, GetIntFromMessage(message) );
@@ -465,7 +472,7 @@ void GetElectronicKeyFormat4FromMessage(
  */
 NetworkSegmentSubtype GetPathNetworkSegmentSubtype(
   const unsigned char *const cip_path) {
-  OPENER_ASSERT( kSegmentTypeNetworkSegment == GetPathSegmentType(cip_path) )
+  OPENER_ASSERT( kSegmentTypeNetworkSegment == GetPathSegmentType(cip_path) );
   const unsigned int kSubtypeMask = 0x1F;
   const unsigned int subtype = (*cip_path) & kSubtypeMask;
   NetworkSegmentSubtype result = kNetworkSegmentSubtypeReserved;
@@ -499,9 +506,9 @@ CipUsint GetPathNetworkSegmentProductionInhibitTimeInMilliseconds(
 /*  OPENER_ASSERT(kSegmentTypeNetworkSegment == GetPathSegmentType(cip_path),"Not a network segment!\n")
    OPENER_ASSERT(kNetworkSegmentSubtypeProductionInhibitTimeInMilliseconds == GetPathNetworkSegmentSubtype(cip_path),
                 "Not a Production Inhibit Time milliseconds segment!\n") */
-  OPENER_ASSERT( kSegmentTypeNetworkSegment == GetPathSegmentType(cip_path) )
+  OPENER_ASSERT( kSegmentTypeNetworkSegment == GetPathSegmentType(cip_path) );
   OPENER_ASSERT( kNetworkSegmentSubtypeProductionInhibitTimeInMilliseconds == GetPathNetworkSegmentSubtype(
-                   cip_path) )
+                   cip_path) );
   return *(cip_path + 1);
 }
 
@@ -518,10 +525,10 @@ CipUdint GetPathNetworkSegmentProductionInhibitTimeInMicroseconds(
                   "Not a Production Inhibit Time microseconds segment!\n")
    OPENER_ASSERT(2 == *(cip_path + 1), "Data Words length is incorrect! See CIP Spec Vol.1 C-1.4.3.3.2\n") */
 
-  OPENER_ASSERT( kSegmentTypeNetworkSegment == GetPathSegmentType(cip_path) )
+  OPENER_ASSERT( kSegmentTypeNetworkSegment == GetPathSegmentType(cip_path) );
   OPENER_ASSERT( kNetworkSegmentSubtypeProductionInhibitTimeInMicroseconds == GetPathNetworkSegmentSubtype(
-                   cip_path) )
-  OPENER_ASSERT( 2 == *(cip_path + 1) )
+                   cip_path) );
+  OPENER_ASSERT( 2 == *(cip_path + 1) );
 
   const unsigned char *message_runner = cip_path + 2;
   return GetDintFromMessage(&message_runner);
@@ -545,7 +552,7 @@ unsigned int GetPathSymbolicSegmentASCIIFormatLength(
   const unsigned char *const cip_path) {
   const unsigned int kSymbolicSegmentASCIIFormatLength = 0x1F;
   const unsigned int length = *cip_path & kSymbolicSegmentASCIIFormatLength;
-  OPENER_ASSERT(0 != length)
+  OPENER_ASSERT(0 != length);
   return length;
 }
 
@@ -569,9 +576,9 @@ SymbolicSegmentExtendedFormat GetPathSymbolicSegmentNumericType(
 
 SymbolicSegmentExtendedFormat GetPathSymbolicSegmentExtendedFormat(
   const unsigned char *const cip_path) {
-  OPENER_ASSERT( kSegmentTypeSymbolicSegment == GetPathSegmentType(cip_path) )
+  OPENER_ASSERT( kSegmentTypeSymbolicSegment == GetPathSegmentType(cip_path) );
   OPENER_ASSERT( kSymbolicSegmentFormatExtendedString == GetPathSymbolicSegmentFormat(
-                   cip_path) )
+                   cip_path) );
   const unsigned int kSymbolicSegmentExtendedFormatMask = 0xE0;
   const unsigned int extended_type = *(cip_path + 1) &
                                      kSymbolicSegmentExtendedFormatMask;
@@ -617,9 +624,9 @@ CipUsint GetPathDataSegmentSimpleDataWordLength(
   const unsigned char *const cip_path) {
 /*  OPENER_ASSERT(kSegmentTypeDataSegment == GetPathSegmentType(cip_path),"Not a data segment!\n");
     OPENER_ASSERT(kDataSegmentSubtypeSimpleData == GetPathDataSegmentSubtype(cip_path), "Not a simple data segment!\n") */
-  OPENER_ASSERT( kSegmentTypeDataSegment == GetPathSegmentType(cip_path) )
+  OPENER_ASSERT( kSegmentTypeDataSegment == GetPathSegmentType(cip_path) );
   OPENER_ASSERT( kDataSegmentSubtypeSimpleData ==
-                 GetPathDataSegmentSubtype(cip_path) )
+                 GetPathDataSegmentSubtype(cip_path) );
 
   const unsigned char *message_runner = cip_path + 1;
   return GetSintFromMessage(&message_runner);

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

@@ -133,7 +133,7 @@ EipUint16 SetupIoConnectionOriginatorToTargetConnectionPoint(
     /* an assembly object should always have an attribute 3 */
     CipAttributeStruct *attribute = GetCipAttribute(instance,
                                                     io_connection_object->consumed_path.attribute_id_or_connection_point);
-    OPENER_ASSERT(attribute != NULL)
+    OPENER_ASSERT(attribute != NULL);
 #ifdef OPENER_CONSUMED_DATA_HAS_RUN_IDLE_HEADER
     bool is_heartbeat = ( ( (CipByteArray *) attribute->data )->length == 0 );
 #endif
@@ -235,7 +235,7 @@ EipUint16 SetupIoConnectionTargetToOriginatorConnectionPoint(
     io_connection_object->produced_path.attribute_id_or_connection_point = 3;
     CipAttributeStruct *attribute = GetCipAttribute(instance,
                                                     io_connection_object->produced_path.attribute_id_or_connection_point);
-    OPENER_ASSERT(attribute != NULL)
+    OPENER_ASSERT(attribute != NULL);
 #ifdef OPENER_PRODUCED_DATA_HAS_RUN_IDLE_HEADER
     bool is_heartbeat = ( ( (CipByteArray *) attribute->data )->length == 0 );
 #endif
@@ -308,7 +308,7 @@ EipStatus EstablishIoConnection(
   OPENER_ASSERT( !(originator_to_target_connection_type ==
                    kConnectionObjectConnectionTypeNull &&
                    target_to_originator_connection_type ==
-                   kConnectionObjectConnectionTypeNull) )
+                   kConnectionObjectConnectionTypeNull) );
 
   io_connection_object->consuming_instance = NULL;
   io_connection_object->consumed_connection_path_length = 0;
@@ -631,7 +631,7 @@ EipUint16 HandleConfigData(CipConnectionObject *connection_object) {
     assembly_class, connection_object->configuration_path.instance_id);
 
   if (0 != g_config_data_length) {
-    OPENER_ASSERT(NULL != config_instance)
+    OPENER_ASSERT(NULL != config_instance);
     if ( ConnectionWithSameConfigPointExists(
            connection_object->configuration_path.instance_id) ) {
       /* there is a connected connection with the same config point
@@ -639,10 +639,10 @@ EipUint16 HandleConfigData(CipConnectionObject *connection_object) {
       CipAttributeStruct *attribute_three = GetCipAttribute(
         config_instance,
         3);
-      OPENER_ASSERT(NULL != attribute_three)
+      OPENER_ASSERT(NULL != attribute_three);
       CipByteArray * attribute_three_data =
         (CipByteArray *) attribute_three->data;
-      OPENER_ASSERT(NULL != attribute_three_data)
+      OPENER_ASSERT(NULL != attribute_three_data);
       if (attribute_three_data->length != g_config_data_length) {
         connection_manager_status =
           kConnectionManagerExtendedStatusCodeErrorOwnershipConflict;

+ 2 - 2
source/src/cip/cipmessagerouter.c

@@ -113,7 +113,7 @@ CipMessageRouterObject *GetRegisteredObject(EipUint32 class_id) {
 
   while (NULL != object) /* for each entry in list*/
   {
-    OPENER_ASSERT(NULL != object->cip_class)
+    OPENER_ASSERT(NULL != object->cip_class);
     if (object->cip_class->class_code == class_id) {
       return object; /* return registration node if it matches class ID*/
     }
@@ -213,7 +213,7 @@ EipStatus NotifyMessageRouter(EipUint8 *data,
       /* call notify function from Object with ClassID (gMRRequest.RequestPath.ClassID)
          object will or will not make an reply into gMRResponse*/
       g_message_router_response.reserved = 0;
-      OPENER_ASSERT(NULL != registered_object->cip_class)
+      OPENER_ASSERT(NULL != registered_object->cip_class);
       OPENER_TRACE_INFO(
         "NotifyMessageRouter: calling notify function of class '%s'\n",
         registered_object->cip_class->class_name);

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

@@ -726,7 +726,7 @@ void CipTcpIpCalculateMulticastIp(CipTcpIpObject *const tcpip)
 
 EipUint16 GetEncapsulationInactivityTimeout(CipInstance *instance) {
   CipAttributeStruct *attribute = GetCipAttribute(instance, 13);
-  OPENER_ASSERT(NULL != attribute)
+  OPENER_ASSERT(NULL != attribute);
   CipUint * data = (CipUint *) attribute->data;
   EipUint16 encapsulation_inactivity_timeout = *data;
   return encapsulation_inactivity_timeout;

+ 2 - 2
source/src/enet_encap/cpf.c

@@ -219,7 +219,7 @@ EipStatus CreateCommonPacketFormatStructure(
 
   int length_count = 0;
   CipUint item_count = GetIntFromMessage(&data);
-  OPENER_ASSERT(4U >= item_count) /* Sanitizing data - probably needs to be changed for productive code */
+  OPENER_ASSERT(4U >= item_count);/* Sanitizing data - probably needs to be changed for productive code */
   common_packet_format_data->item_count = item_count;
   length_count += 2;
   if (common_packet_format_data->item_count >= 1U) {
@@ -629,7 +629,7 @@ int EncodeSockaddrInfoItemTypeId(
   int item_type,
   const CipCommonPacketFormatData *const common_packet_format_data_item,
   ENIPMessage *const outgoing_message) {
-  OPENER_ASSERT(item_type == 0 || item_type == 1)
+  OPENER_ASSERT(item_type == 0 || item_type == 1);
   outgoing_message->used_message_length += AddIntToMessage(
     common_packet_format_data_item->address_info_item[item_type].type_id,
     &outgoing_message->current_message_position);

+ 48 - 43
source/src/ports/MINGW/sample_application/opener_user_conf.h

@@ -160,49 +160,54 @@ typedef unsigned short in_port_t;
 static const MilliSeconds kOpenerTimerTickInMilliSeconds = 10;
 
 #ifdef OPENER_WITH_TRACES
-/* If we have tracing enabled provide print tracing macro */
-#include <stdio.h>
-
-#define LOG_TRACE(...)  fprintf(stderr,__VA_ARGS__)
-
-/*#define PRINT_TRACE(args...)  fprintf(stderr,args);*/
-
-/** @brief A specialized assertion command that will log the assertion and block
- *  further execution in an while(1) loop.
- */
-#define OPENER_ASSERT(assertion) \
-  do { \
-    if( !(assertion) ) { \
-      LOG_TRACE("Assertion \"%s\" failed: file \"%s\", line %d\n", \
-                # assertion, \
-                __FILE__, \
-                __LINE__); \
-      while(1) {;} \
-    } \
-  } while(0);
-
-/* else use standard assert() */
-//#include <assert.h>
-//#include <stdio.h>
-//#define OPENER_ASSERT(assertion) assert(assertion)
-#else
-
-/* for release builds execute the assertion, but don't test it */
-//#define OPENER_ASSERT(assertion) (assertion)
-
-/* the above may result in "statement with no effect" warnings.
- *  If you do not use assert()s to run functions, the an empty
- *  macro can be used as below
- */
-#define OPENER_ASSERT(assertion)
-/* else if you still want assertions to stop execution but without tracing, use the following */
-//#define OPENER_ASSERT(assertion) do { if(!(assertion)) { while(1){;} } } while (0)
-/* else use standard assert() */
-//#include <assert.h>
-//#include <stdio.h>
-//#define OPENER_ASSERT(assertion) assert(assertion)
-
-#endif
+    /* If we have tracing enabled provide LOG_TRACE macro */
+    #include <stdio.h>
+
+    #define LOG_TRACE(...)  fprintf(stderr,__VA_ARGS__)
+
+     #ifdef IDLING_ASSERT
+        /** @brief A specialized assertion command enabled by IDLING_ASSERT that
+         *  will log the assertion and block further
+         *  execution in a while(1) loop.
+         */
+        #define OPENER_ASSERT(assertion)                                    \
+          do {                                                              \
+            if( !(assertion) ) {                                            \
+              LOG_TRACE("Assertion \"%s\" failed: file \"%s\", line %d\n",  \
+                        # assertion, __FILE__, __LINE__);                   \
+              while(1) {  }                                                 \
+            }                                                               \
+          } while(0)
+
+    #else   /* ifdef IDLING_ASSERT */
+        /* Use standard assert() that vanishes only for release builds. */
+        #define OPENER_ASSERT(assertion) assert(assertion)
+    #endif  /* ifdef IDLING_ASSERT */
+
+#else   /* ifdef OPENER_WITH_TRACES */
+    /* Select one of the OPENER_ASSERT() variants below if trace support is off */
+    #if 0
+        /* If there are any strange timing issues, you can try the version below,
+         *  where the assertion is performed but the assert function is not used.
+         *  This may result in "statement with no effect" warnings.
+         */
+        #define OPENER_ASSERT(assertion) (assertion)
+    #elif 0
+    /* If you still want assertions to stop execution but without tracing,
+     *  use the following */
+        #define OPENER_ASSERT(assertion)                    \
+          do { if(!(assertion)) { while(1) {} } } while (0)
+    #elif 0
+        /* Even for debug builds remove assertion. May solicit unused variable
+         *  warnings. */
+        #define OPENER_ASSERT(assertion)
+    #else
+        /* By default use standard assert() that vanishes only
+         *  for release builds. */
+        #define OPENER_ASSERT(assertion) assert(assertion)
+    #endif
+
+#endif  /* ifdef OPENER_WITH_TRACES */
 
 /** @brief The number of bytes used for the Ethernet message buffer on
  * the PC port. For different platforms it may makes sense to

+ 1 - 1
source/src/ports/POSIX/networkhandler.c

@@ -23,7 +23,7 @@ MicroSeconds GetMicroSeconds(void) {
   struct timespec now = { .tv_nsec = 0, .tv_sec = 0 };
 
   int error = clock_gettime( CLOCK_MONOTONIC, &now );
-  OPENER_ASSERT(-1 != error)
+  OPENER_ASSERT(-1 != error);
   MicroSeconds micro_seconds =  (MicroSeconds)now.tv_nsec / 1000ULL +
                                now.tv_sec * 1000000ULL;
   return micro_seconds;

+ 48 - 46
source/src/ports/POSIX/sample_application/opener_user_conf.h

@@ -164,52 +164,54 @@
 static const MilliSeconds kOpenerTimerTickInMilliSeconds = 10;
 
 #ifdef OPENER_WITH_TRACES
-/* If we have tracing enabled provide print tracing macro */
-#include <stdio.h>
-
-#define LOG_TRACE(...)  fprintf(stderr,__VA_ARGS__)
-
-/*#define PRINT_TRACE(args...)  fprintf(stderr,args);*/
-
-/** @brief A specialized assertion command that will log the assertion and block
- *  further execution in an while(1) loop.
- */
-#ifdef IDLING_ASSERT
-#define OPENER_ASSERT(assertion) \
-  do { \
-    if( !(assertion) ) { \
-      LOG_TRACE("Assertion \"%s\" failed: file \"%s\", line %d\n", \
-                # assertion, \
-                __FILE__, \
-                __LINE__); \
-      while(1) {  } \
-    } \
-  } while(0);
-
-/* else use standard assert() */
-//#include <assert.h>
-//#include <stdio.h>
-//#define OPENER_ASSERT(assertion) assert(assertion)
-#else
-#define OPENER_ASSERT(assertion) assert(assertion);
-#endif
-#else
-
-/* for release builds remove assertion */
-#define OPENER_ASSERT(assertion)
-
-/* if there are any strange timing issues, you can try the version below, where the assertion is performed but the assert
- * function is not used
- */
-//#define OPENER_ASSERT(assertion) (assertion)
-/* else if you still want assertions to stop execution but without tracing, use the following */
-//#define OPENER_ASSERT(assertion) do { if(!(assertion)) { while(1){;} } } while (0)
-/* else use standard assert() */
-//#include <assert.h>
-//#include <stdio.h>
-//#define OPENER_ASSERT(assertion) assert(assertion)
-
-#endif
+    /* If we have tracing enabled provide LOG_TRACE macro */
+    #include <stdio.h>
+
+    #define LOG_TRACE(...)  fprintf(stderr,__VA_ARGS__)
+
+     #ifdef IDLING_ASSERT
+        /** @brief A specialized assertion command enabled by IDLING_ASSERT that
+         *  will log the assertion and block further
+         *  execution in a while(1) loop.
+         */
+        #define OPENER_ASSERT(assertion)                                    \
+          do {                                                              \
+            if( !(assertion) ) {                                            \
+              LOG_TRACE("Assertion \"%s\" failed: file \"%s\", line %d\n",  \
+                        # assertion, __FILE__, __LINE__);                   \
+              while(1) {  }                                                 \
+            }                                                               \
+          } while(0)
+
+    #else   /* ifdef IDLING_ASSERT */
+        /* Use standard assert() that vanishes only for release builds. */
+        #define OPENER_ASSERT(assertion) assert(assertion)
+    #endif  /* ifdef IDLING_ASSERT */
+
+#else   /* ifdef OPENER_WITH_TRACES */
+    /* Select one of the OPENER_ASSERT() variants below if trace support is off */
+    #if 0
+        /* If there are any strange timing issues, you can try the version below,
+         *  where the assertion is performed but the assert function is not used.
+         *  This may result in "statement with no effect" warnings.
+         */
+        #define OPENER_ASSERT(assertion) (assertion)
+    #elif 0
+    /* If you still want assertions to stop execution but without tracing,
+     *  use the following */
+        #define OPENER_ASSERT(assertion)                    \
+          do { if(!(assertion)) { while(1) {} } } while (0)
+    #elif 0
+        /* Even for debug builds remove assertion. May solicit unused variable
+         *  warnings. */
+        #define OPENER_ASSERT(assertion)
+    #else
+        /* By default use standard assert() that vanishes only
+         *  for release builds. */
+        #define OPENER_ASSERT(assertion) assert(assertion)
+    #endif
+
+#endif  /* ifdef OPENER_WITH_TRACES */
 
 /** @brief The number of bytes used for the Ethernet message buffer on
  * the PC port. For different platforms it may makes sense to

+ 48 - 46
source/src/ports/WIN32/sample_application/opener_user_conf.h

@@ -163,52 +163,54 @@ typedef unsigned short in_port_t;
 static const MilliSeconds kOpenerTimerTickInMilliSeconds = 10;
 
 #ifdef OPENER_WITH_TRACES
-/* If we have tracing enabled provide print tracing macro */
-#include <stdio.h>
-
-#define LOG_TRACE(...)  fprintf(stderr,__VA_ARGS__)
-
-/*#define PRINT_TRACE(args...)  fprintf(stderr,args);*/
-
-/** @brief A specialized assertion command that will log the assertion and block
- *  further execution in an while(1) loop.
- */
-#ifdef IDLING_ASSERT
-#define OPENER_ASSERT(assertion) \
-  do { \
-    if( !(assertion) ) { \
-      LOG_TRACE("Assertion \"%s\" failed: file \"%s\", line %d\n", \
-                # assertion, \
-                __FILE__, \
-                __LINE__); \
-      while(1) {;} \
-    } \
-  } while(0);
-#else
-#define OPENER_ASSERT(assertion) assert(assertion);
-#endif
-/* else use standard assert() */
-//#include <assert.h>
-//#include <stdio.h>
-//#define OPENER_ASSERT(assertion) assert(assertion)
-#else
-
-/* for release builds execute the assertion, but don't test it */
-#define OPENER_ASSERT(assertion) (assertion);
-
-/* the above may result in "statement with no effect" warnings.
- *  If you do not use assert()s to run functions, the an empty
- *  macro can be used as below
- */
-//#define OPENER_ASSERT(assertion)
-/* else if you still want assertions to stop execution but without tracing, use the following */
-//#define OPENER_ASSERT(assertion) do { if(!(assertion)) { while(1){;} } } while (0)
-/* else use standard assert() */
-//#include <assert.h>
-//#include <stdio.h>
-//#define OPENER_ASSERT(assertion) assert(assertion)
-
-#endif
+    /* If we have tracing enabled provide LOG_TRACE macro */
+    #include <stdio.h>
+
+    #define LOG_TRACE(...)  fprintf(stderr,__VA_ARGS__)
+
+     #ifdef IDLING_ASSERT
+        /** @brief A specialized assertion command enabled by IDLING_ASSERT that
+         *  will log the assertion and block further
+         *  execution in a while(1) loop.
+         */
+        #define OPENER_ASSERT(assertion)                                    \
+          do {                                                              \
+            if( !(assertion) ) {                                            \
+              LOG_TRACE("Assertion \"%s\" failed: file \"%s\", line %d\n",  \
+                        # assertion, __FILE__, __LINE__);                   \
+              while(1) {  }                                                 \
+            }                                                               \
+          } while(0)
+
+    #else   /* ifdef IDLING_ASSERT */
+        /* Use standard assert() that vanishes only for release builds. */
+        #define OPENER_ASSERT(assertion) assert(assertion)
+    #endif  /* ifdef IDLING_ASSERT */
+
+#else   /* ifdef OPENER_WITH_TRACES */
+    /* Select one of the OPENER_ASSERT() variants below if trace support is off */
+    #if 0
+        /* If there are any strange timing issues, you can try the version below,
+         *  where the assertion is performed but the assert function is not used.
+         *  This may result in "statement with no effect" warnings.
+         */
+        #define OPENER_ASSERT(assertion) (assertion)
+    #elif 0
+    /* If you still want assertions to stop execution but without tracing,
+     *  use the following */
+        #define OPENER_ASSERT(assertion)                    \
+          do { if(!(assertion)) { while(1) {} } } while (0)
+    #elif 0
+        /* Even for debug builds remove assertion. May solicit unused variable
+         *  warnings. */
+        #define OPENER_ASSERT(assertion)
+    #else
+        /* By default use standard assert() that vanishes only
+         *  for release builds. */
+        #define OPENER_ASSERT(assertion) assert(assertion)
+    #endif
+
+#endif  /* ifdef OPENER_WITH_TRACES */
 
 /** @brief The number of bytes used for the Ethernet message buffer on
  * the PC port. For different platforms it may makes sense to

+ 2 - 2
source/src/ports/generic_networkhandler.c

@@ -393,7 +393,7 @@ void CheckAndHandleTcpListenerSocket(void) {
 //                        g_timestamps[i].last_update);
 //    }
 
-    OPENER_ASSERT(socket_timer != NULL)
+    OPENER_ASSERT(socket_timer != NULL);
 
     FD_SET(new_socket, &master_socket);
     /* add newfd to master set */
@@ -903,7 +903,7 @@ int CreateUdpSocket(UdpCommuncationDirection communication_direction,
     OPENER_TRACE_ERR(
       "error setting socket to non-blocking on new socket\n");
     CloseUdpSocket(new_socket);
-    OPENER_ASSERT(false) /* This should never happen! */
+    OPENER_ASSERT(false);/* This should never happen! */
     return kEipInvalidSocket;
   }
 

+ 5 - 5
source/src/utils/doublylinkedlist.c

@@ -44,13 +44,13 @@ DoublyLinkedListNode *DoublyLinkedListNodeCreate(
 
 void DoublyLinkedListNodeDestroy(const DoublyLinkedList *const list,
                                  DoublyLinkedListNode **node) {
-  OPENER_ASSERT(list->deallocator != NULL)
+  OPENER_ASSERT(list->deallocator != NULL);
   list->deallocator(node);
 }
 
 void DoublyLinkedListInsertAtHead(DoublyLinkedList *const list,
                                   void *data) {
-  OPENER_ASSERT(list->allocator != NULL)
+  OPENER_ASSERT(list->allocator != NULL);
   DoublyLinkedListNode * new_node = DoublyLinkedListNodeCreate(data,
                                                                list->allocator);
   if(NULL == list->first) {
@@ -65,7 +65,7 @@ void DoublyLinkedListInsertAtHead(DoublyLinkedList *const list,
 
 void DoublyLinkedListInsertAtTail(DoublyLinkedList *const list,
                                   const void *const data) {
-  OPENER_ASSERT(list->allocator != NULL)
+  OPENER_ASSERT(list->allocator != NULL);
   DoublyLinkedListNode * new_node = DoublyLinkedListNodeCreate(data,
                                                                list->allocator);
   if(NULL == list->last) {
@@ -81,7 +81,7 @@ void DoublyLinkedListInsertAtTail(DoublyLinkedList *const list,
 void DoublyLinkedListInsertBeforeNode(DoublyLinkedList *const list,
                                       DoublyLinkedListNode *node,
                                       void *data) {
-  OPENER_ASSERT(list->allocator != NULL)
+  OPENER_ASSERT(list->allocator != NULL);
   if(list->first == node) {
     DoublyLinkedListInsertAtHead(list, data);
   } else {
@@ -97,7 +97,7 @@ void DoublyLinkedListInsertBeforeNode(DoublyLinkedList *const list,
 void DoublyLinkedListInsertAfterNode(DoublyLinkedList *const list,
                                      DoublyLinkedListNode *node,
                                      void *data) {
-  OPENER_ASSERT(list->allocator != NULL)
+  OPENER_ASSERT(list->allocator != NULL);
   if(list->last == node) {
     DoublyLinkedListInsertAtTail(list, data);
   } else {