Various changes suggested by cppcheck

- remove unused variables
- reduce the scope where it makes sense
- correct limits (did you know that strcat()'s last parameter does not
  include the \0 that is always added?)
- set some free()'d pointers to NULL
This commit is contained in:
Tillmann Karras
2014-02-23 23:03:39 +01:00
parent 5f0a8008f4
commit 315a8ba1c0
63 changed files with 494 additions and 420 deletions

View File

@ -32,7 +32,7 @@ static void LogFPSToFile(unsigned long val)
s_bench_file.Open(File::GetUserPath(D_LOGS_IDX) + "fps.txt", "w");
char buffer[256];
snprintf(buffer, 256, "%ld\n", val);
snprintf(buffer, 256, "%lu\n", val);
s_bench_file.WriteArray(buffer, strlen(buffer));
}

View File

@ -70,6 +70,7 @@ void Fifo_Shutdown()
{
if (GpuRunningState) PanicAlert("Fifo shutting down while active");
FreeMemoryPages(videoBuffer, FIFO_SIZE);
videoBuffer = NULL;
}
u8* GetVideoBufferStartPtr()

View File

@ -26,7 +26,7 @@ Inputs:
data : This is an array of RGBA with 8 bits per channel. 4 bytes for each pixel.
row_stride: Determines the amount of bytes per row of pixels.
*/
bool TextureToPng(u8* data, int row_stride, const std::string filename, int width, int height, bool saveAlpha)
bool TextureToPng(u8* data, int row_stride, const std::string& filename, int width, int height, bool saveAlpha)
{
bool success = false;

View File

@ -7,4 +7,4 @@
#include "Common/Common.h"
bool SaveData(const char* filename, const char* pdata);
bool TextureToPng(u8* data, int row_stride, const std::string filename, int width, int height, bool saveAlpha = true);
bool TextureToPng(u8* data, int row_stride, const std::string& filename, int width, int height, bool saveAlpha = true);

View File

@ -73,11 +73,8 @@ void TextureCache::Invalidate()
TextureCache::~TextureCache()
{
Invalidate();
if (temp)
{
FreeAlignedMemory(temp);
temp = NULL;
}
FreeAlignedMemory(temp);
temp = NULL;
}
void TextureCache::OnConfigChanged(VideoConfig& config)
@ -238,11 +235,11 @@ bool TextureCache::CheckForCustomTextureLODs(u64 tex_hash, int texformat, unsign
for (unsigned int level = 1; level < levels; ++level)
{
sprintf(texPathTemp, "%s_mip%i", texBasePathTemp, level);
sprintf(texPathTemp, "%s_mip%u", texBasePathTemp, level);
if (!HiresTextures::HiresTexExists(texPathTemp))
{
if (level > 1)
WARN_LOG(VIDEO, "Couldn't find custom texture LOD with index %i (filename: %s), disabling custom LODs for this texture", level, texPathTemp);
WARN_LOG(VIDEO, "Couldn't find custom texture LOD with index %u (filename: %s), disabling custom LODs for this texture", level, texPathTemp);
return false;
}
@ -260,7 +257,7 @@ PC_TexFormat TextureCache::LoadCustomTexture(u64 tex_hash, int texformat, unsign
if (level == 0)
sprintf(texPathTemp, "%s_%08x_%i", SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(), tex_hash_u32, texformat);
else
sprintf(texPathTemp, "%s_%08x_%i_mip%i", SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(), tex_hash_u32, texformat, level);
sprintf(texPathTemp, "%s_%08x_%i_mip%u", SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(), tex_hash_u32, texformat, level);
unsigned int required_size = 0;
PC_TexFormat ret = HiresTextures::GetHiresTex(texPathTemp, &newWidth, &newHeight, &required_size, texformat, temp_size, temp);

View File

@ -72,7 +72,7 @@ public:
virtual ~TCacheEntryBase();
virtual void Bind(unsigned int stage) = 0;
virtual bool Save(const std::string filename, unsigned int level) = 0;
virtual bool Save(const std::string& filename, unsigned int level) = 0;
virtual void Load(unsigned int width, unsigned int height,
unsigned int expanded_width, unsigned int level) = 0;

View File

@ -141,13 +141,13 @@ void WriteToBitDepth(char*& p, u8 depth, const char* src, const char* dest)
WRITE(p, " %s = floor(%s * 255.0 / exp2(8.0 - %d.0));\n", dest, src, depth);
}
void WriteEncoderEnd(char* p, API_TYPE ApiType)
void WriteEncoderEnd(char*& p, API_TYPE ApiType)
{
WRITE(p, "}\n");
IntensityConstantAdded = false;
}
void WriteI8Encoder(char* p, API_TYPE ApiType)
void WriteI8Encoder(char*& p, API_TYPE ApiType)
{
WriteSwizzler(p, GX_TF_I8, ApiType);
WRITE(p, " float3 texSample;\n");
@ -169,7 +169,7 @@ void WriteI8Encoder(char* p, API_TYPE ApiType)
WriteEncoderEnd(p, ApiType);
}
void WriteI4Encoder(char* p, API_TYPE ApiType)
void WriteI4Encoder(char*& p, API_TYPE ApiType)
{
WriteSwizzler(p, GX_TF_I4, ApiType);
WRITE(p, " float3 texSample;\n");
@ -210,7 +210,7 @@ void WriteI4Encoder(char* p, API_TYPE ApiType)
WriteEncoderEnd(p, ApiType);
}
void WriteIA8Encoder(char* p,API_TYPE ApiType)
void WriteIA8Encoder(char*& p,API_TYPE ApiType)
{
WriteSwizzler(p, GX_TF_IA8, ApiType);
WRITE(p, " float4 texSample;\n");
@ -228,7 +228,7 @@ void WriteIA8Encoder(char* p,API_TYPE ApiType)
WriteEncoderEnd(p, ApiType);
}
void WriteIA4Encoder(char* p,API_TYPE ApiType)
void WriteIA4Encoder(char*& p,API_TYPE ApiType)
{
WriteSwizzler(p, GX_TF_IA4, ApiType);
WRITE(p, " float4 texSample;\n");
@ -260,7 +260,7 @@ void WriteIA4Encoder(char* p,API_TYPE ApiType)
WriteEncoderEnd(p, ApiType);
}
void WriteRGB565Encoder(char* p,API_TYPE ApiType)
void WriteRGB565Encoder(char*& p,API_TYPE ApiType)
{
WriteSwizzler(p, GX_TF_RGB565, ApiType);
@ -283,7 +283,7 @@ void WriteRGB565Encoder(char* p,API_TYPE ApiType)
WriteEncoderEnd(p, ApiType);
}
void WriteRGB5A3Encoder(char* p,API_TYPE ApiType)
void WriteRGB5A3Encoder(char*& p,API_TYPE ApiType)
{
WriteSwizzler(p, GX_TF_RGB5A3, ApiType);
@ -349,7 +349,7 @@ void WriteRGB5A3Encoder(char* p,API_TYPE ApiType)
WriteEncoderEnd(p, ApiType);
}
void WriteRGBA4443Encoder(char* p,API_TYPE ApiType)
void WriteRGBA4443Encoder(char*& p,API_TYPE ApiType)
{
WriteSwizzler(p, GX_TF_RGB5A3, ApiType);
@ -373,7 +373,7 @@ void WriteRGBA4443Encoder(char* p,API_TYPE ApiType)
WriteEncoderEnd(p, ApiType);
}
void WriteRGBA8Encoder(char* p,API_TYPE ApiType)
void WriteRGBA8Encoder(char*& p,API_TYPE ApiType)
{
WriteSwizzler(p, GX_TF_RGBA8, ApiType);
@ -398,7 +398,7 @@ void WriteRGBA8Encoder(char* p,API_TYPE ApiType)
WriteEncoderEnd(p, ApiType);
}
void WriteC4Encoder(char* p, const char* comp,API_TYPE ApiType)
void WriteC4Encoder(char*& p, const char* comp,API_TYPE ApiType)
{
WriteSwizzler(p, GX_CTF_R4, ApiType);
WRITE(p, " float4 color0;\n");
@ -420,7 +420,7 @@ void WriteC4Encoder(char* p, const char* comp,API_TYPE ApiType)
WriteEncoderEnd(p, ApiType);
}
void WriteC8Encoder(char* p, const char* comp,API_TYPE ApiType)
void WriteC8Encoder(char*& p, const char* comp,API_TYPE ApiType)
{
WriteSwizzler(p, GX_CTF_R8, ApiType);
@ -432,7 +432,7 @@ void WriteC8Encoder(char* p, const char* comp,API_TYPE ApiType)
WriteEncoderEnd(p, ApiType);
}
void WriteCC4Encoder(char* p, const char* comp,API_TYPE ApiType)
void WriteCC4Encoder(char*& p, const char* comp,API_TYPE ApiType)
{
WriteSwizzler(p, GX_CTF_RA4, ApiType);
WRITE(p, " float2 texSample;\n");
@ -462,7 +462,7 @@ void WriteCC4Encoder(char* p, const char* comp,API_TYPE ApiType)
WriteEncoderEnd(p, ApiType);
}
void WriteCC8Encoder(char* p, const char* comp, API_TYPE ApiType)
void WriteCC8Encoder(char*& p, const char* comp, API_TYPE ApiType)
{
WriteSwizzler(p, GX_CTF_RA8, ApiType);
@ -472,7 +472,7 @@ void WriteCC8Encoder(char* p, const char* comp, API_TYPE ApiType)
WriteEncoderEnd(p, ApiType);
}
void WriteZ8Encoder(char* p, const char* multiplier,API_TYPE ApiType)
void WriteZ8Encoder(char*& p, const char* multiplier,API_TYPE ApiType)
{
WriteSwizzler(p, GX_CTF_Z8M, ApiType);
@ -493,7 +493,7 @@ void WriteZ8Encoder(char* p, const char* multiplier,API_TYPE ApiType)
WriteEncoderEnd(p, ApiType);
}
void WriteZ16Encoder(char* p,API_TYPE ApiType)
void WriteZ16Encoder(char*& p,API_TYPE ApiType)
{
WriteSwizzler(p, GX_TF_Z16, ApiType);
@ -525,7 +525,7 @@ void WriteZ16Encoder(char* p,API_TYPE ApiType)
WriteEncoderEnd(p, ApiType);
}
void WriteZ16LEncoder(char* p,API_TYPE ApiType)
void WriteZ16LEncoder(char*& p,API_TYPE ApiType)
{
WriteSwizzler(p, GX_CTF_Z16L, ApiType);
@ -561,7 +561,7 @@ void WriteZ16LEncoder(char* p,API_TYPE ApiType)
WriteEncoderEnd(p, ApiType);
}
void WriteZ24Encoder(char* p, API_TYPE ApiType)
void WriteZ24Encoder(char*& p, API_TYPE ApiType)
{
WriteSwizzler(p, GX_TF_Z24X8, ApiType);