Skip to content

Commit de5ef38

Browse files
committed
Global: fix code smells
1 parent 1129ed9 commit de5ef38

15 files changed

+63
-25
lines changed

src/detection/diskio/diskio.c

+5
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,15 @@ const char* ffDetectDiskIO(FFlist* result, FFDiskIOOptions* options)
6969
uint64_t temp = *currValue;
7070
*currValue -= *prevValue;
7171
*currValue /= (time2 - time1) / 1000 /* seconds */;
72+
73+
// For next function call
7274
*prevValue = temp;
7375
}
7476
}
77+
78+
// For next function call
7579
time1 = time2;
80+
// Leak ioCounters1 here
7681

7782
return NULL;
7883
}

src/detection/diskio/diskio_linux.c

+8-6
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
#include <inttypes.h>
99
#include <fcntl.h>
1010

11-
static void parseDiskIOCounters(int dfd, const char* devName, FFlist* result, FFDiskIOOptions* options)
11+
static const char* parseDiskIOCounters(int dfd, const char* devName, FFlist* result, FFDiskIOOptions* options)
1212
{
1313
FF_AUTO_CLOSE_FD int devfd = openat(dfd, "device", O_RDONLY | O_CLOEXEC | O_PATH | O_DIRECTORY);
14-
if (devfd < 0) return; // virtual device
14+
if (devfd < 0) return "virtual device";
1515

1616
FF_STRBUF_AUTO_DESTROY name = ffStrbufCreate();
1717

@@ -49,18 +49,18 @@ static void parseDiskIOCounters(int dfd, const char* devName, FFlist* result, FF
4949
}
5050

5151
if (options->namePrefix.length && !ffStrbufStartsWith(&name, &options->namePrefix))
52-
return;
52+
return "ignored";
5353
}
5454

5555
// I/Os merges sectors ticks ...
5656
uint64_t nRead, sectorRead, nWritten, sectorWritten;
5757
{
5858
char sysBlockStat[PROC_FILE_BUFFSIZ];
5959
ssize_t fileSize = ffReadFileDataRelative(dfd, "stat", ARRAY_SIZE(sysBlockStat) - 1, sysBlockStat);
60-
if (fileSize <= 0) return;
60+
if (fileSize <= 0) return "failed to read stat file";
6161
sysBlockStat[fileSize] = '\0';
6262
if (sscanf(sysBlockStat, "%" PRIu64 "%*u%" PRIu64 "%*u%" PRIu64 "%*u%" PRIu64 "%*u", &nRead, &sectorRead, &nWritten, &sectorWritten) <= 0)
63-
return;
63+
return "invalid stat file format";
6464
}
6565

6666
FFDiskIOResult* device = (FFDiskIOResult*) ffListAdd(result);
@@ -70,6 +70,8 @@ static void parseDiskIOCounters(int dfd, const char* devName, FFlist* result, FF
7070
device->bytesWritten = sectorWritten * 512;
7171
device->readCount = nRead;
7272
device->writeCount = nWritten;
73+
74+
return NULL;
7375
}
7476

