Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another batch of PVS Studio fixes #2756

Merged
merged 15 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pvs-studio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ jobs:

- name: Summarize report
env:
MAX_BUGS: 237
MAX_BUGS: 207
run: |
echo "Full report is included in build Artifacts"
echo
Expand Down
2 changes: 1 addition & 1 deletion include/mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ class MixerChannel {
struct StereoLine {
LINE_INDEX left = LEFT;
LINE_INDEX right = RIGHT;
bool operator==(const StereoLine &other) const;
bool operator==(const StereoLine other) const;
};

static constexpr StereoLine STEREO = {LEFT, RIGHT};
Expand Down
2 changes: 1 addition & 1 deletion src/dos/cdrom.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ inline TMSF frames_to_msf(uint32_t frames)

// Conversion function from Minutes/Second/Frames to frames
//
inline uint32_t msf_to_frames(const TMSF &msf)
inline uint32_t msf_to_frames(const TMSF msf)
{
return msf.min * 60 * REDBOOK_FRAMES_PER_SECOND + msf.sec * REDBOOK_FRAMES_PER_SECOND + msf.fr;
}
Expand Down
36 changes: 18 additions & 18 deletions src/dos/dos_mscdex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,41 +153,41 @@ class CMscdex {
uint16_t GetNumDrives() const { return numDrives; }
uint16_t GetFirstDrive() const { return dinfo[0].drive; }

uint8_t GetSubUnit (uint16_t _drive);
bool GetUPC (uint8_t subUnit, uint8_t& attr, char* upc);
uint8_t GetSubUnit (uint16_t _drive);
bool GetUPC (uint8_t subUnit, uint8_t& attr, char* upc);

void InitNewMedia (uint8_t subUnit);
bool PlayAudioSector (uint8_t subUnit, uint32_t start, uint32_t length);
bool PlayAudioMSF (uint8_t subUnit, uint32_t start, uint32_t length);
bool StopAudio (uint8_t subUnit);
bool StopAudio (uint8_t subUnit);
bool GetAudioStatus (uint8_t subUnit, bool& playing, bool& pause, TMSF& start, TMSF& end);

bool GetSubChannelData (uint8_t subUnit, uint8_t& attr, uint8_t& track, uint8_t &index, TMSF& rel, TMSF& abs);

int RemoveDrive (uint16_t _drive);
int AddDrive (uint16_t _drive, char* physicalPath, uint8_t& subUnit);
bool HasDrive (uint16_t drive);
int RemoveDrive (uint16_t _drive);
int AddDrive (uint16_t _drive, const char* physicalPath, uint8_t& subUnit);
bool HasDrive (uint16_t drive);
void ReplaceDrive (CDROM_Interface* newCdrom, uint8_t subUnit);
void GetDrives (PhysPt data);
void GetDrives (PhysPt data);
void GetDriverInfo (PhysPt data);
bool GetVolumeName (uint8_t subUnit, char* name);
bool GetFileName (uint16_t drive, uint16_t pos, PhysPt data);
bool GetFileName (uint16_t drive, uint16_t pos, PhysPt data);
bool GetDirectoryEntry (uint16_t drive, bool copyFlag, PhysPt pathname, PhysPt buffer, uint16_t& error);
bool ReadVTOC (uint16_t drive, uint16_t volume, PhysPt data, uint16_t& offset, uint16_t& error);
bool ReadSectors (uint16_t drive, uint32_t sector, uint16_t num, PhysPt data);
bool ReadSectors (uint8_t subUnit, bool raw, uint32_t sector, uint16_t num, PhysPt data);
bool ReadVTOC (uint16_t drive, uint16_t volume, PhysPt data, uint16_t& offset, uint16_t& error);
bool ReadSectors (uint16_t drive, uint32_t sector, uint16_t num, PhysPt data);
bool ReadSectors (uint8_t subUnit, bool raw, uint32_t sector, uint16_t num, PhysPt data);
bool ReadSectorsMSF (uint8_t subUnit, bool raw, uint32_t sector, uint16_t num, PhysPt data);
bool SendDriverRequest (uint16_t drive, PhysPt data);
bool IsValidDrive (uint16_t drive);
bool GetCDInfo (uint8_t subUnit, uint8_t& tr1, uint8_t& tr2, TMSF& leadOut);
uint32_t GetVolumeSize (uint8_t subUnit);
bool GetCDInfo (uint8_t subUnit, uint8_t& tr1, uint8_t& tr2, TMSF& leadOut);
uint32_t GetVolumeSize (uint8_t subUnit);
bool GetTrackInfo (uint8_t subUnit, uint8_t track, uint8_t& attr, TMSF& start);
uint16_t GetStatusWord (uint8_t subUnit,uint16_t status);
uint16_t GetStatusWord (uint8_t subUnit,uint16_t status);
bool GetCurrentPos (uint8_t subUnit, TMSF& pos);
uint32_t GetDeviceStatus (uint8_t subUnit);
uint32_t GetDeviceStatus (uint8_t subUnit);
bool GetMediaStatus (uint8_t subUnit, uint8_t& status);
bool LoadUnloadMedia (uint8_t subUnit, bool unload);
bool ResumeAudio (uint8_t subUnit);
bool ResumeAudio (uint8_t subUnit);
bool GetMediaStatus (uint8_t subUnit, bool& media, bool& changed, bool& trayOpen);

private:
Expand Down Expand Up @@ -298,7 +298,7 @@ int CMscdex::RemoveDrive(uint16_t _drive)
return 1;
}

int CMscdex::AddDrive(uint16_t _drive, char* physicalPath, uint8_t& subUnit)
int CMscdex::AddDrive(uint16_t _drive, const char* physicalPath, uint8_t& subUnit)
{
subUnit = 0;
if ((Bitu)GetNumDrives()+1>=MSCDEX_MAX_DRIVES) return 4;
Expand Down Expand Up @@ -1380,7 +1380,7 @@ bool device_MSCDEX::WriteToControlChannel(PhysPt bufptr,uint16_t size,uint16_t *
int MSCDEX_AddDrive(char driveLetter, const char* physicalPath, uint8_t& subUnit)
{
int result = mscdex->AddDrive(drive_index(driveLetter),
const_cast<char*>(physicalPath), subUnit);
physicalPath, subUnit);
return result;
}

Expand Down
6 changes: 3 additions & 3 deletions src/dos/program_autotype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ void AUTOTYPE::PrintKeys()
*/
bool AUTOTYPE::ReadDoubleArg(const std::string &name,
const char *flag,
const double &def_value,
const double &min_value,
const double &max_value,
const double def_value,
const double min_value,
const double max_value,
FeralChild64 marked this conversation as resolved.
Show resolved Hide resolved
double &value)
{
bool result = false;
Expand Down
6 changes: 3 additions & 3 deletions src/dos/program_autotype.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class AUTOTYPE final : public Program {
void PrintKeys();
bool ReadDoubleArg(const std::string &name,
const char *flag,
const double &def_value,
const double &min_value,
const double &max_value,
const double def_value,
const double min_value,
const double max_value,
double &value);
};

Expand Down
2 changes: 1 addition & 1 deletion src/dos/program_boot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ FILE* BOOT::getFSFile_mounted(const char* filename, uint32_t* ksize,
FILE *tmpfile;
char fullname[DOS_PATHLENGTH];

if (!DOS_MakeName(const_cast<char *>(filename), fullname, &drive))
if (!DOS_MakeName(filename, fullname, &drive))
return nullptr;

try {
Expand Down
2 changes: 1 addition & 1 deletion src/hardware/mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ bool MixerChannel::HasFeature(const ChannelFeature feature) const
return features.find(feature) != features.end();
}

bool MixerChannel::StereoLine::operator==(const StereoLine &other) const
bool MixerChannel::StereoLine::operator==(const StereoLine other) const
{
return left == other.left && right == other.right;
}
Expand Down
2 changes: 1 addition & 1 deletion src/hardware/ne2000.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,7 @@ int bx_ne2k_c::rx_frame(const void *buf, unsigned io_len)
memcpy(startptr + 4, buf, (size_t)(endbytes - 4u));
startptr = & BX_NE2K_THIS s.mem[BX_NE2K_THIS s.page_start * 256u -
BX_NE2K_MEMSTART];
memcpy(startptr, (void *)(pktbuf + endbytes - 4u),
memcpy(startptr, (const void *)(pktbuf + endbytes - 4u),
(size_t)(io_len - endbytes + 8u));
BX_NE2K_THIS s.curr_page = nextpage;
}
Expand Down
4 changes: 2 additions & 2 deletions src/hardware/serialport/softmodem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,15 +548,15 @@ void CSerialModem::DoCommand()
// be a valid IP/name
// Transform by adding dots
size_t j = 0;
size_t foundlen = strlen(foundstr);
const size_t foundlen = strlen(foundstr);
for (size_t i = 0; i < foundlen; i++) {
buffer[j++] = foundstr[i];
// Add a dot after the third, sixth and ninth number
if (i == 2 || i == 5 || i == 8)
buffer[j++] = '.';
// If the string is longer than 12 digits,
// interpret the rest as port
if (i == 11 && strlen(foundstr) > 12)
if (i == 11 && foundlen > 12)
buffer[j++] = ':';
}
buffer[j] = 0;
Expand Down
8 changes: 3 additions & 5 deletions src/ints/int10_modes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,11 +851,9 @@ static bool INT10_SetVideoMode_OTHER(uint16_t mode, bool clearmem)
IO_WriteW(crtc_base,0x09 | (scanline-1) << 8);
// Setup the CGA palette using VGA DAC palette
for (size_t i = 0; i < palette.cga16.size(); ++i) {
auto ct = static_cast<uint8_t>(i);
VGA_DAC_SetEntry(ct,
palette.cga16[ct].red,
palette.cga16[ct].green,
palette.cga16[ct].blue);
const auto ct = static_cast<uint8_t>(i);
const auto& entry = palette.cga16[ct];
VGA_DAC_SetEntry(ct, entry.red, entry.green, entry.blue);
}
//Setup the tandy palette
for (uint8_t ct=0;ct<16;ct++) VGA_DAC_CombineColor(ct,ct);
Expand Down
21 changes: 11 additions & 10 deletions src/libs/loguru/loguru.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Website: www.ilikebigbits.com
* Version 2.0.0 - 2018-09-22 - Split loguru.hpp into loguru.hpp and loguru.cpp
* Version 2.1.0 - 2019-09-23 - Update fmtlib + add option to loguru::init to NOT set main thread name.
* Version 2.2.0 - 2020-07-31 - Replace LOGURU_CATCH_SIGABRT with struct SignalOptions
* 2023-08-13 - fix PVS Studio warnings (change by DOSBox Staging Team)

# Compiling
Just include <loguru.hpp> where you want to use Loguru.
Expand Down Expand Up @@ -727,16 +728,16 @@ namespace loguru
LOGURU_EXPORT
void flush();

template<class T> inline Text format_value(const T&) { return textprintf("N/A"); }
template<> inline Text format_value(const char& v) { return textprintf(LOGURU_FMT(c), v); }
template<> inline Text format_value(const int& v) { return textprintf(LOGURU_FMT(d), v); }
template<> inline Text format_value(const unsigned int& v) { return textprintf(LOGURU_FMT(u), v); }
template<> inline Text format_value(const long& v) { return textprintf(LOGURU_FMT(lu), v); }
template<> inline Text format_value(const unsigned long& v) { return textprintf(LOGURU_FMT(ld), v); }
template<> inline Text format_value(const long long& v) { return textprintf(LOGURU_FMT(llu), v); }
template<> inline Text format_value(const unsigned long long& v) { return textprintf(LOGURU_FMT(lld), v); }
template<> inline Text format_value(const float& v) { return textprintf(LOGURU_FMT(f), v); }
template<> inline Text format_value(const double& v) { return textprintf(LOGURU_FMT(f), v); }
template<class T> inline Text format_value(const T) { return textprintf("N/A"); }
template<> inline Text format_value(const char v) { return textprintf(LOGURU_FMT(c), v); }
template<> inline Text format_value(const int v) { return textprintf(LOGURU_FMT(d), v); }
template<> inline Text format_value(const unsigned int v) { return textprintf(LOGURU_FMT(u), v); }
template<> inline Text format_value(const long v) { return textprintf(LOGURU_FMT(lu), v); }
template<> inline Text format_value(const unsigned long v) { return textprintf(LOGURU_FMT(ld), v); }
template<> inline Text format_value(const long long v) { return textprintf(LOGURU_FMT(llu), v); }
template<> inline Text format_value(const unsigned long long v) { return textprintf(LOGURU_FMT(lld), v); }
template<> inline Text format_value(const float v) { return textprintf(LOGURU_FMT(f), v); }
template<> inline Text format_value(const double v) { return textprintf(LOGURU_FMT(f), v); }

/* Thread names can be set for the benefit of readable logs.
If you do not set the thread name, a hex id will be shown instead.
Expand Down
4 changes: 2 additions & 2 deletions src/misc/cross.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void Cross::CreatePlatformConfigDir(std::string &in)
in += "\\DOSBox";
#else
assert(!cached_conf_path.empty());
in = cached_conf_path.c_str();
in = cached_conf_path;
#endif
if (in.back() != CROSS_FILESPLIT)
in += CROSS_FILESPLIT;
Expand Down Expand Up @@ -462,7 +462,7 @@ bool wild_match(const char *haystack, const char *needle)
{
assert(haystack);
assert(needle);
char *p = (char *)needle;
const char *p = needle;
while(*p != '\0') {
switch (*p) {
case '?':
Expand Down
8 changes: 4 additions & 4 deletions src/misc/programs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ void CONFIG::Run(void)
return;
}
// if it's a section, leave it as one-param
Section* sec = control->GetSection(pvars[0].c_str());
Section* sec = control->GetSection(pvars[0]);
if (!sec) {
// could be a property
sec = control->GetSectionFromProperty(
Expand All @@ -504,7 +504,7 @@ void CONFIG::Run(void)
}
case 2: {
// sanity check
Section* sec = control->GetSection(pvars[0].c_str());
Section* sec = control->GetSection(pvars[0]);
Section* sec2 = control->GetSectionFromProperty(
pvars[1].c_str());
if (!sec) {
Expand All @@ -520,7 +520,7 @@ void CONFIG::Run(void)
}
// if we have one value in pvars, it's a section
// two values are section + property
Section* sec = control->GetSection(pvars[0].c_str());
Section* sec = control->GetSection(pvars[0]);
if (sec == nullptr) {
WriteOut(MSG_Get("PROGRAM_CONFIG_PROPERTY_ERROR"),
pvars[0].c_str());
Expand Down Expand Up @@ -695,7 +695,7 @@ void CONFIG::Run(void)
case 1: {
// property/section only
// is it a section?
Section* sec = control->GetSection(pvars[0].c_str());
Section* sec = control->GetSection(pvars[0]);
if (sec) {
// list properties in section
Bitu i = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/misc/setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1683,7 +1683,7 @@ const char* SetProp(std::vector<std::string>& pvars)
}

// Check if the first parameter is a section or property
Section* sec = control->GetSection(pvars[0].c_str());
Section* sec = control->GetSection(pvars[0]);

if (!sec) {
// Not a section: little duplicate from above
Expand Down
2 changes: 1 addition & 1 deletion src/shell/autoexec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ AutoExecModule::AutoExecModule(Section* configuration)

// Enable secure boot if needed

if (has_option_securemode && !has_boot_image) {
if (has_option_securemode) {
if (has_boot_image) {
// Secure mode does not allow booting - so skip it
LOG_WARNING("AUTOEXEC: Secure mode skipped as it does not allow booting");
Expand Down
5 changes: 3 additions & 2 deletions src/shell/shell_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ bool DOS_Shell::SetEnv(const char* entry, const char* new_string)
PhysPt env_write = env_read;
PhysPt env_write_start = env_read;
char env_string[1024 + 1] = {0};
const auto entry_length = strlen(entry);
do {
MEM_StrCopy(env_read, env_string, 1024);
if (!env_string[0]) {
Expand All @@ -698,8 +699,8 @@ bool DOS_Shell::SetEnv(const char* entry, const char* new_string)
if (!strchr(env_string, '=')) {
continue; /* Remove corrupt entry? */
}
if ((strncasecmp(entry, env_string, strlen(entry)) == 0) &&
env_string[strlen(entry)] == '=') {
if ((strncasecmp(entry, env_string, entry_length) == 0) &&
env_string[entry_length] == '=') {
continue;
}
MEM_BlockWrite(env_write,
Expand Down