From bb85d083a7899890d0c14502078f6fa60a09d5df Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Tue, 28 Feb 2012 20:40:24 +0000 Subject: Fix warnings and errors found by the new cppcheck provided static code analysis. --- Bootloaders/HID/HostLoaderApp/hid_bootloader_cli.c | 1 + BuildTests/StaticAnalysisTest/makefile | 2 +- .../BluetoothHost/Lib/BluetoothACLPackets.c | 10 +++++----- LUFA.pnproj | 2 +- .../StandaloneProgrammer/Lib/ProgrammerConfig.c | 6 +++--- .../StandaloneProgrammer/StandaloneProgrammer.c | 19 ++++++++----------- Projects/TempDataLogger/Lib/DS1307.c | 12 ++++-------- 7 files changed, 23 insertions(+), 29 deletions(-) diff --git a/Bootloaders/HID/HostLoaderApp/hid_bootloader_cli.c b/Bootloaders/HID/HostLoaderApp/hid_bootloader_cli.c index e1f2ea03d..4fd6ccf1f 100644 --- a/Bootloaders/HID/HostLoaderApp/hid_bootloader_cli.c +++ b/Bootloaders/HID/HostLoaderApp/hid_bootloader_cli.c @@ -801,6 +801,7 @@ int read_intel_hex(const char *filename) if (*buf) { if (parse_hex_line(buf) == 0) { //printf("Warning, parse error line %d\n", lineno); + fclose(fp); return -2; } } diff --git a/BuildTests/StaticAnalysisTest/makefile b/BuildTests/StaticAnalysisTest/makefile index 1556bbd90..766bf080c 100644 --- a/BuildTests/StaticAnalysisTest/makefile +++ b/BuildTests/StaticAnalysisTest/makefile @@ -18,6 +18,6 @@ EXCLUDE_LIST = HostLoaderApp/ FATFs/ PetiteFATFs/ uip/ MESSAGE_TEMPLATE = "{file}({line}): {severity} ({id}): {message}" all: - cppcheck -q -f --error-exitcode=1 --template $(MESSAGE_TEMPLATE) --enable=style --suppress=variableScope $(EXCLUDE_LIST:%=-i%) $(LUFA_ROOT_PATH) + cppcheck -q -f --error-exitcode=1 --inline-suppr --enable=style --suppress=variableScope --template $(MESSAGE_TEMPLATE) $(EXCLUDE_LIST:%=-i%) $(LUFA_ROOT_PATH) %: \ No newline at end of file diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.c b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.c index 15b98215c..a02a66b7b 100644 --- a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.c +++ b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.c @@ -473,8 +473,8 @@ static inline void Bluetooth_Signal_ConnectionReq(const BT_Signal_Header_t* cons ResponsePacket.SignalCommandHeader.Length = sizeof(ResponsePacket.ConnectionResponse); /* Fill out the Connection Response in the response packet */ - ResponsePacket.ConnectionResponse.DestinationChannel = ChannelData->LocalNumber; - ResponsePacket.ConnectionResponse.SourceChannel = ChannelData->RemoteNumber; + ResponsePacket.ConnectionResponse.DestinationChannel = (ChannelData != NULL) ? ChannelData->LocalNumber : 0; + ResponsePacket.ConnectionResponse.SourceChannel = (ChannelData != NULL) ? ChannelData->RemoteNumber : 0; ResponsePacket.ConnectionResponse.Result = ChannelStatus; ResponsePacket.ConnectionResponse.Status = 0x00; @@ -576,7 +576,7 @@ static inline void Bluetooth_Signal_ConfigurationReq(const BT_Signal_Header_t* c ResponsePacket.SignalCommandHeader.Length = sizeof(ResponsePacket.ConfigurationResponse); /* Fill out the Configuration Response in the response packet */ - ResponsePacket.ConfigurationResponse.SourceChannel = ChannelData->RemoteNumber; + ResponsePacket.ConfigurationResponse.SourceChannel = (ChannelData != NULL) ? ChannelData->RemoteNumber : 0; ResponsePacket.ConfigurationResponse.Flags = 0x00; ResponsePacket.ConfigurationResponse.Result = (ChannelData != NULL) ? BT_CONFIGURATION_SUCCESSFUL : BT_CONFIGURATION_REJECTED; @@ -681,8 +681,8 @@ static inline void Bluetooth_Signal_DisconnectionReq(const BT_Signal_Header_t* c ResponsePacket.SignalCommandHeader.Length = sizeof(ResponsePacket.DisconnectionResponse); /* Fill out the Disconnection Response in the response packet */ - ResponsePacket.DisconnectionResponse.DestinationChannel = ChannelData->RemoteNumber; - ResponsePacket.DisconnectionResponse.SourceChannel = ChannelData->LocalNumber; + ResponsePacket.DisconnectionResponse.DestinationChannel = (ChannelData != NULL) ? ChannelData->RemoteNumber : 0; + ResponsePacket.DisconnectionResponse.SourceChannel = (ChannelData != NULL) ? ChannelData->LocalNumber : 0; Bluetooth_SendPacket(&ResponsePacket, sizeof(ResponsePacket), NULL); diff --git a/LUFA.pnproj b/LUFA.pnproj index 879167974..5407d3f6d 100644 --- a/LUFA.pnproj +++ b/LUFA.pnproj @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/Projects/Incomplete/StandaloneProgrammer/Lib/ProgrammerConfig.c b/Projects/Incomplete/StandaloneProgrammer/Lib/ProgrammerConfig.c index 6a8419d35..917523669 100644 --- a/Projects/Incomplete/StandaloneProgrammer/Lib/ProgrammerConfig.c +++ b/Projects/Incomplete/StandaloneProgrammer/Lib/ProgrammerConfig.c @@ -40,7 +40,7 @@ struct bool ProgrammerConfig_ProcessConfiguration(void) { - memset(&ProgrammerConfig, sizeof(ProgrammerConfig), 0x00); + memset(&ProgrammerConfig, 0x00, sizeof(ProgrammerConfig)); if (!(pf_open("CONF.txt") == FR_OK)) { @@ -61,8 +61,8 @@ bool ProgrammerConfig_ProcessConfiguration(void) &ProgrammerConfig.SigBytes[1], &ProgrammerConfig.SigBytes[2], &ProgrammerConfig.SigBytes[3]); - - sscanf(CurrentLine, "SPEED = %lu", &ProgrammerConfig.ProgrammingSpeed); + + sscanf(CurrentLine, "SPEED = %08lu", &ProgrammerConfig.ProgrammingSpeed); } } while (CurrentLine); diff --git a/Projects/Incomplete/StandaloneProgrammer/StandaloneProgrammer.c b/Projects/Incomplete/StandaloneProgrammer/StandaloneProgrammer.c index 1f9f8391d..cc79a8321 100644 --- a/Projects/Incomplete/StandaloneProgrammer/StandaloneProgrammer.c +++ b/Projects/Incomplete/StandaloneProgrammer/StandaloneProgrammer.c @@ -114,18 +114,15 @@ int main(void) { Programmer_Task(); + #if defined(USB_CAN_BE_HOST) if (USB_CurrentMode == USB_MODE_Host) - { - #if defined(USB_CAN_BE_HOST) - DiskHost_USBTask(); - #endif - } - else - { - #if defined(USB_CAN_BE_DEVICE) - DiskDevice_USBTask(); - #endif - } + DiskHost_USBTask(); + #endif + + #if defined(USB_CAN_BE_DEVICE) + if (USB_CurrentMode == USB_MODE_Device) + DiskDevice_USBTask(); + #endif USB_USBTask(); } diff --git a/Projects/TempDataLogger/Lib/DS1307.c b/Projects/TempDataLogger/Lib/DS1307.c index 459030f84..0fbd17b5a 100644 --- a/Projects/TempDataLogger/Lib/DS1307.c +++ b/Projects/TempDataLogger/Lib/DS1307.c @@ -9,10 +9,7 @@ bool DS1307_SetTimeDate(const TimeDate_t* NewTimeDate) { -#if defined(DUMMY_RTC) - return true; -#endif - +#if !defined(DUMMY_RTC) DS1307_DateTimeRegs_t NewRegValues; const uint8_t WriteAddress = 0; @@ -41,6 +38,7 @@ bool DS1307_SetTimeDate(const TimeDate_t* NewTimeDate) { return false; } +#endif return true; } @@ -55,10 +53,7 @@ bool DS1307_GetTimeDate(TimeDate_t* const TimeDate) TimeDate->Day = 1; TimeDate->Month = 1; TimeDate->Year = 1; - - return true; -#endif - +#else DS1307_DateTimeRegs_t CurrentRegValues; const uint8_t ReadAddress = 0; @@ -78,6 +73,7 @@ bool DS1307_GetTimeDate(TimeDate_t* const TimeDate) TimeDate->Day = (CurrentRegValues.Byte5.Fields.TenDay * 10) + CurrentRegValues.Byte5.Fields.Day; TimeDate->Month = (CurrentRegValues.Byte6.Fields.TenMonth * 10) + CurrentRegValues.Byte6.Fields.Month; TimeDate->Year = (CurrentRegValues.Byte7.Fields.TenYear * 10) + CurrentRegValues.Byte7.Fields.Year; +#endif return true; } -- cgit v1.2.3