Skip to content

Commit 828d9e4

Browse files
authored
Merge pull request #40 from benlye/coverity-fixes
Coverity fixes
2 parents 6baa797 + 3a41b02 commit 828d9e4

8 files changed

+42
-25
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ ASALocalRun/
331331

332332
# Coverity
333333
cov-int/
334+
cov-int.zip
334335

335336
# nix stuff
336337
**/result

src/flash-multi/Dialogs/SerialMonitor.cs

+12-9
Original file line numberDiff line numberDiff line change
@@ -70,30 +70,33 @@ public SerialMonitor(string serialPortName)
7070
/// <returns>A value indicating whether or not the port was successfully opened.</returns>
7171
public bool SerialConnect(string serialPortName)
7272
{
73+
SerialPort serialPort = new SerialPort(serialPortName, 115200, Parity.None, 8, StopBits.One)
74+
{
75+
Handshake = Handshake.XOnXOff,
76+
DtrEnable = true,
77+
RtsEnable = true,
78+
};
79+
7380
try
7481
{
75-
SerialPort serialPort = new SerialPort(serialPortName, 115200, Parity.None, 8, StopBits.One)
76-
{
77-
Handshake = Handshake.XOnXOff,
78-
DtrEnable = true,
79-
RtsEnable = true,
80-
};
8182
serialPort.Open();
82-
8383
serialPort.DataReceived += new SerialDataReceivedEventHandler(this.SerialPortDataReceived);
8484

8585
this.SerialPort = serialPort;
86-
8786
this.buttonConnect.Enabled = false;
8887
this.buttonDisconnect.Enabled = true;
89-
9088
this.Text = $"Flash Multi Serial Monitor - {serialPortName} (Connected)";
9189

9290
Debug.WriteLine($"Connected to {serialPortName}.");
9391
return true;
9492
}
9593
catch (Exception ex)
9694
{
95+
if (serialPort != null)
96+
{
97+
serialPort.Dispose();
98+
}
99+
97100
Debug.WriteLine($"Unable to open port:\n{ex.Message}");
98101
using (new CenterWinDialog(this))
99102
{

src/flash-multi/Dialogs/UsbSupportErrorDialog.cs

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public UsbSupportErrorDialog()
4343
protected override void OnShown(EventArgs e)
4444
{
4545
this.errorIcon.Image = System.Drawing.SystemIcons.Error.ToBitmap();
46+
base.OnShown(e);
4647
}
4748

4849
/// <summary>

src/flash-multi/Dialogs/UsbSupportWarningDialog.cs

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public UsbSupportWarningDialog()
4343
protected override void OnShown(EventArgs e)
4444
{
4545
this.warningIcon.Image = System.Drawing.SystemIcons.Warning.ToBitmap();
46+
base.OnShown(e);
4647
}
4748

4849
/// <summary>

src/flash-multi/Eeprom/Stm32EepromUtils.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,14 @@ internal static bool FirmwareIsEmpty(string filename)
210210
internal static bool EepromIsEmpty(string filename)
211211
{
212212
byte[] data = GetEepromDataFromBackup(filename);
213-
return data.Distinct().Count() == 1 && data.Distinct().FirstOrDefault() == 255;
213+
if (data != null)
214+
{
215+
return data.Distinct().Count() == 1 && data.Distinct().FirstOrDefault() == 255;
216+
}
217+
else
218+
{
219+
return true;
220+
}
214221
}
215222
}
216223
}

src/flash-multi/FileUtils.cs

+8-11
Original file line numberDiff line numberDiff line change
@@ -211,19 +211,16 @@ internal static bool CheckFirmwareFileSize(string filename)
211211
case "AVR":
212212
maxFileSize = fileDetails.BootloaderSupport ? (fileDetails.ModuleMcuFlashSizeKb * 1024) - 512 : fileDetails.ModuleMcuFlashSizeKb * 1024;
213213
break;
214-
case "STM32":
214+
case "STM32F1":
215215
maxFileSize = fileDetails.BootloaderSupport ? (fileDetails.ModuleMcuFlashSizeKb * 1024) - 8192 - 2048 : (fileDetails.ModuleMcuFlashSizeKb * 1024) - 2048;
216-
break;
217-
}
218-
}
219216

220-
// Check if the file contains EEPROM data if it is for an STM32
221-
if (fileDetails.ModuleType == "STM32")
222-
{
223-
byte[] eePromData = Stm32EepromUtils.GetEepromDataFromBackup(filename);
224-
if (eePromData != null && Stm32EepromUtils.FindValidPage(eePromData) >= 0)
225-
{
226-
maxFileSize += 2048;
217+
byte[] eePromData = Stm32EepromUtils.GetEepromDataFromBackup(filename);
218+
if (eePromData != null && Stm32EepromUtils.FindValidPage(eePromData) >= 0)
219+
{
220+
maxFileSize += 2048;
221+
}
222+
223+
break;
227224
}
228225
}
229226

src/flash-multi/FlashMulti.cs

+9-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ public partial class FlashMulti : Form
115115
public FlashMulti()
116116
{
117117
// Set the language
118-
Thread.CurrentThread.CurrentUICulture = new CultureInfo(this.language);
118+
if (this.language != null)
119+
{
120+
Thread.CurrentThread.CurrentUICulture = new CultureInfo(this.language);
121+
}
119122

120123
// Initialize
121124
this.InitializeComponent();
@@ -1231,7 +1234,7 @@ private async Task ReadModule()
12311234
}
12321235

12331236
// Parse the EEPROM data
1234-
if (eepromData.Length > 0)
1237+
if (eepromData != null && eepromData.Length > 0)
12351238
{
12361239
uint globalId;
12371240
if (tempEepromFilename != string.Empty)
@@ -1489,6 +1492,7 @@ private async Task WriteModule()
14891492
// Error if the new bootloader hasn't been enabled
14901493
UsbSupportErrorDialog usbSupportErrorDialog = new UsbSupportErrorDialog();
14911494
usbSupportErrorDialog.ShowDialog();
1495+
usbSupportErrorDialog.Dispose();
14921496
this.EnableControls(true);
14931497
return;
14941498
}
@@ -1502,9 +1506,12 @@ private async Task WriteModule()
15021506

15031507
if (warnResult != DialogResult.OK)
15041508
{
1509+
usbSupportWarning.Dispose();
15051510
this.EnableControls(true);
15061511
return;
15071512
}
1513+
1514+
usbSupportWarning.Dispose();
15081515
}
15091516
}
15101517
}

src/flash-multi/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@
5151
// You can specify all the values or you can default the Build and Revision Numbers
5252
// by using the '*' as shown below:
5353
// [assembly: AssemblyVersion("1.0.*")]
54-
[assembly: AssemblyVersion("0.6.0")]
55-
[assembly: AssemblyFileVersion("0.6.0")]
54+
[assembly: AssemblyVersion("0.6.1")]
55+
[assembly: AssemblyFileVersion("0.6.1")]

0 commit comments

Comments
 (0)