Fix static analysis warnings

Fix warnings for the following:
-include directive not at top of file
-ambiguous indentation for scope of if statement
-not passing expensive object by const reference
-initializing in constructor when using class initialization or initialization
list possible
-member function that doesn't mutate its object not declared const
This commit is contained in:
Allofich 2023-03-30 01:06:54 +09:00
parent 99f92c5340
commit 496dfa6267
8 changed files with 107 additions and 114 deletions

View File

@ -779,10 +779,10 @@ struct DOS_Block {
DOS_Version version = {};
uint16_t firstMCB = 0;
uint16_t errorcode = 0;
uint16_t psp();//{return DOS_SDA(DOS_SDA_SEG,DOS_SDA_OFS).GetPSP();};
void psp(uint16_t _seg);//{ DOS_SDA(DOS_SDA_SEG,DOS_SDA_OFS).SetPSP(_seg);};
RealPt dta();//{return DOS_SDA(DOS_SDA_SEG,DOS_SDA_OFS).GetDTA();};
void dta(RealPt _dta);//{DOS_SDA(DOS_SDA_SEG,DOS_SDA_OFS).SetDTA(_dta);};
uint16_t psp() const;//{return DOS_SDA(DOS_SDA_SEG,DOS_SDA_OFS).GetPSP();};
void psp(uint16_t _seg) const;//{ DOS_SDA(DOS_SDA_SEG,DOS_SDA_OFS).SetPSP(_seg);};
RealPt dta() const;//{return DOS_SDA(DOS_SDA_SEG,DOS_SDA_OFS).GetDTA();};
void dta(RealPt _dta) const;//{DOS_SDA(DOS_SDA_SEG,DOS_SDA_OFS).SetDTA(_dta);};
uint8_t return_code = 0, return_mode = 0;
uint8_t current_drive = 0;

View File

@ -192,7 +192,7 @@ public:
uint32_t GetSeekPos(void);
FILE * fhandle;
private:
bool read_only_medium;
bool read_only_medium = false;
enum { NONE,READ,WRITE } last_action;
};

View File

