diff --git a/Makefile b/Makefile index f8fc3641..d04ca267 100644 --- a/Makefile +++ b/Makefile @@ -212,11 +212,12 @@ pretty-ports: find ./ports -maxdepth 2 -type f -iname *.h -o -iname *.c -exec \ clang-format -i -style=file -fallback-style=none {} \; +CLANG_TIDY_OPTIONS = -fix-errors -checks="readability-braces-around-statements" +CLANG_TIDY_OPTIONS += -- -Isrc -Iports/linux .PHONY: tidy tidy: - find ./src -iname *.h -o -iname *.c -exec \ - clang-tidy {} -fix-errors -checks="readability-braces-around-statements" \ - -- -Isrc -Iports/linux \; + find ./src -iname *.h -o -iname *.c -exec clang-tidy {} $(CLANG_TIDY_OPTIONS) \; + find ./apps -iname *.c -exec clang-tidy {} $(CLANG_TIDY_OPTIONS) \; .PHONY: lint lint: diff --git a/apps/ack-alarm/main.c b/apps/ack-alarm/main.c index 6b7c8533..9e0a73e1 100644 --- a/apps/ack-alarm/main.c +++ b/apps/ack-alarm/main.c @@ -393,8 +393,9 @@ int main(int argc, char *argv[]) tsm_timer_milliseconds( (uint16_t)((current_seconds - last_seconds) * 1000)); } - if (Error_Detected) + if (Error_Detected) { break; +} /* wait until the device is bound, or timeout and quit */ if (!found) { found = address_bind_request( diff --git a/apps/dcc/main.c b/apps/dcc/main.c index 312499ae..f0fa67ba 100644 --- a/apps/dcc/main.c +++ b/apps/dcc/main.c @@ -246,8 +246,9 @@ int main(int argc, char *argv[]) tsm_timer_milliseconds( (uint16_t)((current_seconds - last_seconds) * 1000)); } - if (Error_Detected) + if (Error_Detected) { break; +} /* wait until the device is bound, or timeout and quit */ if (!found) { found = address_bind_request( diff --git a/apps/epics/main.c b/apps/epics/main.c index 06a0699d..f590a3bd 100644 --- a/apps/epics/main.c +++ b/apps/epics/main.c @@ -215,11 +215,12 @@ static void MyAbortHandler( #endif Error_Detected = true; Last_Error_Class = ERROR_CLASS_SERVICES; - if (abort_reason < MAX_BACNET_ABORT_REASON) + if (abort_reason < MAX_BACNET_ABORT_REASON) { Last_Error_Code = (ERROR_CODE_ABORT_BUFFER_OVERFLOW - 1) + abort_reason; - else + } else { Last_Error_Code = ERROR_CODE_ABORT_OTHER; +} } } @@ -236,11 +237,12 @@ static void MyRejectHandler( #endif Error_Detected = true; Last_Error_Class = ERROR_CLASS_SERVICES; - if (reject_reason < MAX_BACNET_REJECT_REASON) + if (reject_reason < MAX_BACNET_REJECT_REASON) { Last_Error_Code = (ERROR_CODE_REJECT_BUFFER_OVERFLOW - 1) + reject_reason; - else + } else { Last_Error_Code = ERROR_CODE_REJECT_OTHER; +} } } @@ -265,8 +267,9 @@ static void MyReadPropertyAckHandler(uint8_t *service_request, Read_Property_Multiple_Data.rpm_data = rp_data; Read_Property_Multiple_Data.new_data = true; } else { - if (len < 0) /* Eg, failed due to no segmentation */ + if (len < 0) { /* Eg, failed due to no segmentation */ Error_Detected = true; +} free(rp_data); } } @@ -294,8 +297,9 @@ static void MyReadPropertyMultipleAckHandler(uint8_t *service_request, Read_Property_Multiple_Data.new_data = true; /* Will process and free the RPM data later */ } else { - if (len < 0) /* Eg, failed due to no segmentation */ + if (len < 0) { /* Eg, failed due to no segmentation */ Error_Detected = true; +} free(rpm_data); } } @@ -421,9 +425,10 @@ static void CheckIsWritableProperty(BACNET_OBJECT_TYPE object_type, * Life Safety Tracking_Value, Reliability, Mode, * or Present_Value when Out_Of_Service is TRUE. */ - if (bIsWritable) + if (bIsWritable) { fprintf(stdout, " Writable"); } +} static const char *protocol_services_supported_text(size_t bit_index) { @@ -498,8 +503,9 @@ static bool PrettyPrintPropertyValue( fprintf(stream, " %s,", protocol_services_supported_text(j)); } - } else /* not supported */ + } else { /* not supported */ fprintf(stream, ","); +} } fprintf(stream, "\n "); } @@ -518,8 +524,9 @@ static bool PrettyPrintPropertyValue( assert(false); /* How did I get here? Fix your code. */ /* Meanwhile, a fallback plan */ status = bacapp_print_value(stdout, object_value); - } else + } else { fprintf(stream, "? \n"); +} return status; } @@ -576,8 +583,9 @@ static void PrintReadPropertyData(BACNET_OBJECT_TYPE object_type, PROP_PROTOCOL_CONFORMANCE_CLASS; break; } - if (object_type == OBJECT_DATETIME_VALUE) + if (object_type == OBJECT_DATETIME_VALUE) { break; /* A special case - no braces for this pair */ +} /* Else, fall through to normal processing. */ default: /* Normal array: open brace */ @@ -587,8 +595,9 @@ static void PrintReadPropertyData(BACNET_OBJECT_TYPE object_type, } } - if (!Using_Walked_List) + if (!Using_Walked_List) { Walked_List_Index = Walked_List_Length = 0; /* In case we need this. */ +} /* value(s) loop until there is no "next" ... */ while (value != NULL) { object_value.object_property = rpm_property->propertyIdentifier; @@ -608,19 +617,22 @@ static void PrintReadPropertyData(BACNET_OBJECT_TYPE object_type, * print it! */ Walked_List_Length = value->type.Unsigned_Int; if (rpm_property->propertyIdentifier == - PROP_OBJECT_LIST) + PROP_OBJECT_LIST) { Object_List_Length = value->type.Unsigned_Int; +} break; - } else + } else { assert(Walked_List_Index == (uint32_t)rpm_property->propertyArrayIndex); +} } else { Walked_List_Index++; /* If we got the whole Object List array in one RP call, * keep the Index and List_Length in sync as we cycle * through. */ - if (rpm_property->propertyIdentifier == PROP_OBJECT_LIST) + if (rpm_property->propertyIdentifier == PROP_OBJECT_LIST) { Object_List_Length = ++Object_List_Index; +} } if (Walked_List_Index == 1) { /* If the array is empty (nothing for this first entry), @@ -634,10 +646,11 @@ static void PrintReadPropertyData(BACNET_OBJECT_TYPE object_type, /* Open this Array of Objects for the first entry (unless * opening brace has already printed, since this is an array * of values[] ) */ - if (value->next == NULL) + if (value->next == NULL) { fprintf(stdout, "{ \n "); - else + } else { fprintf(stdout, "\n "); +} } if (rpm_property->propertyIdentifier == PROP_OBJECT_LIST) { @@ -685,18 +698,21 @@ static void PrintReadPropertyData(BACNET_OBJECT_TYPE object_type, /* If the object is a Sequence, it needs its own bracketing * braces */ - if (isSequence) + if (isSequence) { fprintf(stdout, "{"); +} bacapp_print_value(stdout, &object_value); - if (isSequence) + if (isSequence) { fprintf(stdout, "}"); +} if ((Walked_List_Index < Walked_List_Length) || (value->next != NULL)) { /* There are more. */ fprintf(stdout, ", "); - if (!(Walked_List_Index % 3)) + if (!(Walked_List_Index % 3)) { fprintf(stdout, "\n "); +} } else { fprintf(stdout, " } \n"); } @@ -966,9 +982,9 @@ static EPICS_STATES ProcessRPMData( if (myState == GET_HEADING_RESPONSE) { nextState = PRINT_HEADING; /* press ahead with or without the data */ - } else if (bSuccess && (myState == GET_ALL_RESPONSE)) + } else if (bSuccess && (myState == GET_ALL_RESPONSE)) { nextState = NEXT_OBJECT; - else if (bSuccess) { /* and GET_LIST_OF_ALL_RESPONSE */ + } else if (bSuccess) { /* and GET_LIST_OF_ALL_RESPONSE */ /* Now append the properties we waited on. */ if (bHasStructuredViewList) { Property_List[Property_List_Index] = PROP_STRUCTURED_OBJECT_LIST; @@ -1071,11 +1087,13 @@ static int CheckCommandLineArgs(int argc, char *argv[]) break; case 'n': /* Destination Network Number */ - if (Target_Address.mac_len == 0) + if (Target_Address.mac_len == 0) { fprintf( stderr, "Must provide a Target MAC before DNET \n"); - if (++i < argc) +} + if (++i < argc) { Target_Address.net = (uint16_t)strtol(argv[i], NULL, 0); +} /* Used strtol so dest.net can be either 0x1234 or 4660 */ break; case 't': @@ -1210,8 +1228,9 @@ static void PrintHeading(void) int i, len = bitstring_bits_used(&value->type.Bit_String); printf("-- services reported by this device\n"); for (i = 0; i < len; i++) { - if (bitstring_bit(&value->type.Bit_String, (uint8_t)i)) + if (bitstring_bit(&value->type.Bit_String, (uint8_t)i)) { printf(" %s\n", protocol_services_supported_text(i)); +} } } else { printf("-- use \'Initiate\' or \'Execute\' or both for services.\n"); @@ -1257,8 +1276,9 @@ static void PrintHeading(void) int i, len = bitstring_bits_used(&value->type.Bit_String); printf("-- objects reported by this device\n"); for (i = 0; i < len; i++) { - if (bitstring_bit(&value->type.Bit_String, (uint8_t)i)) + if (bitstring_bit(&value->type.Bit_String, (uint8_t)i)) { printf(" %s\n", bactext_object_type_name(i)); +} } } else { printf("-- possible objects in this device\n"); @@ -1478,8 +1498,9 @@ int main(int argc, char *argv[]) } else { /* Update by adding the MAC address */ - if (max_apdu == 0) + if (max_apdu == 0) { max_apdu = MAX_APDU; /* Whatever set for this datalink. */ +} address_add_binding( Target_Device_Object_Instance, max_apdu, &Target_Address); } @@ -1572,10 +1593,11 @@ int main(int argc, char *argv[]) buffer, MAX_PDU, Target_Device_Object_Instance, rpm_object); if (Request_Invoke_ID > 0) { elapsed_seconds = 0; - if (myState == GET_LIST_OF_ALL_REQUEST) + if (myState == GET_LIST_OF_ALL_REQUEST) { myState = GET_LIST_OF_ALL_RESPONSE; - else + } else { myState = GET_ALL_RESPONSE; +} } break; @@ -1606,10 +1628,10 @@ int main(int argc, char *argv[]) } else if (tsm_invoke_id_free(Request_Invoke_ID)) { elapsed_seconds = 0; Request_Invoke_ID = 0; - if (myState == GET_HEADING_RESPONSE) + if (myState == GET_HEADING_RESPONSE) { myState = PRINT_HEADING; /* just press ahead without the data */ - else if (Error_Detected) { + } else if (Error_Detected) { if (Last_Error_Code == ERROR_CODE_REJECT_UNRECOGNIZED_SERVICE) { /* The normal case for Device Object */ @@ -1620,37 +1642,40 @@ int main(int argc, char *argv[]) ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED) { myState = GET_PROPERTY_REQUEST; StartNextObject(rpm_object, &myObject); - } else if (myState == GET_ALL_RESPONSE) + } else if (myState == GET_ALL_RESPONSE) { /* Try again, just to get a list of properties. */ myState = GET_LIST_OF_ALL_REQUEST; - else { + } else { /* Else drop back to RP. */ myState = GET_PROPERTY_REQUEST; StartNextObject(rpm_object, &myObject); } - } else if (Has_RPM) + } else if (Has_RPM) { myState = GET_ALL_REQUEST; /* Let's try again */ - else + } else { myState = GET_PROPERTY_REQUEST; +} } else if (tsm_invoke_id_failed(Request_Invoke_ID)) { fprintf(stderr, "\rError: TSM Timeout!\n"); tsm_free_invoke_id(Request_Invoke_ID); Request_Invoke_ID = 0; elapsed_seconds = 0; - if (myState == GET_HEADING_RESPONSE) + if (myState == GET_HEADING_RESPONSE) { myState = PRINT_HEADING; /* just press ahead without the data */ - else + } else { myState = GET_ALL_REQUEST; /* Let's try again */ +} } else if (Error_Detected) { /* Don't think we'll ever actually reach this point. */ elapsed_seconds = 0; Request_Invoke_ID = 0; - if (myState == GET_HEADING_RESPONSE) + if (myState == GET_HEADING_RESPONSE) { myState = PRINT_HEADING; /* just press ahead without the data */ - else - myState = NEXT_OBJECT; /* Give up and move on to the + } else { + myState = NEXT_OBJECT; +}/* Give up and move on to the next. */ Error_Count++; } @@ -1668,8 +1693,9 @@ int main(int argc, char *argv[]) if (Request_Invoke_ID == 0) { /* Reached the end of the list. */ myState = NEXT_OBJECT; /* Move on to the next. */ - } else + } else { myState = GET_PROPERTY_RESPONSE; +} break; case GET_PROPERTY_RESPONSE: @@ -1784,8 +1810,9 @@ int main(int argc, char *argv[]) myObject.type = KEY_DECODE_TYPE(nextKey); myObject.instance = KEY_DECODE_ID(nextKey); /* Don't re-list the Device Object among its objects */ - if (myObject.type == OBJECT_DEVICE) + if (myObject.type == OBJECT_DEVICE) { continue; +} /* Closing brace for the previous Object */ printf(" }, \n"); /* Opening brace for the new Object */ @@ -1802,9 +1829,9 @@ int main(int argc, char *argv[]) */ myObject.type = MAX_BACNET_OBJECT_TYPE; } - if (Has_RPM) + if (Has_RPM) { myState = GET_ALL_REQUEST; - else { + } else { myState = GET_PROPERTY_REQUEST; StartNextObject(rpm_object, &myObject); } diff --git a/apps/event/main.c b/apps/event/main.c index 203258ef..bd39a80a 100644 --- a/apps/event/main.c +++ b/apps/event/main.c @@ -585,8 +585,9 @@ int main(int argc, char *argv[]) tsm_timer_milliseconds( (uint16_t)((current_seconds - last_seconds) * 1000)); } - if (Error_Detected) + if (Error_Detected) { break; +} /* wait until the device is bound, or timeout and quit */ if (!found) { found = address_bind_request( diff --git a/apps/getevent/main.c b/apps/getevent/main.c index ff3a8b9b..8dcc94b4 100644 --- a/apps/getevent/main.c +++ b/apps/getevent/main.c @@ -125,8 +125,9 @@ static void My_Get_Event_Ack_Handler(uint8_t *service_request, int len = 0; int i; BACNET_GET_EVENT_INFORMATION_DATA data[MAX_OBJ_IDS_IN_GE_ACK]; - for (i = 0; i < MAX_OBJ_IDS_IN_GE_ACK - 1; i++) + for (i = 0; i < MAX_OBJ_IDS_IN_GE_ACK - 1; i++) { data[i].next = &data[i + 1]; +} printf("Recieved Ack. Saved invoke ID was %i, service returned %i\n", Request_Invoke_ID, service_data->invoke_id); @@ -140,8 +141,9 @@ static void My_Get_Event_Ack_Handler(uint8_t *service_request, ge_ack_print_data(&(data[0]), Target_Device_Object_Instance); if (More_Events) { BACNET_GET_EVENT_INFORMATION_DATA *lastData = &(data[0]); - while (lastData->next) + while (lastData->next) { lastData = lastData->next; +} LastReceivedObjectIdentifier = lastData->objectIdentifier; } } @@ -283,7 +285,8 @@ int main(int argc, char *argv[]) /* keep track of time for next check */ last_seconds = current_seconds; } - if (Error_Detected) + if (Error_Detected) { return 1; +} return 0; } diff --git a/apps/initrouter/main.c b/apps/initrouter/main.c index 82d4d67f..4e8fe19e 100644 --- a/apps/initrouter/main.c +++ b/apps/initrouter/main.c @@ -363,8 +363,9 @@ int main(int argc, char *argv[]) if (pdu_len) { My_NPDU_Handler(&src, &Rx_Buf[0], pdu_len); } - if (Error_Detected) + if (Error_Detected) { break; +} /* increment timer - exit if timed out */ elapsed_seconds = current_seconds - last_seconds; if (elapsed_seconds) { diff --git a/apps/perl/perl_bindings.c b/apps/perl/perl_bindings.c index 169860f2..2d7c6384 100644 --- a/apps/perl/perl_bindings.c +++ b/apps/perl/perl_bindings.c @@ -64,7 +64,7 @@ static void MyAbortHandler( if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { char msg[MAX_ERROR_STRING]; - sprintf(msg, "BACnet Abort: %s", + sprintf(msg, "BACnet Abort: %d", bactext_abort_reason_name((int)abort_reason)); LogError(msg); } @@ -76,7 +76,7 @@ static void MyRejectHandler( if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { char msg[MAX_ERROR_STRING]; - sprintf(msg, "BACnet Reject: %s", + sprintf(msg, "BACnet Reject: %d", bactext_reject_reason_name((int)reject_reason)); LogError(msg); } @@ -90,7 +90,7 @@ static void My_Error_Handler(BACNET_ADDRESS *src, if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { char msg[MAX_ERROR_STRING]; - sprintf(msg, "BACnet Error: %s: %s", + sprintf(msg, "BACnet Error: %d: %d", bactext_error_class_name((int)error_class), bactext_error_code_name((int)error_code)); LogError(msg); @@ -209,7 +209,7 @@ void rpm_ack_extract_data(BACNET_READ_ACCESS_DATA *rpm_data) } } else { /* AccessError */ - sprintf(ackString, "BACnet Error: %s: %s", + sprintf(ackString, "BACnet Error: %d: %d", bactext_error_class_name( (int)listOfProperties->error.error_class), bactext_error_code_name( diff --git a/apps/piface/device.c b/apps/piface/device.c index d24adebf..7b8722ad 100644 --- a/apps/piface/device.c +++ b/apps/piface/device.c @@ -376,8 +376,9 @@ bool Device_Set_Object_Instance_Number(uint32_t object_id) /* Make the change and update the database revision */ Object_Instance_Number = object_id; Device_Inc_Database_Revision(); - } else + } else { status = false; +} return status; } @@ -981,13 +982,13 @@ int Device_Read_Property_Local(BACNET_READ_PROPERTY_DATA *rpdata) case PROP_OBJECT_LIST: count = Device_Object_List_Count(); /* Array element zero is the number of objects in the list */ - if (rpdata->array_index == 0) + if (rpdata->array_index == 0) { apdu_len = encode_application_unsigned(&apdu[0], count); /* if no index was specified, then try to encode the entire list */ /* into one packet. Note that more than likely you will have */ /* to return an error if the number of encoded objects exceeds */ /* your maximum APDU size. */ - else if (rpdata->array_index == BACNET_ARRAY_ALL) { + } else if (rpdata->array_index == BACNET_ARRAY_ALL) { for (i = 1; i <= count; i++) { found = Device_Object_List_Identifier( i, &object_type, &instance); @@ -1192,7 +1193,7 @@ bool Device_Write_Property_Local(BACNET_WRITE_PROPERTY_DATA *wp_data) } break; case PROP_OBJECT_NAME: - status = write_property_string_valid(&wp_data, &value, + status = write_property_string_valid(wp_data, &value, characterstring_capacity(&My_Object_Name)); if (status) { /* All the object names in a device must be unique */ @@ -1213,7 +1214,7 @@ bool Device_Write_Property_Local(BACNET_WRITE_PROPERTY_DATA *wp_data) } break; case PROP_LOCATION: - status = write_property_empty_string_valid(&wp_data, &value, + status = write_property_empty_string_valid(wp_data, &value, MAX_DEV_LOC_LEN); if (status) { Device_Set_Location( @@ -1223,7 +1224,7 @@ bool Device_Write_Property_Local(BACNET_WRITE_PROPERTY_DATA *wp_data) break; case PROP_DESCRIPTION: - status = write_property_empty_string_valid(&wp_data, &value, + status = write_property_empty_string_valid(wp_data, &value, MAX_DEV_DESC_LEN); if (status) { Device_Set_Description( @@ -1232,7 +1233,7 @@ bool Device_Write_Property_Local(BACNET_WRITE_PROPERTY_DATA *wp_data) } break; case PROP_MODEL_NAME: - status = write_property_empty_string_valid(&wp_data, &value, + status = write_property_empty_string_valid(wp_data, &value, MAX_DEV_MOD_LEN); if (status) { Device_Set_Model_Name( diff --git a/apps/ptransfer/h_pt_a.c b/apps/ptransfer/h_pt_a.c index 4e8fc38f..6604b901 100644 --- a/apps/ptransfer/h_pt_a.c +++ b/apps/ptransfer/h_pt_a.c @@ -60,8 +60,9 @@ static void DecodeBlock(char cBlockNum, uint8_t *pData) tag_len = decode_tag_number_and_value(&pData[iLen], &tag_number, &len_value_type); iLen += tag_len; - if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) + if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) { return; +} iLen += decode_unsigned(&pData[iLen], len_value_type, &ulTemp); Response.cMyByte1 = (char)ulTemp; @@ -69,8 +70,9 @@ static void DecodeBlock(char cBlockNum, uint8_t *pData) tag_len = decode_tag_number_and_value(&pData[iLen], &tag_number, &len_value_type); iLen += tag_len; - if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) + if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) { return; +} iLen += decode_unsigned(&pData[iLen], len_value_type, &ulTemp); Response.cMyByte2 = (char)ulTemp; @@ -78,16 +80,18 @@ static void DecodeBlock(char cBlockNum, uint8_t *pData) tag_len = decode_tag_number_and_value(&pData[iLen], &tag_number, &len_value_type); iLen += tag_len; - if (tag_number != BACNET_APPLICATION_TAG_REAL) + if (tag_number != BACNET_APPLICATION_TAG_REAL) { return; +} iLen += decode_real(&pData[iLen], &Response.fMyReal); tag_len = decode_tag_number_and_value(&pData[iLen], &tag_number, &len_value_type); iLen += tag_len; - if (tag_number != BACNET_APPLICATION_TAG_CHARACTER_STRING) + if (tag_number != BACNET_APPLICATION_TAG_CHARACTER_STRING) { return; +} iLen += decode_character_string(&pData[iLen], len_value_type, &bsName); strncpy( diff --git a/apps/ptransfer/main.c b/apps/ptransfer/main.c index a8c84d05..0bf21e59 100644 --- a/apps/ptransfer/main.c +++ b/apps/ptransfer/main.c @@ -299,12 +299,14 @@ int main(int argc, char *argv[]) tsm_timer_milliseconds( ((current_seconds - last_seconds) * 1000)); } - if (Error_Detected) + if (Error_Detected) { break; +} /* wait until the device is bound, or timeout and quit */ - if (!found) + if (!found) { found = address_bind_request( Target_Device_Object_Instance, &max_apdu, &Target_Address); +} if (found) { if (invoke_id == 0) { /* Safe to send a new request */ switch (iType) { @@ -394,7 +396,8 @@ int main(int argc, char *argv[]) last_seconds = current_seconds; } } - if (Error_Detected) + if (Error_Detected) { return 1; +} return 0; } diff --git a/apps/ptransfer/s_ptransfer.c b/apps/ptransfer/s_ptransfer.c index a84715bf..09a09957 100644 --- a/apps/ptransfer/s_ptransfer.c +++ b/apps/ptransfer/s_ptransfer.c @@ -70,8 +70,9 @@ uint8_t Send_Private_Transfer_Request(uint32_t device_id, /* is the device bound? */ status = address_get_by_device(device_id, &max_apdu, &dest); /* is there a tsm available? */ - if (status) + if (status) { invoke_id = tsm_next_free_invokeID(); +} if (invoke_id) { /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); diff --git a/apps/readbdt/main.c b/apps/readbdt/main.c index cc0d056f..e92818fa 100644 --- a/apps/readbdt/main.c +++ b/apps/readbdt/main.c @@ -171,8 +171,9 @@ int main(int argc, char *argv[]) if (pdu_len) { npdu_handler(&src, &Rx_Buf[0], pdu_len); } - if (Error_Detected) + if (Error_Detected) { break; +} /* increment timer - exit if timed out */ elapsed_seconds = current_seconds - last_seconds; if (elapsed_seconds) { diff --git a/apps/readfdt/main.c b/apps/readfdt/main.c index b70ab155..0f446f23 100644 --- a/apps/readfdt/main.c +++ b/apps/readfdt/main.c @@ -170,8 +170,9 @@ int main(int argc, char *argv[]) if (pdu_len) { npdu_handler(&src, &Rx_Buf[0], pdu_len); } - if (Error_Detected) + if (Error_Detected) { break; +} /* increment timer - exit if timed out */ elapsed_seconds = current_seconds - last_seconds; if (elapsed_seconds) { diff --git a/apps/readprop/main.c b/apps/readprop/main.c index 27b1573c..a4da832e 100644 --- a/apps/readprop/main.c +++ b/apps/readprop/main.c @@ -397,8 +397,9 @@ int main(int argc, char *argv[]) tsm_timer_milliseconds( (uint16_t)((current_seconds - last_seconds) * 1000)); } - if (Error_Detected) + if (Error_Detected) { break; +} /* wait until the device is bound, or timeout and quit */ if (!found) { found = address_bind_request( @@ -441,7 +442,8 @@ int main(int argc, char *argv[]) last_seconds = current_seconds; } - if (Error_Detected) + if (Error_Detected) { return 1; +} return 0; } diff --git a/apps/readpropm/main.c b/apps/readpropm/main.c index 4580c635..99ab1616 100644 --- a/apps/readpropm/main.c +++ b/apps/readpropm/main.c @@ -457,8 +457,9 @@ int main(int argc, char *argv[]) if (current_seconds != last_seconds) { tsm_timer_milliseconds(((current_seconds - last_seconds) * 1000)); } - if (Error_Detected) + if (Error_Detected) { break; +} /* wait until the device is bound, or timeout and quit */ if (!found) { found = address_bind_request( @@ -500,7 +501,8 @@ int main(int argc, char *argv[]) last_seconds = current_seconds; } - if (Error_Detected) + if (Error_Detected) { return 1; +} return 0; } diff --git a/apps/readrange/main.c b/apps/readrange/main.c index f7c63c5e..25c165f2 100644 --- a/apps/readrange/main.c +++ b/apps/readrange/main.c @@ -355,8 +355,9 @@ int main(int argc, char *argv[]) tsm_timer_milliseconds( (uint16_t)((current_seconds - last_seconds) * 1000)); } - if (Error_Detected) + if (Error_Detected) { break; +} /* wait until the device is bound, or timeout and quit */ if (!found) { found = address_bind_request( @@ -397,7 +398,8 @@ int main(int argc, char *argv[]) last_seconds = current_seconds; } - if (Error_Detected) + if (Error_Detected) { return 1; +} return 0; } diff --git a/apps/reinit/main.c b/apps/reinit/main.c index a257249e..605e111e 100644 --- a/apps/reinit/main.c +++ b/apps/reinit/main.c @@ -206,8 +206,9 @@ int main(int argc, char *argv[]) if (current_seconds != last_seconds) { tsm_timer_milliseconds(((current_seconds - last_seconds) * 1000)); } - if (Error_Detected) + if (Error_Detected) { break; +} /* wait until the device is bound, or timeout and quit */ if (!found) { found = address_bind_request( @@ -240,7 +241,8 @@ int main(int argc, char *argv[]) last_seconds = current_seconds; } - if (Error_Detected) + if (Error_Detected) { return 1; +} return 0; } diff --git a/apps/router/ipmodule.c b/apps/router/ipmodule.c index 592f1726..bf487a5d 100644 --- a/apps/router/ipmodule.c +++ b/apps/router/ipmodule.c @@ -307,8 +307,9 @@ int dl_ip_recv( } /* the signature of a BACnet/IP packet */ - if (data->buff[0] != BVLL_TYPE_BACNET_IP) + if (data->buff[0] != BVLL_TYPE_BACNET_IP) { return 0; +} switch (data->buff[1]) { case BVLC_ORIGINAL_UNICAST_NPDU: diff --git a/apps/router/main.c b/apps/router/main.c index d90644a5..c50ef723 100644 --- a/apps/router/main.c +++ b/apps/router/main.c @@ -566,9 +566,10 @@ bool parse_cmd(int argc, char *argv[]) current->params.mstp_params.max_master = (uint8_t)atoi(argv[optind]); if (current->params.mstp_params.max_master < - current->route_info.mac[0]) + current->route_info.mac[0]) { current->params.mstp_params.max_master = current->route_info.mac[0]; +} if (argv[optind + 1][0] != '-') { current->params.mstp_params.max_frames = @@ -778,8 +779,9 @@ uint16_t process_msg(BACMSG *msg, MSG_DATA *data, uint8_t **buff) /* if received from another router save real source address (not other * router source address) */ if (addr.net > 0 && addr.net < BACNET_BROADCAST_NETWORK && - data->src.net != addr.net) + data->src.net != addr.net) { memmove(&data->src, &addr, sizeof(BACNET_ADDRESS)); +} /* encode both source and destination for broadcast and router-to-router * communication */ diff --git a/apps/router/mstpmodule.c b/apps/router/mstpmodule.c index 1cf1ce9e..557eb9b8 100644 --- a/apps/router/mstpmodule.c +++ b/apps/router/mstpmodule.c @@ -83,16 +83,18 @@ void *dl_mstp_thread(void *pArgs) break; } - if (port->params.mstp_params.stopbits == 2) + if (port->params.mstp_params.stopbits == 2) { shared_port_data.RS485MOD |= CSTOPB; +} mstp_port.UserData = (void *)&shared_port_data; dlmstp_set_baud_rate(&mstp_port, port->params.mstp_params.baudrate); dlmstp_set_mac_address(&mstp_port, port->route_info.mac[0]); dlmstp_set_max_info_frames(&mstp_port, port->params.mstp_params.max_frames); dlmstp_set_max_master(&mstp_port, port->params.mstp_params.max_master); - if (!dlmstp_init(&mstp_port, port->iface)) + if (!dlmstp_init(&mstp_port, port->iface)) { printf("MSTP %s init failed. Stop.\n", port->iface); +} port->port_id = create_msgbox(); if (port->port_id == INVALID_MSGBOX_ID) { diff --git a/apps/router/network_layer.c b/apps/router/network_layer.c index 292ad52f..b5db3808 100644 --- a/apps/router/network_layer.c +++ b/apps/router/network_layer.c @@ -129,16 +129,18 @@ uint16_t process_network_message(BACMSG *msg, MSG_DATA *data, uint8_t **buff) add_dnet(&srcport->route_info, net, data->src); /* and update routing table */ if (data->pdu[apdu_offset + i + 3] > - 0) /* find next NET value */ + 0) { /* find next NET value */ i = data->pdu[apdu_offset + i + 3] + 4; - else + } else { i = i + 4; +} } buff_len = create_network_message( NETWORK_MESSAGE_INIT_RT_TABLE_ACK, data, buff, NULL); - } else + } else { buff_len = create_network_message( NETWORK_MESSAGE_INIT_RT_TABLE_ACK, data, buff, &buff); +} break; case NETWORK_MESSAGE_INIT_RT_TABLE_ACK: @@ -152,10 +154,11 @@ uint16_t process_network_message(BACMSG *msg, MSG_DATA *data, uint8_t **buff) add_dnet(&srcport->route_info, net, data->src); /* and update routing table */ if (data->pdu[apdu_offset + i + 3] > - 0) /* find next NET value */ + 0) { /* find next NET value */ i = data->pdu[apdu_offset + i + 3] + 4; - else + } else { i = i + 4; +} } } break; @@ -202,8 +205,9 @@ uint16_t create_network_message( bool data_expecting_reply = false; BACNET_NPDU_DATA npdu_data; - if (network_message_type == NETWORK_MESSAGE_INIT_RT_TABLE) + if (network_message_type == NETWORK_MESSAGE_INIT_RT_TABLE) { data_expecting_reply = true; +} init_npdu(&npdu_data, network_message_type, data_expecting_reply); *buff = (uint8_t *)malloc(128); /* resolve different length */ @@ -276,8 +280,9 @@ uint16_t create_network_message( port = port->next; } } - } else + } else { (*buff)[buff_len++] = (uint8_t)0; +} break; case NETWORK_MESSAGE_INVALID: diff --git a/apps/router/portthread.c b/apps/router/portthread.c index ae681115..27468259 100644 --- a/apps/router/portthread.c +++ b/apps/router/portthread.c @@ -51,16 +51,17 @@ ROUTER_PORT *find_dnet(uint16_t net, BACNET_ADDRESS *addr) DNET *dnet; /* for broadcast messages no search is needed */ - if (net == BACNET_BROADCAST_NETWORK) + if (net == BACNET_BROADCAST_NETWORK) { return port; +} while (port != NULL) { /* check if DNET is directly connected to the router */ - if (net == port->route_info.net) + if (net == port->route_info.net) { return port; /* else search router ports DNET list */ - else if (port->route_info.dnets) { + } else if (port->route_info.dnets) { dnet = port->route_info.dnets; while (dnet != NULL) { if (net == dnet->net) { diff --git a/apps/scov/main.c b/apps/scov/main.c index 504372e2..86aebdfd 100644 --- a/apps/scov/main.c +++ b/apps/scov/main.c @@ -418,7 +418,8 @@ int main(int argc, char *argv[]) break; } } - if (Error_Detected) + if (Error_Detected) { return 1; +} return 0; } diff --git a/apps/server/main.c b/apps/server/main.c index 7a44209e..bb575198 100644 --- a/apps/server/main.c +++ b/apps/server/main.c @@ -267,8 +267,9 @@ int main(int argc, char *argv[]) ucix_cleanup(ctx); #endif /* defined(BAC_UCI) */ BACNET_CHARACTER_STRING DeviceName; - if (Device_Object_Name(Device_Object_Instance_Number(),&DeviceName)) + if (Device_Object_Name(Device_Object_Instance_Number(),&DeviceName)) { printf("BACnet Device Name: %s\n", DeviceName.value); +} dlenv_init(); atexit(datalink_cleanup); diff --git a/apps/ucov/main.c b/apps/ucov/main.c index 76076a1d..7caa4ae0 100644 --- a/apps/ucov/main.c +++ b/apps/ucov/main.c @@ -190,15 +190,17 @@ int main(int argc, char *argv[]) tag = strtol(argv[7], NULL, 0); value_string = argv[8]; /* optional priority */ - if (argc > 9) + if (argc > 9) { value_list.priority = strtol(argv[9], NULL, 0); - else + } else { value_list.priority = BACNET_NO_PRIORITY; +} /* optional index */ - if (argc > 10) + if (argc > 10) { value_list.propertyArrayIndex = strtol(argv[10], NULL, 0); - else + } else { value_list.propertyArrayIndex = BACNET_ARRAY_ALL; +} if (cov_data.initiatingDeviceIdentifier >= BACNET_MAX_INSTANCE) { fprintf(stderr, "device-instance=%u - it must be less than %u\r\n", diff --git a/apps/uptransfer/main.c b/apps/uptransfer/main.c index 0e20a23e..0486262b 100644 --- a/apps/uptransfer/main.c +++ b/apps/uptransfer/main.c @@ -315,8 +315,9 @@ int main(int argc, char *argv[]) elapsed_seconds += delta_seconds; tsm_timer_milliseconds(((current_seconds - last_seconds) * 1000)); } - if (Error_Detected) + if (Error_Detected) { break; +} /* wait until the device is bound, or timeout and quit */ if (!found) { found = address_bind_request( @@ -364,7 +365,8 @@ int main(int argc, char *argv[]) last_seconds = current_seconds; } - if (Error_Detected) + if (Error_Detected) { return 1; +} return 0; } diff --git a/apps/whohas/main.c b/apps/whohas/main.c index 666617e0..9ed386f2 100644 --- a/apps/whohas/main.c +++ b/apps/whohas/main.c @@ -241,8 +241,9 @@ int main(int argc, char *argv[]) if (pdu_len) { npdu_handler(&src, &Rx_Buf[0], pdu_len); } - if (Error_Detected) + if (Error_Detected) { break; +} /* increment timer - exit if timed out */ elapsed_seconds += (current_seconds - last_seconds); if (elapsed_seconds > timeout_seconds) { diff --git a/apps/whoisrouter/main.c b/apps/whoisrouter/main.c index 0e9df782..2c714a96 100644 --- a/apps/whoisrouter/main.c +++ b/apps/whoisrouter/main.c @@ -291,8 +291,9 @@ int main(int argc, char *argv[]) if (pdu_len) { My_NPDU_Handler(&src, &Rx_Buf[0], pdu_len); } - if (Error_Detected) + if (Error_Detected) { break; +} /* increment timer - exit if timed out */ elapsed_seconds = current_seconds - last_seconds; if (elapsed_seconds) { diff --git a/apps/writeprop/main.c b/apps/writeprop/main.c index bd804207..d8ede11a 100644 --- a/apps/writeprop/main.c +++ b/apps/writeprop/main.c @@ -286,8 +286,9 @@ int main(int argc, char *argv[]) } Target_Object_Property_Priority = (uint8_t)strtol(argv[5], NULL, 0); Target_Object_Property_Index = strtol(argv[6], NULL, 0); - if (Target_Object_Property_Index == -1) + if (Target_Object_Property_Index == -1) { Target_Object_Property_Index = BACNET_ARRAY_ALL; +} if (Target_Device_Object_Instance > BACNET_MAX_INSTANCE) { fprintf(stderr, "device-instance=%u - it must be less than %u\n", Target_Device_Object_Instance, BACNET_MAX_INSTANCE + 1); @@ -386,8 +387,9 @@ int main(int argc, char *argv[]) tsm_timer_milliseconds( (uint16_t)((current_seconds - last_seconds) * 1000)); } - if (Error_Detected) + if (Error_Detected) { break; +} /* wait until the device is bound, or timeout and quit */ if (!found) { found = address_bind_request( @@ -431,7 +433,8 @@ int main(int argc, char *argv[]) /* keep track of time for next check */ last_seconds = current_seconds; } - if (Error_Detected) + if (Error_Detected) { return 1; +} return 0; } diff --git a/apps/writepropm/main.c b/apps/writepropm/main.c index 62087706..e66f15d6 100644 --- a/apps/writepropm/main.c +++ b/apps/writepropm/main.c @@ -466,8 +466,9 @@ int main(int argc, char *argv[]) if (current_seconds != last_seconds) { tsm_timer_milliseconds(((current_seconds - last_seconds) * 1000)); } - if (Error_Detected) + if (Error_Detected) { break; +} /* wait until the device is bound, or timeout and quit */ if (!found) { found = address_bind_request( diff --git a/src/bacnet/bacapp.c b/src/bacnet/bacapp.c index a251fcbc..f6e837e0 100644 --- a/src/bacnet/bacapp.c +++ b/src/bacnet/bacapp.c @@ -1693,8 +1693,9 @@ bool bacapp_same_value(BACNET_APPLICATION_DATA_VALUE *value, if ((value == NULL) || (test_value == NULL)) { return false; } - if (test_value->tag == value->tag) + if (test_value->tag == value->tag) { status = true; +} if (status) { /* second test for same-ness */ status = false; @@ -1707,52 +1708,60 @@ bool bacapp_same_value(BACNET_APPLICATION_DATA_VALUE *value, #endif #if defined(BACAPP_BOOLEAN) case BACNET_APPLICATION_TAG_BOOLEAN: - if (test_value->type.Boolean == value->type.Boolean) + if (test_value->type.Boolean == value->type.Boolean) { status = true; +} break; #endif #if defined(BACAPP_UNSIGNED) case BACNET_APPLICATION_TAG_UNSIGNED_INT: - if (test_value->type.Unsigned_Int == value->type.Unsigned_Int) + if (test_value->type.Unsigned_Int == value->type.Unsigned_Int) { status = true; +} break; #endif #if defined(BACAPP_SIGNED) case BACNET_APPLICATION_TAG_SIGNED_INT: - if (test_value->type.Signed_Int == value->type.Signed_Int) + if (test_value->type.Signed_Int == value->type.Signed_Int) { status = true; +} break; #endif #if defined(BACAPP_REAL) case BACNET_APPLICATION_TAG_REAL: - if (test_value->type.Real == value->type.Real) + if (test_value->type.Real == value->type.Real) { status = true; +} break; #endif #if defined(BACAPP_DOUBLE) case BACNET_APPLICATION_TAG_DOUBLE: - if (test_value->type.Double == value->type.Double) + if (test_value->type.Double == value->type.Double) { status = true; +} break; #endif #if defined(BACAPP_ENUMERATED) case BACNET_APPLICATION_TAG_ENUMERATED: - if (test_value->type.Enumerated == value->type.Enumerated) + if (test_value->type.Enumerated == value->type.Enumerated) { status = true; +} break; #endif #if defined(BACAPP_DATE) case BACNET_APPLICATION_TAG_DATE: if (datetime_compare_date( - &test_value->type.Date, &value->type.Date) == 0) + &test_value->type.Date, &value->type.Date) == 0) { status = true; +} break; #endif #if defined(BACAPP_TIME) case BACNET_APPLICATION_TAG_TIME: if (datetime_compare_time( - &test_value->type.Time, &value->type.Time) == 0) + &test_value->type.Time, &value->type.Time) == 0) { status = true; +} break; #endif #if defined(BACAPP_OBJECT_ID) diff --git a/src/bacnet/basic/sys/days.c b/src/bacnet/basic/sys/days.c index 12a2496b..560f18bd 100644 --- a/src/bacnet/basic/sys/days.c +++ b/src/bacnet/basic/sys/days.c @@ -22,8 +22,9 @@ */ bool days_is_leap_year(uint16_t year) { - if ((year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0)) + if ((year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0)) { return true; +} return (false); } @@ -42,10 +43,11 @@ uint8_t days_per_month(uint16_t year, uint8_t month) uint8_t month_days[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; - if ((month == 2) && days_is_leap_year(year)) + if ((month == 2) && days_is_leap_year(year)) { return (29); - else if (month >= 1 && month <= 12) + } else if (month >= 1 && month <= 12) { return (month_days[month]); +} return 0; }