7577
const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
@@ -83,7 +85,7 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
8385
{
8486
const char* const devName = sysBlockEntry->d_name;
8587

86-
if (devName[0] == '.') continue;;
88+
if (devName[0] == '.') continue;
8789

8890
FF_AUTO_CLOSE_FD int dfd = openat(dirfd(sysBlockDirp), devName, O_RDONLY | O_CLOEXEC | O_PATH | O_DIRECTORY);
8991
if (dfd > 0) parseDiskIOCounters(dfd, devName, result, options);

src/detection/diskio/diskio_nbsd.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
1212
if (sysctl(mib, ARRAY_SIZE(mib), NULL, &len, NULL, 0) < 0)
1313
return "sysctl({HW_IOSTATS}, NULL) failed";
1414
uint32_t nDrive = (uint32_t) (len / sizeof(struct io_sysctl));
15-
16-
struct io_sysctl* stats = malloc(len);
15+
16+
FF_AUTO_FREE struct io_sysctl* stats = malloc(len);
1717

1818
if (sysctl(mib, ARRAY_SIZE(mib), stats, &len, NULL, 0) < 0)
1919
return "sysctl({HW_IOSTATS}, stats) failed";
20-
20+
2121
for (uint32_t i = 0; i < nDrive; ++i)
2222
{
2323
struct io_sysctl* st = &stats[i];

src/detection/diskio/diskio_obsd.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
1313
return "sysctl({HW_DISKSTATS}, NULL) failed";
1414
uint32_t nDrive = (uint32_t) (len / sizeof(struct diskstats));
1515

16-
struct diskstats* stats = malloc(len);
16+
FF_AUTO_FREE struct diskstats* stats = malloc(len);
1717

1818
if (sysctl(mib, ARRAY_SIZE(mib), stats, &len, NULL, 0) < 0)
1919
return "sysctl({HW_DISKSTATS}, stats) failed";

src/detection/diskio/diskio_sunos.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
2727
continue;
2828

2929
FFDiskIOResult* device = (FFDiskIOResult*) ffListAdd(result);
30-
ffStrbufInit(&device->devPath);
30+
ffStrbufInit(&device->devPath); // unlike other platforms, `/dev/ks_name` is not available
3131
ffStrbufInitS(&device->name, ks->ks_name);
3232
device->bytesRead = kio.nread;
3333
device->readCount = kio.reads;

src/detection/diskio/diskio_windows.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ static bool detectPhysicalDisk(const wchar_t* szDevice, FFlist* result, FFDiskIO
5656
return true;
5757
}
5858

59-
ffStrbufInitWS(&device->devPath, szDevice);
60-
6159
DISK_PERFORMANCE dp = {};
6260
if (DeviceIoControl(hDevice, IOCTL_DISK_PERFORMANCE, NULL, 0, &dp, sizeof(dp), &retSize, NULL))
6361
{
@@ -72,6 +70,8 @@ static bool detectPhysicalDisk(const wchar_t* szDevice, FFlist* result, FFDiskIO
7270
result->length--;
7371
}
7472

73+
ffStrbufInitWS(&device->devPath, szDevice);
74+
7575
return true;
7676
}
7777

src/detection/displayserver/displayserver_android.c

+32-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,33 @@
44

55
#include <math.h>
66

7+
static bool checkHdrStatus(FFDisplayResult* display)
8+
{
9+
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
10+
11+
if (ffSettingsGetAndroidProperty("ro.surface_flinger.has_HDR_display", &buffer))
12+
{
13+
if (ffStrbufIgnCaseEqualS(&buffer, "true"))
14+
{
15+
display->hdrStatus = FF_DISPLAY_HDR_STATUS_SUPPORTED;
16+
17+
if (ffSettingsGetAndroidProperty("persist.sys.hdr_mode", &buffer) &&
18+
ffStrbufToUInt(&buffer, 0) > 0)
19+
display->hdrStatus = FF_DISPLAY_HDR_STATUS_ENABLED;
20+
21+
return true;
22+
}
23+
else
24+
{
25+
display->hdrStatus = FF_DISPLAY_HDR_STATUS_UNSUPPORTED;
26+
return true;
27+
}
28+
}
29+
30+
display->hdrStatus = FF_DISPLAY_HDR_STATUS_UNKNOWN;
31+
return false;
32+
}
33+
734
static void detectWithDumpsys(FFDisplayServerResult* ds)
835
{
936
FF_STRBUF_AUTO_DESTROY buf = ffStrbufCreate();
@@ -54,7 +81,7 @@ static void detectWithDumpsys(FFDisplayServerResult* ds)
5481
}
5582

5683
ffStrbufRecalculateLength(&name);
57-
ffdsAppendDisplay(ds,
84+
FFDisplayResult* display = ffdsAppendDisplay(ds,
5885
(uint32_t)width,
5986
(uint32_t)height,
6087
refreshRate,
@@ -72,6 +99,7 @@ static void detectWithDumpsys(FFDisplayServerResult* ds)
7299
0,
73100
"dumpsys"
74101
);
102+
if (display) display->hdrStatus = checkHdrStatus(display);
75103
}
76104

77105
index = nextIndex + 1;
@@ -92,7 +120,7 @@ static bool detectWithGetprop(FFDisplayServerResult* ds)
92120
uint32_t height = (uint32_t) ffStrbufToUInt(&buffer, 0);
93121
ffStrbufSubstrAfterFirstC(&buffer, ',');
94122
double scaleFactor = (double) ffStrbufToUInt(&buffer, 0) / 160.;
95-
return ffdsAppendDisplay(ds,
123+
FFDisplayResult* display = ffdsAppendDisplay(ds,
96124
width,
97125
height,
98126
0,
@@ -110,6 +138,8 @@ static bool detectWithGetprop(FFDisplayServerResult* ds)
110138
0,
111139
"getprop"
112140
);
141+
if (display) display->hdrStatus = checkHdrStatus(display);
142+
return !!display;
113143
}
114144

115145
return false;

src/detection/displayserver/displayserver_apple.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static void detectDisplays(FFDisplayServerResult* ds)
6868
if(displayInfo)
6969
{
7070
CFDictionaryRef productNames;
71-
if(!ffCfDictGetDict(displayInfo, CFSTR(kDisplayProductName), &productNames))
71+
if(ffCfDictGetDict(displayInfo, CFSTR(kDisplayProductName), &productNames) == NULL)
7272
ffCfDictGetString(productNames, CFSTR("en_US"), &buffer);
7373

7474
// CGDisplayScreenSize reports invalid result for external displays on old Intel MacBook Pro

src/detection/displayserver/linux/wayland/wayland.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ const char* ffdsConnectWayland(FFDisplayServerResult* result)
273273
FF_LIST_FOR_EACH(FFstrbuf, basePath, instance.state.platform.configDirs)
274274
{
275275
char path[1024];
276-
snprintf(path, ARRAY_SIZE(path) - 1, "%s%s", basePath->chars, fileName);
276+
snprintf(path, ARRAY_SIZE(path), "%s%s", basePath->chars, fileName);
277277
if (ffReadFileBuffer(path, &monitorsXml))
278278
break;
279279
}

src/detection/displayserver/linux/wmde.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ static const char* getFromProcesses(FFDisplayServerResult* result)
374374
ffStrbufAppendS(&procPath, dirent->d_name);
375375
uint32_t procFolderPathLength = procPath.length;
376376

377-
//Don't check for processes not owend by the current user.
377+
//Don't check for processes not owned by the current user.
378378
ffStrbufAppendS(&procPath, "/loginuid");
379379
ffReadFileBuffer(procPath.chars, &loginuid);
380380
if(ffStrbufToUInt(&loginuid, (uint64_t) -1) != userId)

src/detection/displayserver/linux/xcb.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ static void xcbRandrHandleScreen(XcbRandrData* data, xcb_screen_t* screen)
333333

334334
const char* ffdsConnectXcbRandr(FFDisplayServerResult* result)
335335
{
336-
FF_LIBRARY_LOAD(xcbRandr, "dlopen lbxcb-randr failed", "libxcb-randr" FF_LIBRARY_EXTENSION, 1)
336+
FF_LIBRARY_LOAD(xcbRandr, "dlopen libxcb-randr failed", "libxcb-randr" FF_LIBRARY_EXTENSION, 1)
337337
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(xcbRandr, xcb_connect)
338338
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(xcbRandr, xcb_get_setup)
339339
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(xcbRandr, xcb_setup_roots_iterator)
@@ -369,7 +369,7 @@ const char* ffdsConnectXcbRandr(FFDisplayServerResult* result)
369369

370370
data.connection = ffxcb_connect(NULL, NULL);
371371
if(data.connection == NULL)
372-
return "xcb_connect failed";
372+
return "xcb_connect() failed";
373373

374374

375375
data.result = result;

src/detection/displayserver/linux/xlib.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ static bool xrandrHandleCrtc(XrandrData* data, XRROutputInfo* output, FFstrbuf*
147147
"xlib-randr-crtc"
148148
);
149149

150-
if (edidLength)
150+
if (item && edidLength)
151151
{
152152
item->hdrStatus = ffEdidGetHdrCompatible(edidData, edidLength) ? FF_DISPLAY_HDR_STATUS_SUPPORTED : FF_DISPLAY_HDR_STATUS_UNSUPPORTED;
153153
ffEdidGetSerialAndManufactureDate(edidData, &item->serial, &item->manufactureYear, &item->manufactureWeek);
@@ -231,7 +231,7 @@ static bool xrandrHandleMonitors(XrandrData* data, Screen* screen)
231231
if(monitorInfos == NULL)
232232
return false;
233233

234-
bool foundAMonitor;
234+
bool foundAMonitor = false;
235235

236236
for(int i = 0; i < numberOfMonitors; i++)
237237
{
@@ -272,7 +272,7 @@ static void xrandrHandleScreen(XrandrData* data, Screen* screen)
272272
0,
273273
(uint32_t) WidthMMOfScreen(screen),
274274
(uint32_t) HeightMMOfScreen(screen),
275-
"xlib_randr_screen"
275+
"xlib-randr-screen"
276276
);
277277
}
278278

src/detection/dns/dns_linux.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const char* ffDetectDNS(FFDNSOptions* options, FFlist* results)
1414
{
1515
FF_AUTO_CLOSE_FILE FILE* file = fopen(FASTFETCH_TARGET_DIR_ROOT RESOLV_CONF, "r");
1616
if (!file)
17-
return "fopen (" FASTFETCH_TARGET_DIR_ROOT "/etc/resolv.conf) failed";
17+
return "fopen (" FASTFETCH_TARGET_DIR_ROOT RESOLV_CONF ") failed";
1818

1919
FF_AUTO_FREE char* line = NULL;
2020
size_t len = 0;

src/detection/editor/editor.c

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#ifdef _WIN32
1111
static inline char* realpath(const char* restrict file_name, char* restrict resolved_name)
1212
{
13+
assert(resolved_name != NULL);
1314
return _fullpath(resolved_name, file_name, _MAX_PATH);
1415
}
1516
#endif

src/detection/host/host_windows.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const char* ffDetectHost(FFHostResult* host)
7272
ffCleanUpSmbiosValue(&host->family);
7373
}
7474

75-
#if _WIN32 && __x86_64__
75+
#if _WIN64
7676
ffHostDetectMac(host);
7777
#endif
7878

0 commit comments

Comments
 (0)