Skip to content

Commit 7c8250c

Browse files
committed
StringUtil: rename ffStrCopy and correctly reflect its usage
1 parent c368908 commit 7c8250c

File tree

7 files changed

+21
-21
lines changed

7 files changed

+21
-21
lines changed

src/detection/cpucache/cpucache_apple.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,35 @@ const char* ffDetectCPUCache(FFCPUCacheResult* result)
2020
{
2121
*pNum = (char) ('0' + i);
2222

23-
ffStrCopyN(pSubkey, "physicalcpu", lenLeft);
23+
ffStrCopy(pSubkey, "physicalcpu", lenLeft);
2424
uint32_t ncpu = (uint32_t) ffSysctlGetInt(sysctlKey, 0);
2525
if (ncpu <= 0) continue;
2626

27-
ffStrCopyN(pSubkey, "l1icachesize", lenLeft);
27+
ffStrCopy(pSubkey, "l1icachesize", lenLeft);
2828
uint32_t size = (uint32_t) ffSysctlGetInt(sysctlKey, 0);
2929
if (size)
3030
ffCPUCacheAddItem(result, 1, size, lineSize, FF_CPU_CACHE_TYPE_INSTRUCTION)->num = ncpu;
3131

32-
ffStrCopyN(pSubkey, "l1dcachesize", lenLeft);
32+
ffStrCopy(pSubkey, "l1dcachesize", lenLeft);
3333
size = (uint32_t) ffSysctlGetInt(sysctlKey, 0);
3434
if (size)
3535
ffCPUCacheAddItem(result, 1, size, lineSize, FF_CPU_CACHE_TYPE_DATA)->num = ncpu;
3636

37-
ffStrCopyN(pSubkey, "l2cachesize", lenLeft);
37+
ffStrCopy(pSubkey, "l2cachesize", lenLeft);
3838
size = (uint32_t) ffSysctlGetInt(sysctlKey, 0);
3939
if (size)
4040
{
41-
ffStrCopyN(pSubkey, "cpusperl2", lenLeft);
41+
ffStrCopy(pSubkey, "cpusperl2", lenLeft);
4242
uint32_t cpuSper = (uint32_t) ffSysctlGetInt(sysctlKey, 0);
4343
if (cpuSper)
4444
ffCPUCacheAddItem(result, 2, size, lineSize, FF_CPU_CACHE_TYPE_UNIFIED)->num = ncpu / cpuSper;
4545
}
4646

47-
ffStrCopyN(pSubkey, "l3cachesize", lenLeft);
47+
ffStrCopy(pSubkey, "l3cachesize", lenLeft);
4848
size = (uint32_t) ffSysctlGetInt(sysctlKey, 0);
4949
if (size)
5050
{
51-
ffStrCopyN(pSubkey, "cpusperl3", lenLeft);
51+
ffStrCopy(pSubkey, "cpusperl3", lenLeft);
5252
uint32_t cpuSper = (uint32_t) ffSysctlGetInt(sysctlKey, 0);
5353
if (cpuSper)
5454
ffCPUCacheAddItem(result, 3, size, lineSize, FF_CPU_CACHE_TYPE_UNIFIED)->num = ncpu / cpuSper;

src/detection/gpu/gpu_linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ static const char* detectPci(const FFGPUOptions* options, FFlist* gpus, FFstrbuf
460460
{
461461
if (ffStrStartsWith(entry->d_name, "card"))
462462
{
463-
ffStrCopyN(drmKeyBuffer, entry->d_name, ARRAY_SIZE(drmKeyBuffer));
463+
ffStrCopy(drmKeyBuffer, entry->d_name, ARRAY_SIZE(drmKeyBuffer));
464464
drmKey = drmKeyBuffer;
465465
break;
466466
}

src/detection/localip/localip_linux.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
231231
FF_LIST_FOR_EACH(FFLocalIpResult, iface, *results)
232232
{
233233
struct ifreq ifr;
234-
ffStrCopyN(ifr.ifr_name, iface->name.chars, IFNAMSIZ);
234+
ffStrCopy(ifr.ifr_name, iface->name.chars, IFNAMSIZ);
235235

236236
if (options->showType & FF_LOCALIP_TYPE_MTU_BIT)
237237
{
@@ -248,7 +248,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
248248
iface->speed = (edata.speed_hi << 16) | edata.speed; // ethtool_cmd_speed is not available on Android
249249
#elif __FreeBSD__ || __APPLE__ || __OpenBSD__ || __NetBSD__
250250
struct ifmediareq ifmr = {};
251-
ffStrCopyN(ifmr.ifm_name, iface->name.chars, IFNAMSIZ);
251+
ffStrCopy(ifmr.ifm_name, iface->name.chars, IFNAMSIZ);
252252
if (ioctl(sockfd, SIOCGIFMEDIA, &ifmr) == 0 && (IFM_TYPE(ifmr.ifm_active) & IFM_ETHER))
253253
{
254254
switch (IFM_SUBTYPE(ifmr.ifm_active))

src/detection/packages/packages_windows.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ static void detectChoco(FF_MAYBE_UNUSED FFPackagesResult* result)
5858
return;
5959

6060
char chocoPath[MAX_PATH + 3];
61-
char* pend = ffStrCopyN(chocoPath, chocoInstall, ARRAY_SIZE(chocoPath));
62-
ffStrCopyN(pend, "/lib/*", ARRAY_SIZE(chocoPath) - (size_t) (pend - chocoPath));
61+
char* pend = ffStrCopy(chocoPath, chocoInstall, ARRAY_SIZE(chocoPath));
62+
ffStrCopy(pend, "/lib/*", ARRAY_SIZE(chocoPath) - (size_t) (pend - chocoPath));
6363
result->choco = getNumElements(chocoPath, FILE_ATTRIBUTE_DIRECTORY, "choco");
6464
}
6565

@@ -71,8 +71,8 @@ static void detectPacman(FFPackagesResult* result)
7171

7272
// MSYS2
7373
char pacmanPath[MAX_PATH + 3];
74-
char* pend = ffStrCopyN(pacmanPath, msystemPrefix, ARRAY_SIZE(pacmanPath));
75-
ffStrCopyN(pend, "/../var/lib/pacman/local/*", ARRAY_SIZE(pacmanPath) - (size_t) (pend - pacmanPath));
74+
char* pend = ffStrCopy(pacmanPath, msystemPrefix, ARRAY_SIZE(pacmanPath));
75+
ffStrCopy(pend, "/../var/lib/pacman/local/*", ARRAY_SIZE(pacmanPath) - (size_t) (pend - pacmanPath));
7676
result->pacman = getNumElements(pacmanPath, FILE_ATTRIBUTE_DIRECTORY, NULL);
7777
}
7878

src/detection/terminalfont/terminalfont_windows.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ static void detectFromWindowsTerminal(const FFstrbuf* terminalExe, FFTerminalFon
9898
if(terminalExe && terminalExe->length > 0 && !ffStrbufEqualS(terminalExe, "Windows Terminal"))
9999
{
100100
char jsonPath[MAX_PATH + 1];
101-
char* pathEnd = ffStrCopyN(jsonPath, terminalExe->chars, ffStrbufLastIndexC(terminalExe, '\\') + 1);
102-
ffStrCopyN(pathEnd, ".portable", ARRAY_SIZE(jsonPath) - (size_t) (pathEnd - jsonPath) - 1);
101+
char* pathEnd = ffStrCopy(jsonPath, terminalExe->chars, ffStrbufLastIndexC(terminalExe, '\\') + 1);
102+
ffStrCopy(pathEnd, ".portable", ARRAY_SIZE(jsonPath) - (size_t) (pathEnd - jsonPath) - 1);
103103

104104
if(ffPathExists(jsonPath, FF_PATHTYPE_ANY))
105105
{
106-
ffStrCopyN(pathEnd, "settings\\settings.json", ARRAY_SIZE(jsonPath) - (size_t) (pathEnd - jsonPath) - 1);
106+
ffStrCopy(pathEnd, "settings\\settings.json", ARRAY_SIZE(jsonPath) - (size_t) (pathEnd - jsonPath) - 1);
107107
if(!ffAppendFileBuffer(jsonPath, &json))
108108
error = "Error reading Windows Terminal portable settings JSON file";
109109
}

src/detection/wifi/wifi_linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ static const char* detectWifiWithIoctls(FFWifiResult* item)
190190
return "socket() failed";
191191

192192
struct iwreq iwr;
193-
ffStrCopyN(iwr.ifr_name, item->inf.description.chars, IFNAMSIZ);
193+
ffStrCopy(iwr.ifr_name, item->inf.description.chars, IFNAMSIZ);
194194
ffStrbufEnsureFree(&item->conn.ssid, IW_ESSID_MAX_SIZE);
195195
iwr.u.essid.pointer = (caddr_t) item->conn.ssid.chars;
196196
iwr.u.essid.length = IW_ESSID_MAX_SIZE + 1;

src/util/stringUtils.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ static inline bool ffCharIsDigit(char c)
8080
return '0' <= c && c <= '9';
8181
}
8282

83-
static inline char* ffStrCopyN(char* __restrict__ dst, const char* __restrict__ src, size_t nDst)
83+
// Copies at most (dstBufSiz - 1) bytes from src to dst; dst is always null-terminated
84+
static inline char* ffStrCopy(char* __restrict__ dst, const char* __restrict__ src, size_t dstBufSiz)
8485
{
85-
assert(dst != NULL);
8686
if (__builtin_expect(dst == NULL, false)) return dst;
8787

88-
size_t len = strnlen(src, nDst - 1);
88+
size_t len = strnlen(src, dstBufSiz - 1);
8989
memcpy(dst, src, len);
9090
dst[len] = '\0';
9191
return dst + len;

0 commit comments

Comments
 (0)