From 02506d293e3c617ec94940a9668ed5d47369d765 Mon Sep 17 00:00:00 2001 From: krcroft Date: Wed, 15 Jan 2020 07:29:47 -0800 Subject: [PATCH] Fix static-analysis issues in cdrom_image One issue in BinaryFile's constructor: There is no sense in testing the 'file' pointer against null, as the memory was allocated using the 'new' operator. The exception will be generated in the case of memory allocation error. 'new' - https://www.viva64.com/en/w/v668/ Two issues relating to assigning a value that's already assigned - https://www.viva64.com/en/w/v1048/ --- src/dos/cdrom_image.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/dos/cdrom_image.cpp b/src/dos/cdrom_image.cpp index 58086159..188e8afa 100644 --- a/src/dos/cdrom_image.cpp +++ b/src/dos/cdrom_image.cpp @@ -57,7 +57,8 @@ CDROM_Interface_Image::BinaryFile::BinaryFile(const char *filename, bool &error) file(nullptr) { file = new ifstream(filename, ios::in | ios::binary); - error = (file == nullptr) || (file->fail()); + // If new fails, an exception is generated and scope leaves this constructor + error = file->fail(); } CDROM_Interface_Image::BinaryFile::~BinaryFile() @@ -803,10 +804,10 @@ bool CDROM_Interface_Image::LoadIsoFile(char* filename) // try to detect iso type if (CanReadPVD(track.file.get(), BYTES_PER_COOKED_REDBOOK_FRAME, false)) { track.sectorSize = BYTES_PER_COOKED_REDBOOK_FRAME; - track.mode2 = false; + // track.mode2 = false (comment only, because this is the default value) } else if (CanReadPVD(track.file.get(), BYTES_PER_RAW_REDBOOK_FRAME, false)) { track.sectorSize = BYTES_PER_RAW_REDBOOK_FRAME; - track.mode2 = false; + // track.mode2 = false (comment only, because this is the default value) } else if (CanReadPVD(track.file.get(), 2336, true)) { track.sectorSize = 2336; track.mode2 = true;