Global: fix code smells

This commit is contained in:
李通洲
2025-03-26 16:42:39 +08:00
parent 1129ed9be4
commit de5ef3842c
15 changed files with 63 additions and 25 deletions
+5
View File
@@ -69,10 +69,15 @@ const char* ffDetectDiskIO(FFlist* result, FFDiskIOOptions* options)
uint64_t temp = *currValue;
*currValue -= *prevValue;
*currValue /= (time2 - time1) / 1000 /* seconds */;
// For next function call
*prevValue = temp;
}
}
// For next function call
time1 = time2;
// Leak ioCounters1 here
return NULL;
}
+8 -6
View File
@@ -8,10 +8,10 @@
#include <inttypes.h>
#include <fcntl.h>
static void parseDiskIOCounters(int dfd, const char* devName, FFlist* result, FFDiskIOOptions* options)
static const char* parseDiskIOCounters(int dfd, const char* devName, FFlist* result, FFDiskIOOptions* options)
{
FF_AUTO_CLOSE_FD int devfd = openat(dfd, "device", O_RDONLY | O_CLOEXEC | O_PATH | O_DIRECTORY);
if (devfd < 0) return; // virtual device
if (devfd < 0) return "virtual device";
FF_STRBUF_AUTO_DESTROY name = ffStrbufCreate();
@@ -49,7 +49,7 @@ static void parseDiskIOCounters(int dfd, const char* devName, FFlist* result, FF
}
if (options->namePrefix.length && !ffStrbufStartsWith(&name, &options->namePrefix))
return;
return "ignored";
}
// I/Os merges sectors ticks ...
@@ -57,10 +57,10 @@ static void parseDiskIOCounters(int dfd, const char* devName, FFlist* result, FF
{
char sysBlockStat[PROC_FILE_BUFFSIZ];
ssize_t fileSize = ffReadFileDataRelative(dfd, "stat", ARRAY_SIZE(sysBlockStat) - 1, sysBlockStat);
if (fileSize <= 0) return;
if (fileSize <= 0) return "failed to read stat file";
sysBlockStat[fileSize] = '\0';
if (sscanf(sysBlockStat, "%" PRIu64 "%*u%" PRIu64 "%*u%" PRIu64 "%*u%" PRIu64 "%*u", &nRead, &sectorRead, &nWritten, &sectorWritten) <= 0)
return;
return "invalid stat file format";
}
FFDiskIOResult* device = (FFDiskIOResult*) ffListAdd(result);
@@ -70,6 +70,8 @@ static void parseDiskIOCounters(int dfd, const char* devName, FFlist* result, FF
device->bytesWritten = sectorWritten * 512;
device->readCount = nRead;
device->writeCount = nWritten;
return NULL;
}
const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
@@ -83,7 +85,7 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
{
const char* const devName = sysBlockEntry->d_name;
if (devName[0] == '.') continue;;
if (devName[0] == '.') continue;
FF_AUTO_CLOSE_FD int dfd = openat(dirfd(sysBlockDirp), devName, O_RDONLY | O_CLOEXEC | O_PATH | O_DIRECTORY);
if (dfd > 0) parseDiskIOCounters(dfd, devName, result, options);
+3 -3
View File
@@ -12,12 +12,12 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
if (sysctl(mib, ARRAY_SIZE(mib), NULL, &len, NULL, 0) < 0)
return "sysctl({HW_IOSTATS}, NULL) failed";
uint32_t nDrive = (uint32_t) (len / sizeof(struct io_sysctl));
struct io_sysctl* stats = malloc(len);
FF_AUTO_FREE struct io_sysctl* stats = malloc(len);
if (sysctl(mib, ARRAY_SIZE(mib), stats, &len, NULL, 0) < 0)
return "sysctl({HW_IOSTATS}, stats) failed";
for (uint32_t i = 0; i < nDrive; ++i)
{
struct io_sysctl* st = &stats[i];
+1 -1
View File
@@ -13,7 +13,7 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
return "sysctl({HW_DISKSTATS}, NULL) failed";
uint32_t nDrive = (uint32_t) (len / sizeof(struct diskstats));
struct diskstats* stats = malloc(len);
FF_AUTO_FREE struct diskstats* stats = malloc(len);
if (sysctl(mib, ARRAY_SIZE(mib), stats, &len, NULL, 0) < 0)
return "sysctl({HW_DISKSTATS}, stats) failed";
+1 -1
View File
@@ -27,7 +27,7 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
continue;
FFDiskIOResult* device = (FFDiskIOResult*) ffListAdd(result);
ffStrbufInit(&device->devPath);
ffStrbufInit(&device->devPath); // unlike other platforms, `/dev/ks_name` is not available
ffStrbufInitS(&device->name, ks->ks_name);
device->bytesRead = kio.nread;
device->readCount = kio.reads;
+2 -2
View File
@@ -56,8 +56,6 @@ static bool detectPhysicalDisk(const wchar_t* szDevice, FFlist* result, FFDiskIO
return true;
}
ffStrbufInitWS(&device->devPath, szDevice);
DISK_PERFORMANCE dp = {};
if (DeviceIoControl(hDevice, IOCTL_DISK_PERFORMANCE, NULL, 0, &dp, sizeof(dp), &retSize, NULL))
{
@@ -72,6 +70,8 @@ static bool detectPhysicalDisk(const wchar_t* szDevice, FFlist* result, FFDiskIO
result->length--;
}
ffStrbufInitWS(&device->devPath, szDevice);
return true;
}
@@ -4,6 +4,33 @@
#include <math.h>
static bool checkHdrStatus(FFDisplayResult* display)
{
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
if (ffSettingsGetAndroidProperty("ro.surface_flinger.has_HDR_display", &buffer))
{
if (ffStrbufIgnCaseEqualS(&buffer, "true"))
{
display->hdrStatus = FF_DISPLAY_HDR_STATUS_SUPPORTED;
if (ffSettingsGetAndroidProperty("persist.sys.hdr_mode", &buffer) &&
ffStrbufToUInt(&buffer, 0) > 0)
display->hdrStatus = FF_DISPLAY_HDR_STATUS_ENABLED;
return true;
}
else
{
display->hdrStatus = FF_DISPLAY_HDR_STATUS_UNSUPPORTED;
return true;
}
}
display->hdrStatus = FF_DISPLAY_HDR_STATUS_UNKNOWN;
return false;
}
static void detectWithDumpsys(FFDisplayServerResult* ds)
{
FF_STRBUF_AUTO_DESTROY buf = ffStrbufCreate();
@@ -54,7 +81,7 @@ static void detectWithDumpsys(FFDisplayServerResult* ds)
}
ffStrbufRecalculateLength(&name);
ffdsAppendDisplay(ds,
FFDisplayResult* display = ffdsAppendDisplay(ds,
(uint32_t)width,
(uint32_t)height,
refreshRate,
@@ -72,6 +99,7 @@ static void detectWithDumpsys(FFDisplayServerResult* ds)
0,
"dumpsys"
);
if (display) display->hdrStatus = checkHdrStatus(display);
}
index = nextIndex + 1;
@@ -92,7 +120,7 @@ static bool detectWithGetprop(FFDisplayServerResult* ds)
uint32_t height = (uint32_t) ffStrbufToUInt(&buffer, 0);
ffStrbufSubstrAfterFirstC(&buffer, ',');
double scaleFactor = (double) ffStrbufToUInt(&buffer, 0) / 160.;
return ffdsAppendDisplay(ds,
FFDisplayResult* display = ffdsAppendDisplay(ds,
width,
height,
0,
@@ -110,6 +138,8 @@ static bool detectWithGetprop(FFDisplayServerResult* ds)
0,
"getprop"
);
if (display) display->hdrStatus = checkHdrStatus(display);
return !!display;
}
return false;
@@ -68,7 +68,7 @@ static void detectDisplays(FFDisplayServerResult* ds)
if(displayInfo)
{
CFDictionaryRef productNames;
if(!ffCfDictGetDict(displayInfo, CFSTR(kDisplayProductName), &productNames))
if(ffCfDictGetDict(displayInfo, CFSTR(kDisplayProductName), &productNames) == NULL)
ffCfDictGetString(productNames, CFSTR("en_US"), &buffer);
// CGDisplayScreenSize reports invalid result for external displays on old Intel MacBook Pro
@@ -273,7 +273,7 @@ const char* ffdsConnectWayland(FFDisplayServerResult* result)
FF_LIST_FOR_EACH(FFstrbuf, basePath, instance.state.platform.configDirs)
{
char path[1024];
snprintf(path, ARRAY_SIZE(path) - 1, "%s%s", basePath->chars, fileName);
snprintf(path, ARRAY_SIZE(path), "%s%s", basePath->chars, fileName);
if (ffReadFileBuffer(path, &monitorsXml))
break;
}
+1 -1
View File
@@ -374,7 +374,7 @@ static const char* getFromProcesses(FFDisplayServerResult* result)
ffStrbufAppendS(&procPath, dirent->d_name);
uint32_t procFolderPathLength = procPath.length;
//Don't check for processes not owend by the current user.
//Don't check for processes not owned by the current user.
ffStrbufAppendS(&procPath, "/loginuid");
ffReadFileBuffer(procPath.chars, &loginuid);
if(ffStrbufToUInt(&loginuid, (uint64_t) -1) != userId)
+2 -2
View File
@@ -333,7 +333,7 @@ static void xcbRandrHandleScreen(XcbRandrData* data, xcb_screen_t* screen)
const char* ffdsConnectXcbRandr(FFDisplayServerResult* result)
{
FF_LIBRARY_LOAD(xcbRandr, "dlopen lbxcb-randr failed", "libxcb-randr" FF_LIBRARY_EXTENSION, 1)
FF_LIBRARY_LOAD(xcbRandr, "dlopen libxcb-randr failed", "libxcb-randr" FF_LIBRARY_EXTENSION, 1)
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(xcbRandr, xcb_connect)
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(xcbRandr, xcb_get_setup)
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(xcbRandr, xcb_setup_roots_iterator)
@@ -369,7 +369,7 @@ const char* ffdsConnectXcbRandr(FFDisplayServerResult* result)
data.connection = ffxcb_connect(NULL, NULL);
if(data.connection == NULL)
return "xcb_connect failed";
return "xcb_connect() failed";
data.result = result;
+3 -3
View File
@@ -147,7 +147,7 @@ static bool xrandrHandleCrtc(XrandrData* data, XRROutputInfo* output, FFstrbuf*
"xlib-randr-crtc"
);
if (edidLength)
if (item && edidLength)
{
item->hdrStatus = ffEdidGetHdrCompatible(edidData, edidLength) ? FF_DISPLAY_HDR_STATUS_SUPPORTED : FF_DISPLAY_HDR_STATUS_UNSUPPORTED;
ffEdidGetSerialAndManufactureDate(edidData, &item->serial, &item->manufactureYear, &item->manufactureWeek);
@@ -231,7 +231,7 @@ static bool xrandrHandleMonitors(XrandrData* data, Screen* screen)
if(monitorInfos == NULL)
return false;
bool foundAMonitor;
bool foundAMonitor = false;
for(int i = 0; i < numberOfMonitors; i++)
{
@@ -272,7 +272,7 @@ static void xrandrHandleScreen(XrandrData* data, Screen* screen)
0,
(uint32_t) WidthMMOfScreen(screen),
(uint32_t) HeightMMOfScreen(screen),
"xlib_randr_screen"
"xlib-randr-screen"
);
}
+1 -1
View File
@@ -14,7 +14,7 @@ const char* ffDetectDNS(FFDNSOptions* options, FFlist* results)
{
FF_AUTO_CLOSE_FILE FILE* file = fopen(FASTFETCH_TARGET_DIR_ROOT RESOLV_CONF, "r");
if (!file)
return "fopen (" FASTFETCH_TARGET_DIR_ROOT "/etc/resolv.conf) failed";
return "fopen (" FASTFETCH_TARGET_DIR_ROOT RESOLV_CONF ") failed";
FF_AUTO_FREE char* line = NULL;
size_t len = 0;
+1
View File
@@ -10,6 +10,7 @@
#ifdef _WIN32
static inline char* realpath(const char* restrict file_name, char* restrict resolved_name)
{
assert(resolved_name != NULL);
return _fullpath(resolved_name, file_name, _MAX_PATH);
}
#endif
+1 -1
View File
@@ -72,7 +72,7 @@ const char* ffDetectHost(FFHostResult* host)
ffCleanUpSmbiosValue(&host->family);
}
#if _WIN32 && __x86_64__
#if _WIN64
ffHostDetectMac(host);
#endif