Skip to content

Commit

Permalink
Merge pull request #40 from benlye/coverity-fixes
Browse files Browse the repository at this point in the history
Coverity fixes
  • Loading branch information
benlye authored Jan 18, 2021
2 parents 6baa797 + 3a41b02 commit 828d9e4
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ ASALocalRun/

# Coverity
cov-int/
cov-int.zip

# nix stuff
**/result
21 changes: 12 additions & 9 deletions src/flash-multi/Dialogs/SerialMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,33 @@ public SerialMonitor(string serialPortName)
/// <returns>A value indicating whether or not the port was successfully opened.</returns>
public bool SerialConnect(string serialPortName)
{
SerialPort serialPort = new SerialPort(serialPortName, 115200, Parity.None, 8, StopBits.One)
{
Handshake = Handshake.XOnXOff,
DtrEnable = true,
RtsEnable = true,
};

try
{
SerialPort serialPort = new SerialPort(serialPortName, 115200, Parity.None, 8, StopBits.One)
{
Handshake = Handshake.XOnXOff,
DtrEnable = true,
RtsEnable = true,
};
serialPort.Open();

serialPort.DataReceived += new SerialDataReceivedEventHandler(this.SerialPortDataReceived);

this.SerialPort = serialPort;

this.buttonConnect.Enabled = false;
this.buttonDisconnect.Enabled = true;

this.Text = $"Flash Multi Serial Monitor - {serialPortName} (Connected)";

Debug.WriteLine($"Connected to {serialPortName}.");
return true;
}
catch (Exception ex)
{
if (serialPort != null)
{
serialPort.Dispose();
}

Debug.WriteLine($"Unable to open port:\n{ex.Message}");
using (new CenterWinDialog(this))
{
Expand Down
1 change: 1 addition & 0 deletions src/flash-multi/Dialogs/UsbSupportErrorDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public UsbSupportErrorDialog()
protected override void OnShown(EventArgs e)
{
this.errorIcon.Image = System.Drawing.SystemIcons.Error.ToBitmap();
base.OnShown(e);
}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions src/flash-multi/Dialogs/UsbSupportWarningDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public UsbSupportWarningDialog()
protected override void OnShown(EventArgs e)
{
this.warningIcon.Image = System.Drawing.SystemIcons.Warning.ToBitmap();
base.OnShown(e);
}

/// <summary>
Expand Down
9 changes: 8 additions & 1 deletion src/flash-multi/Eeprom/Stm32EepromUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,14 @@ internal static bool FirmwareIsEmpty(string filename)
internal static bool EepromIsEmpty(string filename)
{
byte[] data = GetEepromDataFromBackup(filename);
return data.Distinct().Count() == 1 && data.Distinct().FirstOrDefault() == 255;
if (data != null)
{
return data.Distinct().Count() == 1 && data.Distinct().FirstOrDefault() == 255;
}
else
{
return true;
}
}
}
}
19 changes: 8 additions & 11 deletions src/flash-multi/FileUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,19 +211,16 @@ internal static bool CheckFirmwareFileSize(string filename)
case "AVR":
maxFileSize = fileDetails.BootloaderSupport ? (fileDetails.ModuleMcuFlashSizeKb * 1024) - 512 : fileDetails.ModuleMcuFlashSizeKb * 1024;
break;
case "STM32":
case "STM32F1":
maxFileSize = fileDetails.BootloaderSupport ? (fileDetails.ModuleMcuFlashSizeKb * 1024) - 8192 - 2048 : (fileDetails.ModuleMcuFlashSizeKb * 1024) - 2048;
break;
}
}

// Check if the file contains EEPROM data if it is for an STM32
if (fileDetails.ModuleType == "STM32")
{
byte[] eePromData = Stm32EepromUtils.GetEepromDataFromBackup(filename);
if (eePromData != null && Stm32EepromUtils.FindValidPage(eePromData) >= 0)
{
maxFileSize += 2048;
byte[] eePromData = Stm32EepromUtils.GetEepromDataFromBackup(filename);
if (eePromData != null && Stm32EepromUtils.FindValidPage(eePromData) >= 0)
{
maxFileSize += 2048;
}

break;
}
}

Expand Down
11 changes: 9 additions & 2 deletions src/flash-multi/FlashMulti.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ public partial class FlashMulti : Form
public FlashMulti()
{
// Set the language
Thread.CurrentThread.CurrentUICulture = new CultureInfo(this.language);
if (this.language != null)
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo(this.language);
}

// Initialize
this.InitializeComponent();
Expand Down Expand Up @@ -1231,7 +1234,7 @@ private async Task ReadModule()
}

// Parse the EEPROM data
if (eepromData.Length > 0)
if (eepromData != null && eepromData.Length > 0)
{
uint globalId;
if (tempEepromFilename != string.Empty)
Expand Down Expand Up @@ -1489,6 +1492,7 @@ private async Task WriteModule()
// Error if the new bootloader hasn't been enabled
UsbSupportErrorDialog usbSupportErrorDialog = new UsbSupportErrorDialog();
usbSupportErrorDialog.ShowDialog();
usbSupportErrorDialog.Dispose();
this.EnableControls(true);
return;
}
Expand All @@ -1502,9 +1506,12 @@ private async Task WriteModule()

if (warnResult != DialogResult.OK)
{
usbSupportWarning.Dispose();
this.EnableControls(true);
return;
}

usbSupportWarning.Dispose();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/flash-multi/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.6.0")]
[assembly: AssemblyFileVersion("0.6.0")]
[assembly: AssemblyVersion("0.6.1")]
[assembly: AssemblyFileVersion("0.6.1")]

0 comments on commit 828d9e4

Please sign in to comment.