@ -257,7 +257,7 @@ DOS_InfoBlock dos_infoblock;
extern int bootdrive;
extern bool force_sfn, dos_kernel_disabled;
uint16_t DOS_Block::psp() {
uint16_t DOS_Block::psp() const {
if (dos_kernel_disabled) {
LOG_MSG("BUG: DOS kernel is disabled (booting a guest OS), and yet somebody is still asking for DOS's current PSP segment\n");
return 0x0000;
@ -266,7 +266,7 @@ uint16_t DOS_Block::psp() {
return DOS_SDA(DOS_SDA_SEG,DOS_SDA_OFS).GetPSP();
}
void DOS_Block::psp(uint16_t _seg) {
void DOS_Block::psp(uint16_t _seg) const {
if (dos_kernel_disabled) {
LOG_MSG("BUG: DOS kernel is disabled (booting a guest OS), and yet somebody is still attempting to change DOS's current PSP segment\n");
return;
@ -275,7 +275,7 @@ void DOS_Block::psp(uint16_t _seg) {
DOS_SDA(DOS_SDA_SEG,DOS_SDA_OFS).SetPSP(_seg);
}
RealPt DOS_Block::dta() {
RealPt DOS_Block::dta() const {
if (dos_kernel_disabled) {
LOG_MSG("BUG: DOS kernel is disabled (booting a guest OS), and yet somebody is still asking for DOS's DTA (disk transfer address)\n");
return 0;
@ -284,7 +284,7 @@ RealPt DOS_Block::dta() {
return DOS_SDA(DOS_SDA_SEG,DOS_SDA_OFS).GetDTA();
}
void DOS_Block::dta(RealPt _dta) {
void DOS_Block::dta(RealPt _dta) const {
if (dos_kernel_disabled) {
LOG_MSG("BUG: DOS kernel is disabled (booting a guest OS), and yet somebody is still attempting to change DOS's DTA (disk transfer address)\n");
return;

View File

@ -60,6 +60,7 @@
#include "mouse.h"
#include "../ints/int10.h"
#include "../output/output_opengl.h"
#include "paging.h"
#if !defined(HX_DOS)
#include "../libs/tinyfiledialogs/tinyfiledialogs.c"
#endif
@ -73,7 +74,6 @@ host_cnv_char_t *CodePageGuestToHost(const char *s);
#if !defined(S_ISREG)
# define S_ISREG(x) ((x & S_IFREG) == S_IFREG)
#endif
#include "../dos/cdrom.h"
#include <ShlObj.h>
#else
#include <libgen.h>
@ -110,7 +110,7 @@ extern int toSetCodePage(DOS_Shell *shell, int newCP, int opt);
void MSG_Init(), JFONT_Init(), InitFontHandle(), ShutFontHandle(), DOSBox_SetSysMenu(), Load_Language(std::string name);
void DOS_EnableDriveMenu(char drv), GFX_SetTitle(int32_t cycles, int frameskip, Bits timing, bool paused), UpdateSDLDrawTexture();
void runBoot(const char *str), runMount(const char *str), runImgmount(const char *str), runRescan(const char *str), show_prompt(), ttf_reset(void);
void getdrivezpath(std::string &path, std::string dirname), drivezRegister(std::string path, std::string dir, bool usecp), UpdateDefaultPrinterFont(void);
void getdrivezpath(std::string &path, std::string const& dirname), drivezRegister(std::string const& path, std::string const& dir, bool usecp), UpdateDefaultPrinterFont(void);
std::string GetDOSBoxXPath(bool withexe=false);
FILE *testLoadLangFile(const char *fname);
@ -1631,9 +1631,6 @@ unsigned char PC98_ITF_ROM[0x8000];
bool PC98_ITF_ROM_init = false;
unsigned char PC98_BANK_Select = 0x12;
#include "mem.h"
#include "paging.h"
class PC98ITFPageHandler : public PageHandler {
public:
PC98ITFPageHandler() : PageHandler(PFLAG_READABLE|PFLAG_HASROM) {}
@ -3056,7 +3053,7 @@ const uint8_t freedos_mbr[] = {
class IMGMAKE : public Program {
public:
#ifdef WIN32
bool OpenDisk(HANDLE* f, OVERLAPPED* o, uint8_t* name) {
bool OpenDisk(HANDLE* f, OVERLAPPED* o, uint8_t* name) const {
o->hEvent = INVALID_HANDLE_VALUE;
*f = CreateFile( (LPCSTR)name, GENERIC_READ | GENERIC_WRITE,
0, // exclusive access
@ -3081,12 +3078,12 @@ public:
return true;
}
void CloseDisk(HANDLE f, OVERLAPPED* o) {
void CloseDisk(HANDLE f, OVERLAPPED* o) const {
if(f != INVALID_HANDLE_VALUE) CloseHandle(f);
if(o->hEvent != INVALID_HANDLE_VALUE) CloseHandle(o->hEvent);
}
bool StartReadDisk(HANDLE f, OVERLAPPED* o, uint8_t* buffer, Bitu offset, Bitu size) {
bool StartReadDisk(HANDLE f, OVERLAPPED* o, uint8_t* buffer, Bitu offset, Bitu size) const {
o->Offset = (DWORD)offset;
if (!ReadFile(f, buffer, (DWORD)size, NULL, o) &&
(GetLastError()==ERROR_IO_PENDING)) return true;
@ -3094,7 +3091,7 @@ public:
}
// 0=still waiting, 1=catastrophic failure, 2=success, 3=sector not found, 4=crc error
Bitu CheckDiskReadComplete(HANDLE f, OVERLAPPED* o) {
Bitu CheckDiskReadComplete(HANDLE f, OVERLAPPED* o) const {
DWORD numret;
BOOL b = GetOverlappedResult( f, o, &numret,false);
if(b) return 2;
@ -4452,7 +4449,7 @@ public:
void DisplayMenuCursorEnd(void) { WriteOut("\033[0m\n"); }
void DisplayMenuNone(void) { WriteOut("\033[44m\033[K\033[0m\n"); }
bool CON_IN(uint8_t * data) {
bool CON_IN(uint8_t * data) const {
uint8_t c;
uint16_t n=1;
@ -4508,7 +4505,11 @@ public:
return;
}
if(cmd->FindExist("usage",false)) {DisplayUsage(); if (attr) DOS_SetAnsiAttr(attr); return; }
if(cmd->FindExist("usage", false)) {
DisplayUsage();
if(attr) DOS_SetAnsiAttr(attr);
return;
}
uint8_t c;uint16_t n=1;
#define CURSOR(option) \
@ -6023,12 +6024,12 @@ private:
return true;
}
void AddToDriveManager(const char drive, DOS_Drive* imgDisk, const uint8_t mediaid) {
void AddToDriveManager(const char drive, DOS_Drive* imgDisk, const uint8_t mediaid) const {
std::vector<DOS_Drive*> imgDisks = { imgDisk };
AddToDriveManager(drive, imgDisks, mediaid);
}
void AddToDriveManager(const char drive, const std::vector<DOS_Drive*> &imgDisks, const uint8_t mediaid) {
void AddToDriveManager(const char drive, const std::vector<DOS_Drive*> &imgDisks, const uint8_t mediaid) const {
std::vector<DOS_Drive*>::size_type ct;
// Update DriveManager
@ -6193,7 +6194,7 @@ private:
}
}
bool DetectMFMsectorPartition(uint8_t buf[], uint32_t fcsize, Bitu sizes[]) {
bool DetectMFMsectorPartition(uint8_t buf[], uint32_t fcsize, Bitu sizes[]) const {
// This is used for plain MFM sector format as created by IMGMAKE
// It tries to find the first partition. Addressing is in CHS format.
/* Offset | Length | Description
@ -6256,7 +6257,7 @@ private:
return false;
}
bool DetectBximagePartition(uint32_t fcsize, Bitu sizes[]) {
bool DetectBximagePartition(uint32_t fcsize, Bitu sizes[]) const {
// Try bximage disk geometry
uint32_t cylinders = fcsize / (16 * 63);
// Int13 only supports up to 1023 cylinders

View File

@ -115,7 +115,7 @@ void UDFTagId::parse(const unsigned int sz,const unsigned char *b) {
}
}
bool UDFTagId::tagChecksumOK(const unsigned int sz,const unsigned char *b) {
bool UDFTagId::tagChecksumOK(const unsigned int sz,const unsigned char *b) const {
uint8_t chksum = 0;
if (sz < 16)
@ -132,7 +132,7 @@ bool UDFTagId::tagChecksumOK(const unsigned int sz,const unsigned char *b) {
return true;
}
bool UDFTagId::dataChecksumOK(const unsigned int sz,const unsigned char *b) {
bool UDFTagId::dataChecksumOK(const unsigned int sz,const unsigned char *b) const {
if (DescriptorCRCLength != 0) {
if ((DescriptorCRCLength+16u) > sz)
return false;
@ -696,8 +696,7 @@ UDFlong_ad::UDFlong_ad() {
UDFextent::UDFextent() {
}
UDFextent::UDFextent(const struct UDFextent_ad &s) {
ex = s;
UDFextent::UDFextent(const struct UDFextent_ad &s) : ex(s) {
}
////////////////////////////////////
@ -711,7 +710,7 @@ UDFextents::UDFextents(const struct UDFextent_ad &s) {
////////////////////////////////////
void isoDrive::UDFFileEntryToExtents(UDFextents &ex,UDFFileEntry &fe) {
void isoDrive::UDFFileEntryToExtents(UDFextents &ex,UDFFileEntry &fe) const {
ex.xl.clear();
ex.indata.clear();
ex.is_indata = false;
@ -739,7 +738,7 @@ void isoDrive::UDFFileEntryToExtents(UDFextents &ex,UDFFileEntry &fe) {
////////////////////////////////////
void isoDrive::UDFextent_rewind(struct UDFextents &ex) {
void isoDrive::UDFextent_rewind(struct UDFextents &ex) const {
ex.relofs = 0;
ex.extent = 0;
ex.extofs = 0;
@ -755,7 +754,7 @@ uint64_t isoDrive::UDFtotalsize(struct UDFextents &ex) const {
return total;
}
uint64_t isoDrive::UDFextent_seek(struct UDFextents &ex,uint64_t ofs) {
uint64_t isoDrive::UDFextent_seek(struct UDFextents &ex,uint64_t ofs) const {
UDFextent_rewind(ex);
if (ex.is_indata) {
@ -783,7 +782,7 @@ uint64_t isoDrive::UDFextent_seek(struct UDFextents &ex,uint64_t ofs) {
return (uint64_t)ex.extofs + (uint64_t)ex.relofs;
}
unsigned int isoDrive::UDFextent_read(struct UDFextents &ex,unsigned char *buf,size_t count) {
unsigned int isoDrive::UDFextent_read(struct UDFextents &ex,unsigned char *buf,size_t count) const {
unsigned int rd = 0;
if (ex.is_indata) {
@ -975,9 +974,6 @@ isoDrive::isoDrive(char driveLetter, const char* fileName, uint8_t mediaid, int&
enable_udf = (dos.version.major > 7 || (dos.version.major == 7 && dos.version.minor >= 10));//default
enable_rock_ridge = (dos.version.major >= 7 || uselfn);//default
enable_joliet = (dos.version.major >= 7 || uselfn);//default
is_rock_ridge = false;
is_joliet = false;
is_udf = false;
for (const auto &opt : options) {
size_t equ = opt.find_first_of('=');
std::string name,value;
@ -1713,11 +1709,11 @@ bool isoDrive::ReadCachedSector(uint8_t** buffer, const uint32_t sector) {
return true;
}
inline bool isoDrive :: readSector(uint8_t *buffer, uint32_t sector) {
inline bool isoDrive :: readSector(uint8_t *buffer, uint32_t sector) const {
return CDROM_Interface_Image::images[subUnit]->ReadSector(buffer, false, sector);
}
int isoDrive::readDirEntry(isoDirEntry* de, const uint8_t* data,unsigned int dirIteratorIndex) {
int isoDrive::readDirEntry(isoDirEntry* de, const uint8_t* data,unsigned int dirIteratorIndex) const {
// This code is NOT for UDF filesystem access!
if (is_udf) return -1;
@ -1955,7 +1951,7 @@ static bool escape_is_joliet(const unsigned char *esc) {
return false;
}
bool isoDrive :: loadImageUDFAnchorVolumePointer(UDFAnchorVolumeDescriptorPointer &avdp,uint8_t pvd[COOKED_SECTOR_SIZE],uint32_t sector) {
bool isoDrive :: loadImageUDFAnchorVolumePointer(UDFAnchorVolumeDescriptorPointer &avdp,uint8_t pvd[COOKED_SECTOR_SIZE],uint32_t sector) const {
UDFTagId aid;
if (!aid.get(COOKED_SECTOR_SIZE,pvd)) return false;

View File

@ -96,6 +96,12 @@
#include "cp1258_uni.h"
#include "cp3021_uni.h"
#if defined (WIN32)
#include <Shellapi.h>
#else
#include <glob.h>
#endif
#if defined(PATH_MAX) && !defined(MAX_PATH)
#define MAX_PATH PATH_MAX
#endif
@ -1090,7 +1096,7 @@ int FileDirExistUTF8(std::string &localname, const char *name) {
extern uint16_t fztime, fzdate;
extern bool force_conversion, InitCodePage();
std::string GetDOSBoxXPath(bool withexe=false);
void getdrivezpath(std::string &path, std::string dirname) {
void getdrivezpath(std::string &path, std::string const& dirname) {
const host_cnv_char_t* host_name = CodePageGuestToHost(path.c_str());
if (host_name == NULL) {path = "";return;}
struct stat cstat;
@ -1126,7 +1132,7 @@ void getdrivezpath(std::string &path, std::string dirname) {
}
}
void drivezRegister(std::string path, std::string dir, bool usecp) {
void drivezRegister(std::string const& path, std::string const& dir, bool usecp) {
int cp = dos.loaded_codepage;
if (!usecp || !cp) {
force_conversion = true;
@ -1612,11 +1618,6 @@ bool localDrive::GetSystemFilename(char *sysName, char const * const dosName) {
#endif
}
#if defined (WIN32)
#include <Shellapi.h>
#else
#include <glob.h>
#endif
bool localDrive::FileUnlink(const char * name) {
if (readonly) {
DOS_SetError(DOSERR_WRITE_PROTECTED);
@ -2888,14 +2889,12 @@ uint32_t localFile::GetSeekPos() {
localFile::localFile() {}
localFile::localFile(const char* _name, FILE * handle) {
fhandle=handle;
localFile::localFile(const char* _name, FILE* handle) : fhandle(handle) {
open=true;
localFile::UpdateDateTimeFromHost();
attr=DOS_ATTR_ARCHIVE;
last_action=NONE;
read_only_medium=false;
name=0;
SetName(_name);
@ -2982,15 +2981,12 @@ bool MSCDEX_HasMediaChanged(uint8_t subUnit);
bool MSCDEX_GetVolumeName(uint8_t subUnit, char* name);
cdromDrive::cdromDrive(const char driveLetter, const char * startdir,uint16_t _bytes_sector,uint8_t _sectors_cluster,uint16_t _total_clusters,uint16_t _free_clusters,uint8_t _mediaid, int& error, std::vector<std::string> &options)
:localDrive(startdir,_bytes_sector,_sectors_cluster,_total_clusters,_free_clusters,_mediaid,options),
subUnit(0),
driveLetter('\0')
:localDrive(startdir,_bytes_sector,_sectors_cluster,_total_clusters,_free_clusters,_mediaid,options), driveLetter(driveLetter)
{
// Init mscdex
error = MSCDEX_AddDrive(driveLetter,startdir,subUnit);
strcpy(info, "CDRom ");
strcat(info, startdir);
this->driveLetter = driveLetter;
// Get Volume Label
char name[32];
if (MSCDEX_GetVolumeName(subUnit,name)) dirCache.SetLabel(name,true,true);

View File

@ -101,7 +101,7 @@ public:
virtual bool add_special_file_to_disk(const char* dosname, const char* operation, uint16_t value, bool isdir);
virtual void EmptyCache(void) { dirCache.EmptyCache(); };
virtual void MediaChange() {};
const char* getBasedir() {return basedir;};
const char* getBasedir() const {return basedir;};
struct {
uint16_t bytes_sector;
uint8_t sectors_cluster;
@ -537,7 +537,7 @@ public:
virtual bool isRemote(void);
virtual bool isRemovable(void);virtual Bits UnMount(void);
private:
uint8_t subUnit; char driveLetter;
uint8_t subUnit = 0; char driveLetter = '\0';
};
class physfscdromDrive : public physfsDrive
@ -688,8 +688,8 @@ struct UDFTagId { /* ECMA-167 7.2.1 */
bool get(const unsigned int sz,const unsigned char *b);
void parse(const unsigned int sz,const unsigned char *b);
bool tagChecksumOK(const unsigned int sz,const unsigned char *b);
bool dataChecksumOK(const unsigned int sz,const unsigned char *b);
bool tagChecksumOK(const unsigned int sz,const unsigned char *b) const;
bool dataChecksumOK(const unsigned int sz,const unsigned char *b) const;
bool checksumOK(const unsigned int sz,const unsigned char *b);
UDFTagId(const unsigned int sz,const unsigned char *b);
UDFTagId();
@ -1059,13 +1059,13 @@ public:
virtual Bits UnMount(void);
bool loadImage();
bool loadImageUDF();
bool loadImageUDFAnchorVolumePointer(UDFAnchorVolumeDescriptorPointer &avdp,uint8_t *pvd/*COOKED_SECTOR_SIZE*/,uint32_t sector);
bool readSector(uint8_t *buffer, uint32_t sector);
bool loadImageUDFAnchorVolumePointer(UDFAnchorVolumeDescriptorPointer &avdp,uint8_t *pvd/*COOKED_SECTOR_SIZE*/,uint32_t sector) const;
bool readSector(uint8_t *buffer, uint32_t sector) const;
void setFileName(const char* fileName);
virtual char const* GetLabel(void) {return discLabel;};
virtual void Activate(void);
private:
int readDirEntry(isoDirEntry* de, const uint8_t* data, unsigned int direntindex);
int readDirEntry(isoDirEntry* de, const uint8_t* data, unsigned int direntindex) const;
bool lookup(isoDirEntry *de, const char *path);
bool lookup(UDFFileIdentifierDescriptor &fid, UDFFileEntry &fe, const char *path);
int UpdateMscdex(char driveLetter, const char* path, uint8_t& subUnit);
@ -1114,10 +1114,10 @@ private:
UDFFileSetDescriptor fsetd;
UDFPartitionDescriptor partd;
public:
void UDFextent_rewind(struct UDFextents &ex);
void UDFFileEntryToExtents(UDFextents &ex,UDFFileEntry &fe);
uint64_t UDFextent_seek(struct UDFextents &ex,uint64_t ofs);
unsigned int UDFextent_read(struct UDFextents &ex,unsigned char *buf,size_t count);
void UDFextent_rewind(struct UDFextents &ex) const;
void UDFFileEntryToExtents(UDFextents &ex,UDFFileEntry &fe) const;
uint64_t UDFextent_seek(struct UDFextents &ex,uint64_t ofs) const;
unsigned int UDFextent_read(struct UDFextents &ex,unsigned char *buf,size_t count) const;
uint64_t UDFtotalsize(struct UDFextents &ex) const;
private:
struct DirIterator {
@ -1190,7 +1190,7 @@ public:
virtual bool TestDir(const char * dir);
virtual bool RemoveDir(const char * dir);
virtual bool MakeDir(const char * dir);
const char* getOverlaydir() {return overlaydir;};
const char* getOverlaydir() const {return overlaydir;};
bool ovlnocachedir = false;
bool ovlreadonly = false;
private:

View File

@ -3614,7 +3614,7 @@ private:
OPL_Mode oplmode;
/* Support Functions */
void Find_Type_And_Opl(Section_prop* config,SB_TYPES& type, OPL_Mode& opl_mode){
void Find_Type_And_Opl(Section_prop* config,SB_TYPES& type, OPL_Mode& opl_mode) const {
sb.vibra = false;
sb.ess_type = ESS_NONE;
sb.reveal_sc_type = RSC_NONE;