Skip to content

Commit

Permalink
reSharper: local variables can be made 'const'
Browse files Browse the repository at this point in the history
  • Loading branch information
jcdr428 committed Aug 9, 2023
1 parent 0228f86 commit 0007d79
Show file tree
Hide file tree
Showing 51 changed files with 1,176 additions and 1,176 deletions.
12 changes: 6 additions & 6 deletions libmediation/fs/osdep/directory_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ char getDirSeparator() { return '\\'; }

string extractFileDir(const string& fileName)
{
size_t index = fileName.find_last_of('\\');
const size_t index = fileName.find_last_of('\\');
if (index != string::npos)
return fileName.substr(0, index + 1);

Expand Down Expand Up @@ -40,7 +40,7 @@ uint64_t getFileSize(const std::string& fileName)

bool createDir(const std::string& dirName, bool createParentDirs)
{
bool ok = preCreateDir(
const bool ok = preCreateDir(
[](auto&& parentDir) {
return parentDir.empty() || parentDir[parentDir.size() - 1] == ':' || parentDir == "\\\\." ||
parentDir == "\\\\.\\" || // UNC patch prefix
Expand Down Expand Up @@ -78,8 +78,8 @@ bool findFiles(const string& path, const string& fileMask, vector<string>* fileL
WIN32_FIND_DATA fileData; // Data structure describes the file found
// Search handle returned by FindFirstFile

auto searchStr = toWide(path + '/' + fileMask);
HANDLE hSearch = FindFirstFile(searchStr.data(), &fileData);
const auto searchStr = toWide(path + '/' + fileMask);
const HANDLE hSearch = FindFirstFile(searchStr.data(), &fileData);
if (hSearch == INVALID_HANDLE_VALUE)
return false;

Expand All @@ -102,8 +102,8 @@ bool findDirs(const string& path, vector<string>* dirsList)
WIN32_FIND_DATA fileData; // Data structure describes the file found
// Search handle returned by FindFirstFile

auto searchStr = toWide(path + "*");
HANDLE hSearch = FindFirstFile(searchStr.data(), &fileData);
const auto searchStr = toWide(path + "*");
const HANDLE hSearch = FindFirstFile(searchStr.data(), &fileData);
if (hSearch == INVALID_HANDLE_VALUE)
return false;

Expand Down
26 changes: 13 additions & 13 deletions libmediation/fs/osdep/file_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
void throwFileError()
{
LPVOID msgBuf = nullptr;
DWORD dw = GetLastError();
const DWORD dw = GetLastError();

FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, nullptr, dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&msgBuf, 0, nullptr);

std::string str((char*)msgBuf);
const std::string str((char*)msgBuf);
throw std::runtime_error(str);
}

Expand Down Expand Up @@ -72,7 +72,7 @@ File::File(const char* fName, unsigned int oflag, unsigned int systemDependentFl
if (oflag & File::ofAppend)
{
long hiword = 0;
DWORD newPointerLow = SetFilePointer(m_impl, 0, &hiword, FILE_END);
const DWORD newPointerLow = SetFilePointer(m_impl, 0, &hiword, FILE_END);
if (newPointerLow == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR)
throwFileError();
}
Expand Down Expand Up @@ -117,7 +117,7 @@ bool File::open(const char* fName, unsigned int oflag, unsigned int systemDepend
if (oflag & File::ofAppend)
{
long hiword = 0;
DWORD newPointerLow = SetFilePointer(m_impl, 0, &hiword, FILE_END);
const DWORD newPointerLow = SetFilePointer(m_impl, 0, &hiword, FILE_END);
if (newPointerLow == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR)
throwFileError();
}
Expand All @@ -129,7 +129,7 @@ bool File::open(const char* fName, unsigned int oflag, unsigned int systemDepend
bool File::close()
{
// sync();
BOOL res = CloseHandle(m_impl);
const BOOL res = CloseHandle(m_impl);
m_impl = INVALID_HANDLE_VALUE;
return res != 0;
}
Expand All @@ -140,7 +140,7 @@ int File::read(void* buffer, uint32_t count) const
return -1;

DWORD bytesRead = 0;
BOOL res = ReadFile(m_impl, buffer, count, &bytesRead, nullptr);
const BOOL res = ReadFile(m_impl, buffer, count, &bytesRead, nullptr);
if (!res)
return -1;

Expand All @@ -155,7 +155,7 @@ int File::write(const void* buffer, uint32_t count)
return -1;

DWORD bytesWritten = 0;
BOOL res = WriteFile(m_impl, buffer, count, &bytesWritten, nullptr);
const BOOL res = WriteFile(m_impl, buffer, count, &bytesWritten, nullptr);
if (!res)
{
throwFileError();
Expand All @@ -175,7 +175,7 @@ bool File::isOpen() const { return m_impl != INVALID_HANDLE_VALUE; }
bool File::size(uint64_t* const fileSize) const
{
DWORD highDw;
DWORD lowDw = GetFileSize(m_impl, &highDw);
const DWORD lowDw = GetFileSize(m_impl, &highDw);
if ((lowDw == INVALID_FILE_SIZE) && (GetLastError() != NO_ERROR))
return false;
*fileSize = highDw;
Expand Down Expand Up @@ -203,10 +203,10 @@ uint64_t File::seek(int64_t offset, SeekMethod whence)
break;
}

LONG distanceToMoveLow = (uint32_t)(offset & 0xffffffff);
const LONG distanceToMoveLow = (uint32_t)(offset & 0xffffffff);
LONG distanceToMoveHigh = (uint32_t)((offset & 0xffffffff00000000ull) >> 32);

DWORD newPointerLow = SetFilePointer(m_impl, distanceToMoveLow, &distanceToMoveHigh, moveMethod);
const DWORD newPointerLow = SetFilePointer(m_impl, distanceToMoveLow, &distanceToMoveHigh, moveMethod);
if (newPointerLow == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR)
return (uint64_t)-1;

Expand All @@ -217,10 +217,10 @@ uint64_t File::seek(int64_t offset, SeekMethod whence)

bool File::truncate(uint64_t newFileSize)
{
LONG distanceToMoveLow = (uint32_t)(newFileSize & 0xffffffff);
const LONG distanceToMoveLow = (uint32_t)(newFileSize & 0xffffffff);
LONG distanceToMoveHigh = (uint32_t)((newFileSize & 0xffffffff00000000ull) >> 32);
DWORD newPointerLow = SetFilePointer(m_impl, distanceToMoveLow, &distanceToMoveHigh, FILE_BEGIN);
int errCode = GetLastError();
const DWORD newPointerLow = SetFilePointer(m_impl, distanceToMoveLow, &distanceToMoveHigh, FILE_BEGIN);
const int errCode = GetLastError();
if ((newPointerLow == INVALID_SET_FILE_POINTER) && (errCode != NO_ERROR))
// return false;
throwFileError();
Expand Down
22 changes: 11 additions & 11 deletions libmediation/types/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,15 @@ uint64_t roundUp64(const uint64_t& value, const uint64_t& roundVal)

string strPadLeft(const string& str, size_t newSize, char filler)
{
int cnt = (int)(newSize - str.size());
const int cnt = (int)(newSize - str.size());
string prefix = "";
for (int i = 0; i < cnt; i++) prefix += filler;
return prefix + str;
}

string strPadRight(const string& str, size_t newSize, char filler)
{
int cnt = (int)(newSize - str.size());
const int cnt = (int)(newSize - str.size());
string postfix = "";
for (int i = 0; i < cnt; i++) postfix += filler;
return str + postfix;
Expand Down Expand Up @@ -266,7 +266,7 @@ vector<string> splitStr(const string& str, const string& splitter)
{
vector<string> res;

size_t splitterSize = splitter.size();
const size_t splitterSize = splitter.size();
size_t posBegin = 0;
size_t posEnd = string::npos;

Expand Down Expand Up @@ -340,7 +340,7 @@ string extractFileName2(const string& src, bool withExt)
{
string fileName = src;

size_t extSep = fileName.find_last_of('.');
const size_t extSep = fileName.find_last_of('.');
size_t dirSep = fileName.find_last_of('/');

if (dirSep == string::npos)
Expand Down Expand Up @@ -380,10 +380,10 @@ string closeDirPath(const string& src, char delimiter)
// extract the filename from a path, check for invalid characters
bool isValidFileName(const string& src)
{
string filename = extractFileName(src);
const string filename = extractFileName(src);

// invalidChars() returns a different regex pattern for Windows or Unix
bool isvalid = !(std::regex_search(filename, invalidChars()));
const bool isvalid = !(std::regex_search(filename, invalidChars()));
return isvalid;
}

Expand Down Expand Up @@ -441,20 +441,20 @@ string strToLowerCase(const string& src)

uint32_t my_ntohl(const uint32_t val)
{
auto* tmp = (uint8_t*)&val;
const auto* tmp = (uint8_t*)&val;
return tmp[3] + (tmp[2] << 8) + (tmp[1] << 16) + (tmp[0] << 24);
}

uint16_t my_ntohs(const uint16_t val)
{
auto* tmp = (uint8_t*)&val;
const auto* tmp = (uint8_t*)&val;
return tmp[1] + (tmp[0] << 8);
}

char* strnstr(const char* s1, const char* s2, size_t len)
{
size_t l1 = len;
size_t l2 = strlen(s2);
const size_t l2 = strlen(s2);
if (!l2)
return (char*)s1;
while (l1 >= l2)
Expand Down Expand Up @@ -494,15 +494,15 @@ std::vector<wchar_t> mbtwc_wrapper(int codePage, const char* inputStr, int input

std::vector<wchar_t> fromAcp(const char* acpStr, int sz)
{
auto requiredSiz = MultiByteToWideChar(CP_ACP, 0, acpStr, sz, nullptr, 0);
const auto requiredSiz = MultiByteToWideChar(CP_ACP, 0, acpStr, sz, nullptr, 0);
return mbtwc_wrapper(CP_ACP, acpStr, sz, requiredSiz);
}

std::vector<wchar_t> toWide(const std::string& utf8Str) { return toWide(utf8Str.c_str(), (int)utf8Str.size()); }

std::vector<wchar_t> toWide(const char* utf8Str, int sz)
{
auto requiredSiz = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, utf8Str, sz, nullptr, 0);
const auto requiredSiz = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, utf8Str, sz, nullptr, 0);
if (requiredSiz != 0)
{
return mbtwc_wrapper(CP_UTF8, utf8Str, sz, static_cast<std::size_t>(requiredSiz));
Expand Down
10 changes: 5 additions & 5 deletions tsMuxer/aac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ bool AACCodec::decodeFrame(uint8_t* buffer, uint8_t* end)
bits.skipBit(); /* home */

/* adts_variable_header */
bits.skipBit(); /* copyright_identification_bit */
bits.skipBit(); /* copyright_identification_start */
int frameSize = bits.getBits(13); /* aac_frame_length */
bits.skipBits(11); /* adts_buffer_fullness */
m_rdb = bits.getBits(2); /* number_of_raw_data_blocks_in_frame */
bits.skipBit(); /* copyright_identification_bit */
bits.skipBit(); /* copyright_identification_start */
const int frameSize = bits.getBits(13); /* aac_frame_length */
bits.skipBits(11); /* adts_buffer_fullness */
m_rdb = bits.getBits(2); /* number_of_raw_data_blocks_in_frame */

m_channels = aac_channels[m_channels_index];
m_sample_rate = aac_sample_rates[m_sample_rates_index];
Expand Down
46 changes: 23 additions & 23 deletions tsMuxer/ac3Codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const CodecInfo &AC3Codec::getCodecInfo()
// returns true if ok, or false if error
bool AC3Codec::crc32(uint8_t *buf, int length)
{
uint8_t *end = buf + length;
const uint8_t *end = buf + length;

int crc = 0;
while (buf < end) crc = ctx[(uint8_t)crc ^ *buf++] ^ (crc >> 8);
Expand All @@ -91,7 +91,7 @@ AC3Codec::AC3ParseError AC3Codec::parseHeader(uint8_t *buf, uint8_t *end)
return AC3ParseError::SYNC;

// read ahead to bsid to make sure this is AC-3, not E-AC-3
int id = buf[3] >> 3;
const int id = buf[3] >> 3;
if (id > 16)
return AC3ParseError::BSID;

Expand Down Expand Up @@ -123,11 +123,11 @@ AC3Codec::AC3ParseError AC3Codec::parseHeader(uint8_t *buf, uint8_t *end)

gbc.skipBits(14); // substreamid, frmsize

int fscod = gbc.getBits(2);
const int fscod = gbc.getBits(2);

if (fscod == 3)
{
int m_fscod2 = gbc.getBits(2);
const int m_fscod2 = gbc.getBits(2);
if (m_fscod2 == 3)
return AC3ParseError::SYNC;

Expand All @@ -139,9 +139,9 @@ AC3Codec::AC3ParseError AC3Codec::parseHeader(uint8_t *buf, uint8_t *end)
numblkscod = gbc.getBits(2);
m_sample_rate = ff_ac3_freqs[fscod];
}
int number_of_blocks_per_syncframe = numblkscod == 0 ? 1 : (numblkscod == 1 ? 2 : (numblkscod == 2 ? 3 : 6));
int acmod = gbc.getBits(3);
int lfeon = gbc.getBit();
const int number_of_blocks_per_syncframe = numblkscod == 0 ? 1 : (numblkscod == 1 ? 2 : (numblkscod == 2 ? 3 : 6));
const int acmod = gbc.getBits(3);
const int lfeon = gbc.getBit();

m_samples = eac3_blocks[numblkscod] << 8;
m_bit_rateExt = m_frame_size * m_sample_rate * 8 / m_samples;
Expand All @@ -158,7 +158,7 @@ AC3Codec::AC3ParseError AC3Codec::parseHeader(uint8_t *buf, uint8_t *end)
{
if (gbc.getBit())
{
int chanmap = gbc.getBits(16);
const int chanmap = gbc.getBits(16);
if (chanmap & 0x7fe0) // mask standard 5.1 channels
m_extChannelsExists = true;
}
Expand Down Expand Up @@ -190,7 +190,7 @@ AC3Codec::AC3ParseError AC3Codec::parseHeader(uint8_t *buf, uint8_t *end)
gbc.skipBits(12); // mixdata
else if (mixdef == 3)
{
int mixdeflen = gbc.getBits(5); //
const int mixdeflen = gbc.getBits(5); //
if (gbc.getBit()) // mixdata2e
{
gbc.skipBits(5); // premixcmpsel, drcsrc, premixcmpscl
Expand Down Expand Up @@ -333,7 +333,7 @@ int AC3Codec::decodeFrame(uint8_t *buf, uint8_t *end, int &skipBytes)
if (m_state == AC3State::stateDecodeAC3)
{
skipBytes = 0;
AC3ParseError err = parseHeader(buf, end);
const AC3ParseError err = parseHeader(buf, end);

if (err == AC3ParseError::NOT_ENOUGH_BUFFER)
return NOT_ENOUGH_BUFFER;
Expand Down Expand Up @@ -421,12 +421,12 @@ AC3Codec::AC3ParseError AC3Codec::testParseHeader(uint8_t *buf, uint8_t *end)
BitStreamReader gbc{};
gbc.setBuffer(buf, buf + 7);

int test_sync_word = gbc.getBits(16);
const int test_sync_word = gbc.getBits(16);
if (test_sync_word != 0x0B77)
return AC3ParseError::SYNC;

// read ahead to bsid to make sure this is AC-3, not E-AC-3
int test_bsid = gbc.showBits(29) & 0x1F;
const int test_bsid = gbc.showBits(29) & 0x1F;
/*
if (test_bsid != m_bsid)
return AC3_PARSE_ERROR_SYNC;
Expand All @@ -443,18 +443,18 @@ AC3Codec::AC3ParseError AC3Codec::testParseHeader(uint8_t *buf, uint8_t *end)
else
{
gbc.skipBits(16); // test_crc1
int test_fscod = gbc.getBits(2);
const int test_fscod = gbc.getBits(2);
if (test_fscod == 3)
return AC3ParseError::SAMPLE_RATE;

int test_frmsizecod = gbc.getBits(6);
const int test_frmsizecod = gbc.getBits(6);
if (test_frmsizecod > 37)
return AC3ParseError::FRAME_SIZE;

gbc.skipBits(5); // skip bsid, already got it

int test_bsmod = gbc.getBits(3);
int test_acmod = gbc.getBits(3);
const int test_bsmod = gbc.getBits(3);
const int test_acmod = gbc.getBits(3);

if (test_fscod != m_fscod || /*(test_frmsizecod>>1) != (m_frmsizecod>>1) ||*/
test_bsmod != m_bsmod /*|| test_acmod != m_acmod*/)
Expand All @@ -468,20 +468,20 @@ AC3Codec::AC3ParseError AC3Codec::testParseHeader(uint8_t *buf, uint8_t *end)

if (m_acmod == AC3_ACMOD_STEREO)
{
int test_dsurmod = gbc.getBits(2);
const int test_dsurmod = gbc.getBits(2);
if (test_dsurmod != m_dsurmod)
return AC3ParseError::SYNC;
}
int test_lfeon = gbc.getBit();
const int test_lfeon = gbc.getBit();

if (test_lfeon != m_lfeon)
return AC3ParseError::SYNC;

int test_halfratecod = max(test_bsid, 8) - 8;
int test_sample_rate = ff_ac3_freqs[test_fscod] >> test_halfratecod;
int test_bit_rate = (ff_ac3_bitratetab[test_frmsizecod >> 1] * 1000) >> test_halfratecod;
int test_channels = ff_ac3_channels[test_acmod] + test_lfeon;
int test_frame_size = ff_ac3_frame_sizes[test_frmsizecod][test_fscod] * 2;
const int test_halfratecod = max(test_bsid, 8) - 8;
const int test_sample_rate = ff_ac3_freqs[test_fscod] >> test_halfratecod;
const int test_bit_rate = (ff_ac3_bitratetab[test_frmsizecod >> 1] * 1000) >> test_halfratecod;
const int test_channels = ff_ac3_channels[test_acmod] + test_lfeon;
const int test_frame_size = ff_ac3_frame_sizes[test_frmsizecod][test_fscod] * 2;
if (test_halfratecod != m_halfratecod || test_sample_rate != m_sample_rate || test_bit_rate != m_bit_rate ||
test_channels != m_channels || test_frame_size != m_frame_size)
return AC3ParseError::SYNC;
Expand Down
Loading

0 comments on commit 0007d79

Please sign in to comment.