Skip to content

Commit b257134

Browse files
committed
Chore: introduce macro ARRAY_SIZE
1 parent 5497cb6 commit b257134

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+142
-135
lines changed

src/common/format.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ typedef struct FFformatarg
4343
void ffFormatAppendFormatArg(FFstrbuf* buffer, const FFformatarg* formatarg);
4444
void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, uint32_t numArgs, const FFformatarg* arguments);
4545
#define FF_PARSE_FORMAT_STRING_CHECKED(buffer, formatstr, numArgs, arguments) do {\
46-
static_assert(sizeof(arguments) / sizeof(*(arguments)) == (numArgs), "Invalid number of format arguments");\
46+
static_assert(sizeof(arguments) / sizeof(*arguments) == (numArgs), "Invalid number of format arguments");\
4747
ffParseFormatString((buffer), (formatstr), (numArgs), (arguments));\
4848
} while (0)

src/common/printing.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ typedef enum FFPrintType {
1414
void ffPrintLogoAndKey(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFPrintType printType);
1515
void ffPrintFormat(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFPrintType printType, uint32_t numArgs, const FFformatarg* arguments);
1616
#define FF_PRINT_FORMAT_CHECKED(moduleName, moduleIndex, moduleArgs, printType, numArgs, arguments) do {\
17-
static_assert(sizeof(arguments) / sizeof(*(arguments)) == (numArgs), "Invalid number of format arguments");\
17+
static_assert(sizeof(arguments) / sizeof(*arguments) == (numArgs), "Invalid number of format arguments");\
1818
ffPrintFormat((moduleName), (moduleIndex), (moduleArgs), (printType), (numArgs), (arguments));\
1919
} while (0)
2020
FF_C_PRINTF(5, 6) void ffPrintError(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFPrintType printType, const char* message, ...);
@@ -23,6 +23,6 @@ void ffPrintCharTimes(char c, uint32_t times);
2323

2424
void ffPrintModuleFormatHelp(const char* name, const char* def, uint32_t numArgs, const char* args[]);
2525
#define FF_PRINT_MODULE_FORMAT_HELP_CHECKED(moduleName, def, numArgs, args) do {\
26-
static_assert(sizeof(args) / sizeof(*(args)) == (numArgs), "Invalid number of format arguments");\
26+
static_assert(sizeof(args) / sizeof(*args) == (numArgs), "Invalid number of format arguments");\
2727
ffPrintModuleFormatHelp((moduleName), (def), (numArgs), (args));\
2828
} while (0)

src/common/processing_linux.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,14 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons
153153

