Skip to content

Commit

Permalink
Merge pull request #16542 from unknownbrackets/warnings
Browse files Browse the repository at this point in the history
Cleanup some warnings from static analysis
  • Loading branch information
hrydgard authored Dec 11, 2022
2 parents 31efd95 + c9f3878 commit 9317fbd
Show file tree
Hide file tree
Showing 185 changed files with 598 additions and 673 deletions.
2 changes: 1 addition & 1 deletion Common/Arm64Emitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class ArithOption
private:
ARM64Reg m_destReg;
WidthSpecifier m_width;
ExtendSpecifier m_extend;
ExtendSpecifier m_extend = EXTEND_UXTB;
TypeSpecifier m_type;
ShiftType m_shifttype;
u32 m_shift;
Expand Down
29 changes: 13 additions & 16 deletions Common/ArmEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,32 +112,29 @@ class Operand2
OpType Type;

// IMM types
u8 Rotation; // Only for u8 values
u8 Rotation = 0; // Only for u8 values

// Register types
u8 IndexOrShift;
ShiftType Shift;
u8 IndexOrShift = 0;
ShiftType Shift = ST_LSL;
public:
OpType GetType() const
{
OpType GetType() const {
return Type;
}
Operand2() {}
Operand2(u32 imm, OpType type = TYPE_IMM)
{
Type = type;
Value = imm;
Rotation = 0;
Operand2() {
Type = TYPE_IMM;
Value = 0;
}
Operand2(u32 imm, OpType type = TYPE_IMM) {
Type = type;
Value = imm;
}

Operand2(ARMReg Reg)
{
Operand2(ARMReg Reg) {
Type = TYPE_REG;
Value = Reg;
Rotation = 0;
}
Operand2(u8 imm, u8 rotation)
{
Operand2(u8 imm, u8 rotation) {
Type = TYPE_IMM;
Value = imm;
Rotation = rotation;
Expand Down
4 changes: 3 additions & 1 deletion Common/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ int Buffer::TakeLineCRLF(std::string *dest) {
if (after_next_line < 0) {
return after_next_line;
} else {
Take(after_next_line - 2, dest);
_dbg_assert_(after_next_line >= 2);
if (after_next_line != 2)
Take((size_t)after_next_line - 2, dest);
Skip(2); // Skip the CRLF
return after_next_line - 2;
}
Expand Down
5 changes: 4 additions & 1 deletion Common/CPUDetect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,10 @@ void CPUInfo::Detect() {
#if PPSSPP_PLATFORM(WINDOWS)
#if !PPSSPP_PLATFORM(UWP)
typedef BOOL (WINAPI *getLogicalProcessorInformationEx_f)(LOGICAL_PROCESSOR_RELATIONSHIP RelationshipType, PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX Buffer, PDWORD ReturnedLength);
auto getLogicalProcessorInformationEx = (getLogicalProcessorInformationEx_f)GetProcAddress(GetModuleHandle(L"kernel32.dll"), "GetLogicalProcessorInformationEx");
getLogicalProcessorInformationEx_f getLogicalProcessorInformationEx = nullptr;
HMODULE kernel32 = GetModuleHandle(L"kernel32.dll");
if (kernel32)
getLogicalProcessorInformationEx = (getLogicalProcessorInformationEx_f)GetProcAddress(kernel32, "GetLogicalProcessorInformationEx");
#else
void *getLogicalProcessorInformationEx = nullptr;
#endif
Expand Down
5 changes: 4 additions & 1 deletion Common/CodeBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ template<class T> class CodeBlock : public CodeBlockCommon, public T {

public:
CodeBlock() {}
virtual ~CodeBlock() { if (region) FreeCodeSpace(); }
~CodeBlock() {
if (region)
FreeCodeSpace();
}

// Call this before you generate any code.
void AllocCodeSpace(int size) {
Expand Down
6 changes: 3 additions & 3 deletions Common/ConsoleListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ConsoleListener : public LogListener {
#if defined(USING_WIN_UI)
COORD GetCoordinates(int BytesRead, int BufferWidth);
#endif
void Log(const LogMessage &message);
void Log(const LogMessage &message) override;
void ClearScreen(bool Cursor = true);

void Show(bool bShow);
Expand All @@ -66,8 +66,8 @@ class ConsoleListener : public LogListener {
static std::atomic<uint32_t> logPendingReadPos;
static std::atomic<uint32_t> logPendingWritePos;

int openWidth_;
int openHeight_;
int openWidth_ = 0;
int openHeight_ = 0;
std::wstring title_;
#endif
bool bHidden;
Expand Down
82 changes: 0 additions & 82 deletions Common/Data/Convert/ColorConv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,88 +34,6 @@
#endif
#endif

// convert 4444 image to 8888, parallelizable
void convert4444_gl(u16* data, u32* out, int width, int l, int u) {
for (int y = l; y < u; ++y) {
for (int x = 0; x < width; ++x) {
u32 val = data[y*width + x];
u32 r = ((val >> 12) & 0xF) * 17;
u32 g = ((val >> 8) & 0xF) * 17;
u32 b = ((val >> 4) & 0xF) * 17;
u32 a = ((val >> 0) & 0xF) * 17;
out[y*width + x] = (a << 24) | (b << 16) | (g << 8) | r;
}
}
}

// convert 565 image to 8888, parallelizable
void convert565_gl(u16* data, u32* out, int width, int l, int u) {
for (int y = l; y < u; ++y) {
for (int x = 0; x < width; ++x) {
u32 val = data[y*width + x];
u32 r = Convert5To8((val >> 11) & 0x1F);
u32 g = Convert6To8((val >> 5) & 0x3F);
u32 b = Convert5To8((val)& 0x1F);
out[y*width + x] = (0xFF << 24) | (b << 16) | (g << 8) | r;
}
}
}

// convert 5551 image to 8888, parallelizable
void convert5551_gl(u16* data, u32* out, int width, int l, int u) {
for (int y = l; y < u; ++y) {
for (int x = 0; x < width; ++x) {
u32 val = data[y*width + x];
u32 r = Convert5To8((val >> 11) & 0x1F);
u32 g = Convert5To8((val >> 6) & 0x1F);
u32 b = Convert5To8((val >> 1) & 0x1F);
u32 a = (val & 0x1) * 255;
out[y*width + x] = (a << 24) | (b << 16) | (g << 8) | r;
}
}
}

// convert 4444 image to 8888, parallelizable
void convert4444_dx9(u16* data, u32* out, int width, int l, int u) {
for (int y = l; y < u; ++y) {
for (int x = 0; x < width; ++x) {
u32 val = data[y*width + x];
u32 r = ((val >> 0) & 0xF) * 17;
u32 g = ((val >> 4) & 0xF) * 17;
u32 b = ((val >> 8) & 0xF) * 17;
u32 a = ((val >> 12) & 0xF) * 17;
out[y*width + x] = (a << 24) | (b << 16) | (g << 8) | r;
}
}
}

// convert 565 image to 8888, parallelizable
void convert565_dx9(u16* data, u32* out, int width, int l, int u) {
for (int y = l; y < u; ++y) {
for (int x = 0; x < width; ++x) {
u32 val = data[y*width + x];
u32 r = Convert5To8((val)& 0x1F);
u32 g = Convert6To8((val >> 5) & 0x3F);
u32 b = Convert5To8((val >> 11) & 0x1F);
out[y*width + x] = (0xFF << 24) | (b << 16) | (g << 8) | r;
}
}
}

// convert 5551 image to 8888, parallelizable
void convert5551_dx9(u16* data, u32* out, int width, int l, int u) {
for (int y = l; y < u; ++y) {
for (int x = 0; x < width; ++x) {
u32 val = data[y*width + x];
u32 r = Convert5To8((val >> 0) & 0x1F);
u32 g = Convert5To8((val >> 5) & 0x1F);
u32 b = Convert5To8((val >> 10) & 0x1F);
u32 a = ((val >> 15) & 0x1) * 255;
out[y*width + x] = (a << 24) | (b << 16) | (g << 8) | r;
}
}
}

void ConvertBGRA8888ToRGBA8888(u32 *dst, const u32 *src, u32 numPixels) {
#ifdef _M_SSE
const __m128i maskGA = _mm_set1_epi32(0xFF00FF00);
Expand Down
9 changes: 0 additions & 9 deletions Common/Data/Convert/ColorConv.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,6 @@ inline u16 RGBA8888ToRGBA444X(u32 value) {
return r | g | b;
}

// convert image to 8888, parallelizable
// TODO: Implement these in terms of the conversion functions below.
void convert4444_gl(u16* data, u32* out, int width, int l, int u);
void convert565_gl(u16* data, u32* out, int width, int l, int u);
void convert5551_gl(u16* data, u32* out, int width, int l, int u);
void convert4444_dx9(u16* data, u32* out, int width, int l, int u);
void convert565_dx9(u16* data, u32* out, int width, int l, int u);
void convert5551_dx9(u16* data, u32* out, int width, int l, int u);

// "Complete" set of color conversion functions between the usual formats.

// TODO: Need to revisit the naming convention of these. Seems totally backwards
Expand Down
2 changes: 1 addition & 1 deletion Common/Data/Encoding/Utf8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ int u8_toucs(uint32_t *dest, int sz, const char *src, int srcsz)
the NUL as well.
the destination string will never be bigger than the source string.
*/
int u8_toutf8(char *dest, int sz, uint32_t *src, int srcsz)
int u8_toutf8(char *dest, int sz, const uint32_t *src, int srcsz)
{
uint32_t ch;
int i = 0;
Expand Down
8 changes: 5 additions & 3 deletions Common/Data/Format/JSONReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ class JsonReader {
JsonReader(const std::string &filename);
JsonReader(const void *data, size_t size) {
buffer_ = (char *)malloc(size + 1);
memcpy(buffer_, data, size);
buffer_[size] = 0;
parse();
if (buffer_) {
memcpy(buffer_, data, size);
buffer_[size] = 0;
parse();
}
}
JsonReader(const JsonNode *node) {
ok_ = true;
Expand Down
1 change: 1 addition & 0 deletions Common/Data/Text/WrapText.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class WordWrapper {
WordWrapper(const char *str, float maxW, int flags)
: str_(str), maxW_(maxW), flags_(flags) {
}
virtual ~WordWrapper() {}

std::string Wrapped();

Expand Down
5 changes: 3 additions & 2 deletions Common/File/FileUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ FILE *OpenCFile(const Path &path, const char *mode) {
return nullptr;
}
FILE *f = fdopen(descriptor, "wb");
if (!strcmp(mode, "at") || !strcmp(mode, "a")) {
if (f && (!strcmp(mode, "at") || !strcmp(mode, "a"))) {
// Append mode.
fseek(f, 0, SEEK_END);
}
Expand Down Expand Up @@ -250,7 +250,8 @@ static bool ResolvePathVista(const std::wstring &path, wchar_t *buf, DWORD bufSi
#else
if (!getFinalPathNameByHandleW) {
HMODULE kernel32 = GetModuleHandle(L"kernel32.dll");
getFinalPathNameByHandleW = (getFinalPathNameByHandleW_f)GetProcAddress(kernel32, "GetFinalPathNameByHandleW");
if (kernel32)
getFinalPathNameByHandleW = (getFinalPathNameByHandleW_f)GetProcAddress(kernel32, "GetFinalPathNameByHandleW");
}
#endif

Expand Down
8 changes: 4 additions & 4 deletions Common/File/VFS/AssetReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ class DirectoryAssetReader : public AssetReader {
public:
explicit DirectoryAssetReader(const Path &path);
// use delete[]
virtual uint8_t *ReadAsset(const char *path, size_t *size);
virtual bool GetFileListing(const char *path, std::vector<File::FileInfo> *listing, const char *filter);
virtual bool GetFileInfo(const char *path, File::FileInfo *info);
virtual std::string toString() const {
uint8_t *ReadAsset(const char *path, size_t *size) override;
bool GetFileListing(const char *path, std::vector<File::FileInfo> *listing, const char *filter) override;
bool GetFileInfo(const char *path, File::FileInfo *info) override;
std::string toString() const override {
return path_.ToString();
}

Expand Down
10 changes: 7 additions & 3 deletions Common/GPU/D3D11/thin3d_d3d11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class D3D11DrawContext : public DrawContext {
private:
void ApplyCurrentState();

ID3D11DepthStencilState *GetCachedDepthStencilState(D3D11DepthStencilState *state, uint8_t stencilWriteMask, uint8_t stencilCompareMask);
ID3D11DepthStencilState *GetCachedDepthStencilState(const D3D11DepthStencilState *state, uint8_t stencilWriteMask, uint8_t stencilCompareMask);

HWND hWnd_;
ID3D11Device *device_;
Expand Down Expand Up @@ -550,7 +550,7 @@ class D3D11BlendState : public BlendState {
float blendFactor[4];
};

ID3D11DepthStencilState *D3D11DrawContext::GetCachedDepthStencilState(D3D11DepthStencilState *state, uint8_t stencilWriteMask, uint8_t stencilCompareMask) {
ID3D11DepthStencilState *D3D11DrawContext::GetCachedDepthStencilState(const D3D11DepthStencilState *state, uint8_t stencilWriteMask, uint8_t stencilCompareMask) {
D3D11DepthStencilKey key;
key.desc = state->desc;
key.writeMask = stencilWriteMask;
Expand Down Expand Up @@ -1476,6 +1476,7 @@ void D3D11DrawContext::CopyFramebufferImage(Framebuffer *srcfb, int level, int x
dstTex = dst->depthStencilTex;
break;
}
_assert_(srcTex && dstTex);

// TODO: Check for level too!
if (width == src->Width() && width == dst->Width() && height == src->Height() && height == dst->Height() && x == 0 && y == 0 && z == 0 && dstX == 0 && dstY == 0 && dstZ == 0) {
Expand Down Expand Up @@ -1534,7 +1535,7 @@ bool D3D11DrawContext::CopyFramebufferToMemorySync(Framebuffer *src, int channel

bool useGlobalPacktex = (bx + bw <= 512 && by + bh <= 512) && channelBits == FB_COLOR_BIT;

ID3D11Texture2D *packTex;
ID3D11Texture2D *packTex = nullptr;
if (!useGlobalPacktex) {
D3D11_TEXTURE2D_DESC packDesc{};
packDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
Expand Down Expand Up @@ -1573,6 +1574,9 @@ bool D3D11DrawContext::CopyFramebufferToMemorySync(Framebuffer *src, int channel
packTex = packTexture_;
}

if (!packTex)
return false;

D3D11_BOX srcBox{ (UINT)bx, (UINT)by, 0, (UINT)(bx + bw), (UINT)(by + bh), 1 };
DataFormat srcFormat = DataFormat::UNDEFINED;
switch (channelBits) {
Expand Down
15 changes: 8 additions & 7 deletions Common/GPU/D3D9/thin3d_d3d9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ class D3D9Texture : public Texture {
D3D9Texture(LPDIRECT3DDEVICE9 device, LPDIRECT3DDEVICE9EX deviceEx, const TextureDesc &desc);
~D3D9Texture();
void SetToSampler(LPDIRECT3DDEVICE9 device, int sampler);
LPDIRECT3DBASETEXTURE9 Texture() const {
LPDIRECT3DBASETEXTURE9 TexturePtr() const {
// TODO: Cleanup
if (tex_) {
return tex_;
Expand Down Expand Up @@ -590,7 +590,7 @@ class D3D9Context : public DrawContext {
case NativeObject::DEVICE_EX:
return (uint64_t)(uintptr_t)deviceEx_;
case NativeObject::TEXTURE_VIEW:
return (uint64_t)(((D3D9Texture *)srcObject)->Texture());
return (uint64_t)(((D3D9Texture *)srcObject)->TexturePtr());
default:
return 0;
}
Expand Down Expand Up @@ -1007,7 +1007,7 @@ class D3D9Buffer : public Buffer {
device->CreateVertexBuffer((UINT)size, usage, 0, D3DPOOL_DEFAULT, &vbuffer_, NULL);
}
}
virtual ~D3D9Buffer() override {
~D3D9Buffer() {
if (ibuffer_) {
ibuffer_->Release();
}
Expand Down Expand Up @@ -1072,16 +1072,16 @@ void D3D9Context::UpdateBuffer(Buffer *buffer, const uint8_t *data, size_t offse
return;
}
if (buf->vbuffer_) {
void *ptr;
void *ptr = nullptr;
HRESULT res = buf->vbuffer_->Lock((UINT)offset, (UINT)size, &ptr, (flags & UPDATE_DISCARD) ? D3DLOCK_DISCARD : 0);
if (!FAILED(res)) {
if (!FAILED(res) && ptr) {
memcpy(ptr, data, size);
buf->vbuffer_->Unlock();
}
} else if (buf->ibuffer_) {
void *ptr;
void *ptr = nullptr;
HRESULT res = buf->ibuffer_->Lock((UINT)offset, (UINT)size, &ptr, (flags & UPDATE_DISCARD) ? D3DLOCK_DISCARD : 0);
if (!FAILED(res)) {
if (!FAILED(res) && ptr) {
memcpy(ptr, data, size);
buf->ibuffer_->Unlock();
}
Expand Down Expand Up @@ -1438,6 +1438,7 @@ bool D3D9Context::CopyFramebufferToMemorySync(Framebuffer *src, int channelBits,

LPDIRECT3DSURFACE9 offscreen = nullptr;
HRESULT hr = E_UNEXPECTED;
_assert_(fb != nullptr);
if (channelBits == FB_COLOR_BIT) {
fb->tex->GetLevelDesc(0, &desc);

Expand Down
2 changes: 1 addition & 1 deletion Common/GPU/OpenGL/GLRenderManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ class GLRenderManager {
return step.create_program.program;
}

GLRInputLayout *CreateInputLayout(std::vector<GLRInputLayout::Entry> &entries) {
GLRInputLayout *CreateInputLayout(const std::vector<GLRInputLayout::Entry> &entries) {
GLRInitStep step{ GLRInitStepType::CREATE_INPUT_LAYOUT };
step.create_input_layout.inputLayout = new GLRInputLayout();
step.create_input_layout.inputLayout->entries = entries;
Expand Down
Loading

0 comments on commit 9317fbd

Please sign in to comment.