Improved code based on CppCheck results

None of this should change the engine's behavior, but the code is better
this way.


Former-commit-id: 0127769848fc1f7fc8006ee607985cfc0ead2965
This commit is contained in:
Lynix
2015-06-05 13:25:17 +02:00
parent 0f27930467
commit fc65b30f84
15 changed files with 22 additions and 49 deletions

View File

@@ -551,7 +551,6 @@ NzString NzFile::AbsolutePath(const NzString& filePath)
return path;
// Nous avons un chemin absolu, mais il nous faut un peu le nettoyer
unsigned int pathLen = base.GetSize();
for (unsigned int i = 0; i < sep.size(); ++i)
{
if (sep[i] == '.')
@@ -563,12 +562,8 @@ NzString NzFile::AbsolutePath(const NzString& filePath)
sep.erase(sep.begin() + i--);
}
else
pathLen += sep[i].GetSize();
}
pathLen += sep.size()-1;
NzStringStream stream(base);
for (unsigned int i = 0; i < sep.size(); ++i)
{
@@ -730,10 +725,9 @@ bool NzFile::FillHash(NzAbstractHash* hash) const
nzUInt64 remainingSize = file.GetSize();
char buffer[NAZARA_CORE_FILE_BUFFERSIZE];
unsigned int size;
while (remainingSize > 0)
{
size = static_cast<unsigned int>(std::min(remainingSize, static_cast<nzUInt64>(NAZARA_CORE_FILE_BUFFERSIZE)));
unsigned int size = static_cast<unsigned int>(std::min(remainingSize, static_cast<nzUInt64>(NAZARA_CORE_FILE_BUFFERSIZE)));
if (file.Read(&buffer[0], sizeof(char), size) != sizeof(char)*size)
{
NazaraError("Unable to read file");

View File

@@ -79,7 +79,7 @@ NzHashCRC32::NzHashCRC32(nzUInt32 polynomial)
{
table[i] = crc32_reflect(i, 8) << 24;
for (unsigned int j = 0; j < 8; ++j)
table[i] = (table[i] << 1) ^ (table[i] & (1 << 31) ? polynomial : 0);
table[i] = (table[i] << 1) ^ (table[i] & ((1 << 31) ? polynomial : 0));
table[i] = crc32_reflect(table[i], 32);
}

View File

@@ -436,16 +436,15 @@ namespace
void SHA1_Update(SHA_CTX* context, const nzUInt8* data, std::size_t len)
{
unsigned int freespace, usedspace;
if (len == 0)
/* Calling with no data is valid - we do nothing */
return;
usedspace = (context->s1.bitcount >> 3) % 64;
unsigned int usedspace = (context->s1.bitcount >> 3) % 64;
if (usedspace > 0)
{
/* Calculate how much free space is available in the buffer */
freespace = 64 - usedspace;
unsigned int freespace = 64 - usedspace;
if (len >= freespace)
{
@@ -647,17 +646,15 @@ void SHA256_Internal_Transform(SHA_CTX* context, const nzUInt32* data)
void SHA256_Update(SHA_CTX* context, const nzUInt8 *data, std::size_t len)
{
unsigned int freespace, usedspace;
if (len == 0)
/* Calling with no data is valid - we do nothing */
return;
usedspace = (context->s256.bitcount >> 3) % 64;
unsigned int usedspace = (context->s256.bitcount >> 3) % 64;
if (usedspace > 0)
{
/* Calculate how much free space is available in the buffer */
freespace = 64 - usedspace;
unsigned int freespace = 64 - usedspace;
if (len >= freespace)
{
@@ -905,17 +902,15 @@ void SHA512_Internal_Transform(SHA_CTX* context, const nzUInt64* data)
void SHA512_Update(SHA_CTX* context, const nzUInt8 *data, std::size_t len)
{
unsigned int freespace, usedspace;
if (len == 0)
/* Calling with no data is valid - we do nothing */
return;
usedspace = (context->s512.bitcount[0] >> 3) % 128;
unsigned int usedspace = (context->s512.bitcount[0] >> 3) % 128;
if (usedspace > 0)
{
/* Calculate how much free space is available in the buffer */
freespace = 128 - usedspace;
unsigned int freespace = 128 - usedspace;
if (len >= freespace)
{