154154
size_t len = 0;
155155
int mibs[] = { CTL_KERN, KERN_PROCARGS2, pid };
156-
if (sysctl(mibs, sizeof(mibs) / sizeof(*mibs), NULL, &len, NULL, 0) == 0)
156+
if (sysctl(mibs, ARRAY_SIZE(mibs), NULL, &len, NULL, 0) == 0)
157157
{// try get arg0
158158
#ifndef MAC_OS_X_VERSION_10_15
159159
//don't know why if don't let len longer, proArgs2 and len will change during the following sysctl() in old MacOS version.
160160
len++;
161161
#endif
162162
FF_AUTO_FREE char* const procArgs2 = malloc(len);
163-
if (sysctl(mibs, sizeof(mibs) / sizeof(*mibs), procArgs2, &len, NULL, 0) == 0)
163+
if (sysctl(mibs, ARRAY_SIZE(mibs), procArgs2, &len, NULL, 0) == 0)
164164
{
165165
// https://gist.github.com/nonowarn/770696#file-getargv-c-L46
166166
uint32_t argc = *(uint32_t*) procArgs2;

src/common/processing_windows.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const char* ffProcessAppendOutput(FFstrbuf* buffer, char* const argv[], bool use
5050
int timeout = instance.config.general.processingTimeout;
5151

5252
wchar_t pipeName[32];
53-
swprintf(pipeName, sizeof(pipeName) / sizeof(*pipeName), L"\\\\.\\pipe\\FASTFETCH-%u", GetCurrentProcessId());
53+
swprintf(pipeName, ARRAY_SIZE(pipeName), L"\\\\.\\pipe\\FASTFETCH-%u", GetCurrentProcessId());
5454

5555
FF_AUTO_CLOSE_FD HANDLE hChildPipeRead = CreateNamedPipeW(
5656
pipeName,

src/common/properties.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ bool ffParsePropFileValues(const char* filename, uint32_t numQueries, FFpropquer
100100
bool valueStorage[32];
101101
bool* unsetValues = valueStorage;
102102

103-
if (numQueries > sizeof(valueStorage) / sizeof(valueStorage[0]))
103+
if (numQueries > ARRAY_SIZE(valueStorage))
104104
unsetValues = malloc(sizeof(bool) * numQueries);
105105

106106
bool allSet = true;

src/detection/bootmgr/bootmgr_windows.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ const char* ffDetectBootmgr(FFBootmgrResult* result)
3838

3939
uint8_t buffer[2048];
4040
wchar_t key[16];
41-
swprintf(key, sizeof(key) / sizeof(*key), L"Boot%04X", value);
41+
swprintf(key, ARRAY_SIZE(key), L"Boot%04X", value);
4242
uint32_t size = GetFirmwareEnvironmentVariableW(key, L"{" FF_EFI_GLOBAL_GUID L"}", buffer, sizeof(buffer));
43-
if (size < sizeof(FFEfiLoadOption) || size == sizeof(buffer))
43+
if (size < sizeof(FFEfiLoadOption) || size == ARRAY_SIZE(buffer))
4444
return "GetFirmwareEnvironmentVariableW(Boot####) failed";
4545

4646
ffEfiFillLoadOption((FFEfiLoadOption *)buffer, result);

src/detection/brightness/brightness_apple.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ static const char* detectWithDdcci(FF_MAYBE_UNUSED const FFDisplayServerResult*
9292

9393
for (uint32_t i = 0; i < 2; ++i)
9494
{
95-
IOAVServiceWriteI2C(service, 0x37, 0x51, i2cIn, sizeof(i2cIn));
95+
IOAVServiceWriteI2C(service, 0x37, 0x51, i2cIn, ARRAY_SIZE(i2cIn));
9696
usleep(options->ddcciSleep * 1000);
9797
}
9898
}
9999

100100
uint8_t i2cOut[12] = {};
101-
if (IOAVServiceReadI2C(service, 0x37, 0x51, i2cOut, sizeof(i2cOut)) == KERN_SUCCESS)
101+
if (IOAVServiceReadI2C(service, 0x37, 0x51, i2cOut, ARRAY_SIZE(i2cOut)) == KERN_SUCCESS)
102102
{
103103
if (i2cOut[2] != 0x02 || i2cOut[3] != 0x00)
104104
continue;
@@ -113,7 +113,7 @@ static const char* detectWithDdcci(FF_MAYBE_UNUSED const FFDisplayServerResult*
113113
ffStrbufInit(&brightness->name);
114114

115115
uint8_t edid[128] = {};
116-
if (IOAVServiceReadI2C(service, 0x50, 0x00, edid, sizeof(edid)) == KERN_SUCCESS)
116+
if (IOAVServiceReadI2C(service, 0x50, 0x00, edid, ARRAY_SIZE(edid)) == KERN_SUCCESS)
117117
ffEdidGetName(edid, &brightness->name);
118118
}
119119
}
@@ -155,12 +155,12 @@ static const char* detectWithDdcci(const FFDisplayServerResult* displayServer, F
155155
.sendAddress = 0x6e,
156156
.sendTransactionType = kIOI2CSimpleTransactionType,
157157
.sendBuffer = (vm_address_t) i2cIn,
158-
.sendBytes = sizeof(i2cIn) / sizeof(i2cIn[0]),
158+
.sendBytes = ARRAY_SIZE(i2cIn),
159159
.minReplyDelay = options->ddcciSleep,
160160
.replyAddress = 0x6F,
161161
.replySubAddress = 0x51,
162162
.replyTransactionType = kIOI2CDDCciReplyTransactionType,
163-
.replyBytes = sizeof(i2cOut) / sizeof(i2cOut[0]),
163+
.replyBytes = ARRAY_SIZE(i2cOut),
164164
.replyBuffer = (vm_address_t) i2cOut,
165165
};
166166
IOReturn ret = IOI2CSendRequest(connect, kNilOptions, &request);

src/detection/brightness/brightness_bsd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const char* ffDetectBrightness(FF_MAYBE_UNUSED FFBrightnessOptions* options, FFl
1616

1717
for (char i = '0'; i <= '9'; ++i)
1818
{
19-
path[sizeof(path) - 2] = i;
19+
path[ARRAY_SIZE(path) - 2] = i;
2020

2121
FF_AUTO_CLOSE_FD int blfd = open(path, O_RDONLY | O_CLOEXEC);
2222
if (blfd < 0)

src/detection/brightness/brightness_linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static const char* detectWithBacklight(FFlist* result)
4848
// if we managed to get edid, use it
4949
ffStrbufAppendS(&brightness->name, "/edid");
5050
uint8_t edidData[128];
51-
if(ffReadFileData(brightness->name.chars, sizeof(edidData), edidData) == sizeof(edidData))
51+
if(ffReadFileData(brightness->name.chars, ARRAY_SIZE(edidData), edidData) == ARRAY_SIZE(edidData))
5252
{
5353
ffStrbufClear(&brightness->name);
5454
ffEdidGetName(edidData, &brightness->name);

src/detection/btrfs/btrfs_linux.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ static const char* enumerateDevices(FFBtrfsResult* item, int dfd, FFstrbuf* buff
2424
ffStrbufAppendC(&item->devices, ',');
2525
ffStrbufAppendS(&item->devices, entry->d_name);
2626

27-
char path[sizeof(entry->d_name) + sizeof("/size") + 1];
28-
snprintf(path, sizeof(path), "%s/size", entry->d_name);
27+
char path[ARRAY_SIZE(entry->d_name) + ARRAY_SIZE("/size") + 1];
28+
snprintf(path, ARRAY_SIZE(path), "%s/size", entry->d_name);
2929

3030
if (ffReadFileBufferRelative(subfd, path, buffer))
3131
item->totalSize += ffStrbufToUInt(buffer, 0) * 512;

0 commit comments

Comments
 (0)