From e0781ccfc15500fc51122dcb795d84f836c8cec9 Mon Sep 17 00:00:00 2001 From: David Holm Date: Sat, 29 Dec 2018 11:50:47 +0100 Subject: [PATCH 1/5] diskimage: Fix memory leak Use array delete operator for pointer that was allocated with new[] so that all entries are deleted. --- DiskImage.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/DiskImage.cpp b/DiskImage.cpp index abf96f5..ac29e2e 100644 --- a/DiskImage.cpp +++ b/DiskImage.cpp @@ -1394,7 +1394,7 @@ void TDiskImage::readFDI(int hfile, bool readonly) { if (rsize < fdiOFF) { - delete tracksinfo; + delete[] tracksinfo; delete ptr; ShowError(ERR_CORRUPT); return; @@ -1405,7 +1405,7 @@ void TDiskImage::readFDI(int hfile, bool readonly) if (rsize < fdiOFFdata + tracksinfo[trk*(MaxSide + 1) + side].DataOffset) { - delete tracksinfo; + delete[] tracksinfo; delete ptr; ShowError(ERR_CORRUPT); return; @@ -1424,7 +1424,7 @@ void TDiskImage::readFDI(int hfile, bool readonly) if (rsize < fdiOFFdata + tracksinfo[trk*(MaxSide + 1) + side].DataOffset + tracksinfo[trk*(MaxSide + 1) + side].SectorsInfo[isec].SectorOffset) { - delete tracksinfo; + delete[] tracksinfo; delete ptr; ShowError(ERR_CORRUPT); return; @@ -1475,7 +1475,7 @@ void TDiskImage::readFDI(int hfile, bool readonly) if (trkdatalen + SecCount*(3 + 2) > 6250) // 3x4E & 2x00 per sec checking { - delete tracksinfo; + delete[] tracksinfo; delete ptr; for (int t = 0; t < 256; t++) for (int s = 0; s < 256; s++) @@ -1640,7 +1640,7 @@ void TDiskImage::readFDI(int hfile, bool readonly) } } - delete tracksinfo; + delete[] tracksinfo; delete ptr; ReadOnly = readonly; FType = DIT_FDI; From 6813f707ea7d37436203f5c494ac706234c038d4 Mon Sep 17 00:00:00 2001 From: David Holm Date: Sat, 29 Dec 2018 11:55:20 +0100 Subject: [PATCH 2/5] fpga_io, user_io, minimig: Remove unreferenced printf arguments Remove arguments to *printf that were not being referenced by the format strings. --- fpga_io.cpp | 2 +- support/minimig/minimig_config.cpp | 2 +- user_io.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fpga_io.cpp b/fpga_io.cpp index c0c2c86..9922c71 100644 --- a/fpga_io.cpp +++ b/fpga_io.cpp @@ -486,7 +486,7 @@ int fpga_load_rbf(const char *name, const char *cfg) { if (read(rbf, buf, st.st_size) Date: Sat, 29 Dec 2018 11:58:59 +0100 Subject: [PATCH 3/5] sharpmz: sharpmz_ui does not return a value The `sharpmz_ui` function does not have a return statement so declare it as void. --- support/sharpmz/sharpmz.cpp | 14 +++++++------- support/sharpmz/sharpmz.h | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/support/sharpmz/sharpmz.cpp b/support/sharpmz/sharpmz.cpp index c6bd362..05db175 100644 --- a/support/sharpmz/sharpmz.cpp +++ b/support/sharpmz/sharpmz.cpp @@ -1967,13 +1967,13 @@ int sharpmz_default_ui_state(void) // code base and to limit common code case size. // The same general programming structure is maintained to enable easier changes. // -int sharpmz_ui(int idleState, int idle2State, int systemState, int selectFile, - unsigned char *parentstate, unsigned char *menustate, unsigned char *menusub, unsigned char *menusub_last, - unsigned int *menumask, char *selectedPath, const char **helptext, char *helptext_custom, - unsigned char *fs_ExtLen, unsigned char *fs_Options, unsigned char *fs_MenuSelect, unsigned char *fs_MenuCancel, - char *fs_pFileExt, - unsigned char menu, unsigned char select, unsigned char up, unsigned char down, - unsigned char left, unsigned char right, unsigned char plus, unsigned char minus) +void sharpmz_ui(int idleState, int idle2State, int systemState, int selectFile, + unsigned char *parentstate, unsigned char *menustate, unsigned char *menusub, unsigned char *menusub_last, + unsigned int *menumask, char *selectedPath, const char **helptext, char *helptext_custom, + unsigned char *fs_ExtLen, unsigned char *fs_Options, unsigned char *fs_MenuSelect, unsigned char *fs_MenuCancel, + char *fs_pFileExt, + unsigned char menu, unsigned char select, unsigned char up, unsigned char down, + unsigned char left, unsigned char right, unsigned char plus, unsigned char minus) { // Locals - original variables are generally all lower case, variables specific to this method are capitalised on change of word. // diff --git a/support/sharpmz/sharpmz.h b/support/sharpmz/sharpmz.h index b7e1cf1..49a80b5 100644 --- a/support/sharpmz/sharpmz.h +++ b/support/sharpmz/sharpmz.h @@ -459,7 +459,7 @@ char *sharpmz_get_next_filename(char); void sharpmz_clear_filelist(void); void sharpmz_select_file(const char*, unsigned char, char *, char, char *); int sharpmz_default_ui_state(void); -int sharpmz_ui(int, int, int, int, +void sharpmz_ui(int, int, int, int, unsigned char *, unsigned char *, unsigned char *, unsigned char *, unsigned int *, char *, const char **, char *, unsigned char *, unsigned char *, unsigned char *, unsigned char *, From e144cd713f28af1d525f62bcf379925f10aa7a61 Mon Sep 17 00:00:00 2001 From: David Holm Date: Sat, 29 Dec 2018 12:15:39 +0100 Subject: [PATCH 4/5] menu: Initialize variables before use Initialize `rdb` and `m` to zero at the top of `HandleUI` before they are accessed. --- menu.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/menu.cpp b/menu.cpp index ed79b8b..0f84160 100644 --- a/menu.cpp +++ b/menu.cpp @@ -678,12 +678,12 @@ void HandleUI(void) return; } - struct RigidDiskBlock *rdb; + struct RigidDiskBlock *rdb = nullptr; static char opensave; char *p; char s[40]; - unsigned char m, up, down, select, menu, right, left, plus, minus; + unsigned char m = 0, up, down, select, menu, right, left, plus, minus; uint8_t mod; unsigned long len; char enable; From 7debf7ce1adc429be6f4c7fcbbc1c86adb4f8f5b Mon Sep 17 00:00:00 2001 From: David Holm Date: Sat, 29 Dec 2018 12:20:03 +0100 Subject: [PATCH 5/5] input: Remove spurious backslash Remove backslash at end of comment so that the next line doesn't get commented out as well. --- input.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/input.cpp b/input.cpp index f635f26..1d5e5c1 100644 --- a/input.cpp +++ b/input.cpp @@ -475,7 +475,7 @@ static const int ev2ps2[] = NONE, //191 KEY_F21 NONE, //192 KEY_F22 NONE, //193 KEY_F23 - 0x5D, //194 U-mlaut on DE mapped to \ + 0x5D, //194 U-mlaut on DE mapped to NONE, //195 ??? NONE, //196 ??? NONE, //197 ???