Fix some assorted static analysis warnings

This commit is contained in:
Henrik Rydgård committed 2025-08-25 10:14:15 +02:00
1 parent 0d8b4416f4
commit 3e62157487
7 files changed
+54 -26

No files matched your search

+2 -2
View File
@@ -95,7 +95,6 @@ void BreakIntoPSPDebugger(const char *reason) {
bool HandleAssert(const char *function, const char *file, int line, const char *expression, const char* format, ...) {
// Read message and write it to the log
char text[LOG_BUF_SIZE];
const char *caption = "Critical";
va_list args;
va_start(args, format);
vsnprintf(text, sizeof(text), format, args);
@@ -136,7 +135,8 @@ bool HandleAssert(const char *function, const char *file, int line, const char *
const char *threadName = GetCurrentThreadName();
OutputDebugStringA(formatted);
printf("%s\n", formatted);
std::wstring wcaption = ConvertUTF8ToWString(std::string(caption) + " " + (threadName ? threadName : "(unknown thread)"));
static const std::string caption = "Critical";
std::wstring wcaption = ConvertUTF8ToWString(caption + " " + (threadName ? threadName : "(unknown thread)"));
switch (MessageBox(g_dialogParent, ConvertUTF8ToWString(text).c_str(), wcaption.c_str(), msgBoxStyle)) {
case IDYES:
return true;
+2 -2
View File
@@ -759,9 +759,9 @@ bool DetectRectangleFromPair(const RasterizerState &state, const ClipVertexData
bool DetectRectangleThroughModeSlices(const RasterizerState &state, const ClipVertexData data[4]) {
// Color and Z must be flat.
for (int i = 1; i < 4; ++i) {
if (!(data[i].v.color0 == data[0].v.color0))
if (data[i].v.color0 != data[0].v.color0)
return false;
if (!(data[i].v.screenpos.z == data[0].v.screenpos.z)) {
if (data[i].v.screenpos.z != data[0].v.screenpos.z) {
// Sometimes, we don't actually care about z.
if (state.pixelID.depthWrite || state.pixelID.DepthTestFunc() != GE_COMP_ALWAYS)
return false;
+6 -3
View File
@@ -687,7 +687,7 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
return true;
}
case SystemRequestType::BROWSE_FOR_FOLDER:
{
// Launch on a thread to avoid blocking the main thread. Can feel slow.
std::thread([=] {
SetCurrentThreadName("BrowseForFolder");
std::string folder = W32Util::BrowseForFolder2(MainWindow::GetHWND(), param1, param2);
@@ -698,10 +698,13 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
}
}).detach();
return true;
}
case SystemRequestType::SHOW_FILE_IN_FOLDER:
W32Util::ShowFileInFolder(param1);
// Launch on a thread to avoid blocking the main thread. Can feel slow.
std::thread([=] {
SetCurrentThreadName("ShowFileInFolder");
W32Util::ShowFileInFolder(param1);
}).detach();
return true;
case SystemRequestType::TOGGLE_FULLSCREEN_STATE:
@@ -170,7 +170,7 @@ class CameraHelper {
String devName = index + ":" + (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK ? "Back Camera" : "Front Camera");
deviceList.add(devName);
} catch (Exception e) {
Log.e(TAG, "Failed to get camera info: " + e.toString());
Log.e(TAG, "Failed to get camera info: " + e);
}
}
return deviceList;
@@ -262,7 +262,7 @@ class CameraHelper {
mCamera.startPreview();
mIsCameraRunning = true;
} catch (Exception e) {
Log.e(TAG, "Cannot start camera: " + e.toString());
Log.e(TAG, "Cannot start camera: " + e);
}
}
@@ -16,15 +16,15 @@ public class InputDeviceState {
private int deviceId = NativeApp.DEVICE_ID_DEFAULT;
private InputDevice mDevice;
private int[] mAxes;
private final InputDevice mDevice;
private final int[] mAxes;
private float[] mAxisPrevValue;
// Buffers for the native calls.
private int[] mAxisIds = null;
private float[] mValues = null;
private final int[] mAxisIds;
private final float[] mValues;
private int sources;
private final int sources;
InputDevice getDevice() {
return mDevice;
@@ -2,7 +2,6 @@ package org.ppsspp.ppsspp;
import android.opengl.GLSurfaceView;
import android.util.Log;
import android.widget.Toast;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
@@ -12,8 +11,8 @@ import javax.microedition.khronos.opengles.GL10;
// Only used for the OpenGL backend.
public class NativeRenderer implements GLSurfaceView.Renderer {
private static String TAG = "NativeRenderer";
private NativeActivity mActivity;
private static final String TAG = "NativeRenderer";
private final NativeActivity mActivity;
private boolean inFrame = false;
private boolean failed = false;
@@ -1,8 +1,8 @@
package org.ppsspp.ppsspp;
import android.annotation.TargetApi;
import androidx.annotation.Keep;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
@@ -10,9 +10,6 @@ import android.os.Bundle;
import android.os.Environment;
import android.os.Looper;
import android.os.ParcelFileDescriptor;
import android.os.StatFs;
import android.os.storage.StorageVolume;
import android.provider.MediaStore;
import android.util.Log;
import android.system.StructStatVfs;
import android.system.Os;
@@ -25,7 +22,6 @@ import androidx.annotation.RequiresApi;
import androidx.documentfile.provider.DocumentFile;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.io.File;
@@ -135,6 +131,8 @@ public class PpssppActivity extends NativeActivity {
// called by the C++ code through JNI. Dispatch anything we can't directly handle
// on the gfx thread to the UI thread.
@Keep
@SuppressWarnings("unused")
public void postCommand(String command, String parameter) {
final String cmd = command;
final String param = parameter;
@@ -146,6 +144,8 @@ public class PpssppActivity extends NativeActivity {
});
}
@Keep
@SuppressWarnings("unused")
public String getDebugString(String str) {
if (str.equals("InputDevice")) {
return getInputDeviceDebugString();
@@ -267,6 +267,8 @@ public class PpssppActivity extends NativeActivity {
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Keep
@SuppressWarnings("unused")
public long computeRecursiveDirectorySize(String uriString) {
try {
Uri uri = Uri.parse(uriString);
@@ -283,6 +285,8 @@ public class PpssppActivity extends NativeActivity {
// * https://stackoverflow.com/q
// uestions/42186820/documentfile-is-very-slow
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Keep
@SuppressWarnings("unused")
public String[] listContentUriDir(String uriString) {
Cursor c = null;
try {
@@ -292,8 +296,6 @@ public class PpssppActivity extends NativeActivity {
uri, DocumentsContract.getDocumentId(uri));
final ArrayList<String> listing = new ArrayList<>();
String selection = null;
String[] selectionArgs = null;
c = resolver.query(childrenUri, columns, null, null, null);
if (c == null) {
return new String[]{ "X" };
@@ -321,6 +323,8 @@ public class PpssppActivity extends NativeActivity {
}
}
@Keep
@SuppressWarnings("unused")
public int contentUriCreateDirectory(String rootTreeUri, String dirName) {
try {
Uri uri = Uri.parse(rootTreeUri);
@@ -338,6 +342,8 @@ public class PpssppActivity extends NativeActivity {
}
}
@Keep
@SuppressWarnings("unused")
public int contentUriCreateFile(String rootTreeUri, String fileName) {
try {
Uri uri = Uri.parse(rootTreeUri);
@@ -356,6 +362,7 @@ public class PpssppActivity extends NativeActivity {
}
}
@Keep
public int contentUriRemoveFile(String fileName) {
try {
Uri uri = Uri.parse(fileName);
@@ -363,6 +370,7 @@ public class PpssppActivity extends NativeActivity {
if (documentFile != null) {
return documentFile.delete() ? STORAGE_ERROR_SUCCESS : STORAGE_ERROR_UNKNOWN;
} else {
// This can return null on old Android versions (that we no longer supports).
return STORAGE_ERROR_UNKNOWN;
}
} catch (Exception e) {
@@ -374,6 +382,8 @@ public class PpssppActivity extends NativeActivity {
// NOTE: The destination is the parent directory! This means that contentUriCopyFile
// cannot rename things as part of the operation.
@TargetApi(Build.VERSION_CODES.N)
@Keep
@SuppressWarnings("unused")
public int contentUriCopyFile(String srcFileUri, String dstParentDirUri) {
try {
Uri srcUri = Uri.parse(srcFileUri);
@@ -388,6 +398,8 @@ public class PpssppActivity extends NativeActivity {
// NOTE: The destination is the parent directory! This means that contentUriCopyFile
// cannot rename things as part of the operation.
@TargetApi(Build.VERSION_CODES.N_MR1)
@Keep
@SuppressWarnings("unused")
public int contentUriMoveFile(String srcFileUri, String srcParentDirUri, String dstParentDirUri) {
try {
Uri srcUri = Uri.parse(srcFileUri);
@@ -404,6 +416,8 @@ public class PpssppActivity extends NativeActivity {
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Keep
@SuppressWarnings("unused")
public int contentUriRenameFileTo(String fileUri, String newName) {
try {
Uri uri = Uri.parse(fileUri);
@@ -436,6 +450,8 @@ public class PpssppActivity extends NativeActivity {
// Probably slightly faster than contentUriGetFileInfo.
// Smaller difference now than before I changed that one to a query...
@TargetApi(Build.VERSION_CODES.KITKAT)
@Keep
@SuppressWarnings("unused")
public boolean contentUriFileExists(String fileUri) {
Cursor c = null;
try {
@@ -458,6 +474,8 @@ public class PpssppActivity extends NativeActivity {
}
}
@Keep
@SuppressWarnings("unused")
public String contentUriGetFileInfo(String fileName) {
Cursor c = null;
try {
@@ -484,11 +502,13 @@ public class PpssppActivity extends NativeActivity {
// let's just not bother with that for now.
// NOTE: This is really super slow!
@RequiresApi(Build.VERSION_CODES.M)
@Keep
@SuppressWarnings("unused")
public long contentUriGetFreeStorageSpaceSlow(Uri uri) {
try {
ParcelFileDescriptor pfd = getContentResolver().openFileDescriptor(uri, "r");
if (pfd == null) {
Log.w(TAG, "Failed to get free storage space from URI: " + uri.toString());
Log.w(TAG, "Failed to get free storage space from URI: " + uri);
return -1;
}
StructStatVfs stats = Os.fstatvfs(pfd.getFileDescriptor());
@@ -503,6 +523,8 @@ public class PpssppActivity extends NativeActivity {
}
}
@Keep
@SuppressWarnings("unused")
public long contentUriGetFreeStorageSpace(String str) {
Uri uri = Uri.parse(str);
if (uri == null) {
@@ -519,18 +541,22 @@ public class PpssppActivity extends NativeActivity {
}
@TargetApi(Build.VERSION_CODES.O)
@Keep
@SuppressWarnings("unused")
public long filePathGetFreeStorageSpace(String filePath) {
try {
StorageManager storageManager = getApplicationContext().getSystemService(StorageManager.class);
File file = new File(filePath);
UUID volumeUUID = storageManager.getUuidForPath(file);
return storageManager.getAllocatableBytes(volumeUUID);
} catch (Exception e) {
} catch (Exception e) {
Log.e(TAG, "filePathGetFreeStorageSpace exception: " + e);
return -1;
}
}
@Keep
@SuppressWarnings("unused")
public boolean isExternalStoragePreservedLegacy() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
// In 29 and later, we can check whether we got preserved storage legacy.