Skip to content

Commit 5d10fa9

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

File tree

15 files changed

+62
-24
lines changed

15 files changed

+62
-24
lines changed

src/detection/diskio/diskio.c

Lines changed: 5 additions & 0 deletions
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

Lines changed: 7 additions & 5 deletions
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,7 +49,7 @@ 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 ...
@@ -60,7 +60,7 @@ static void parseDiskIOCounters(int dfd, const char* devName, FFlist* result, FF
6060
if (fileSize <= 0) return;
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 32 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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)

0 commit comments

Comments
 (0)