Skip to content

Commit 9a722bf

Browse files
committed
core-builtin: add and use built in shim wrapper for strlen
Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
1 parent e1143d7 commit 9a722bf

45 files changed

Lines changed: 96 additions & 61 deletions

Some content is hidden

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

Makefile.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2642,6 +2642,7 @@ functions: \
26422642
BUILTIN_STRCHR \
26432643
BUILTIN_STRCMP \
26442644
BUILTIN_STRDUP \
2645+
BUILTIN_STRLEN \
26452646
BUILTIN_STRNCMP \
26462647
BUILTIN_STRSTR \
26472648
BUILTIN_SUPPORTS \
@@ -3734,6 +3735,9 @@ BUILTIN_STRCMP:
37343735
BUILTIN_STRDUP:
37353736
$(call check,test-builtin-strdup,HAVE_BUILTIN_STRDUP,__builtin_strdup)
37363737

3738+
BUILTIN_STRLEN:
3739+
$(call check,test-builtin-strlen,HAVE_BUILTIN_STRLEN,__builtin_strlen)
3740+
37373741
BUILTIN_STRNCMP:
37383742
$(call check,test-builtin-strncmp,HAVE_BUILTIN_STRNCMP,__builtin_strncmp)
37393743

core-affinity.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ static void stress_topology_set_get(
103103
int n_sets = 0;
104104
int which;
105105

106-
if (sscanf(arg + strlen(topology) , "%d", &which) != 1) {
106+
if (sscanf(arg + shim_strlen(topology) , "%d", &which) != 1) {
107107
(void)fprintf(stderr, "%s: invalid argument '%s' missing integer\n", topology, arg);
108108
_exit(EXIT_FAILURE);
109109
}

core-builtin.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@
7373
#define shim_strcmp(s1, s2) strcmp((s1), (s2))
7474
#endif
7575

76+
#if defined(HAVE_BUILTIN_STRLEN)
77+
#define shim_strlen(str) __builtin_strlen((str))
78+
#else
79+
#define shim_strlen(str) strlen((str))
80+
#endif
81+
7682
#if defined(HAVE_BUILTIN_STRNCMP)
7783
#define shim_strncmp(s1, s2, n) __builtin_strncmp((s1), (s2), (n))
7884
#else

core-config-check.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static int stress_config_check_cpu_filter(const struct dirent *d)
8383
{
8484
if (UNLIKELY(!d))
8585
return 0;
86-
if (UNLIKELY(strlen(d->d_name) < 4))
86+
if (UNLIKELY(shim_strlen(d->d_name) < 4))
8787
return 0;
8888
if (shim_strncmp(d->d_name, "cpu", 3))
8989
return 0;

core-cpu-cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ static int stress_cpu_cache_get_riscv(
333333
base++;
334334
if (!*base)
335335
return 0;
336-
if (strlen(base) < 4)
336+
if (shim_strlen(base) < 4)
337337
return 0;
338338
if (sscanf(base + 3, "%d", &cpu_num) != 1)
339339
return 0;

core-cpuidle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ void stress_cpuidle_log_info(void)
362362
return;
363363

364364
for (cc = cpu_cstate_list; cc; cc = cc->next) {
365-
len += strlen(cc->cstate) + 2;
365+
len += shim_strlen(cc->cstate) + 2;
366366
}
367367
buf = (char *)calloc(len, sizeof(*buf));
368368
if (UNLIKELY(!buf))

core-filesystem.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,7 +1685,7 @@ static void stress_fs_clean_dir_files(
16851685
end = path + PATH_MAX;
16861686

16871687
while (n--) {
1688-
size_t name_len = strlen(names[n]->d_name) + 1;
1688+
size_t name_len = shim_strlen(names[n]->d_name) + 1;
16891689
#if !defined(DT_DIR) || \
16901690
!defined(DT_LNK) || \
16911691
!defined(DT_REG)
@@ -1699,7 +1699,7 @@ static void stress_fs_clean_dir_files(
16991699
}
17001700

17011701
(void)snprintf(ptr, (size_t)(end - ptr), "/%s", names[n]->d_name);
1702-
name_len = strlen(ptr);
1702+
name_len = shim_strlen(ptr);
17031703

17041704
#if defined(DT_DIR) && \
17051705
defined(DT_LNK) && \
@@ -1767,7 +1767,7 @@ void stress_fs_clean_dir(
17671767
const uint32_t instance)
17681768
{
17691769
const char *temp_path = stress_fs_temp_path_get();
1770-
const size_t temp_path_len = strlen(temp_path);
1770+
const size_t temp_path_len = shim_strlen(temp_path);
17711771

17721772
if (LIKELY(name != NULL)) {
17731773
char path[PATH_MAX];

core-ftrace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ static int stress_ftrace_current_tracer(const char *str, const bool carp)
189189
char filename[PATH_MAX];
190190

191191
(void)snprintf(filename, sizeof(filename), "%s/tracing/current_tracer", path);
192-
if (stress_fs_file_write(filename, str, strlen(str)) < 0) {
192+
if (stress_fs_file_write(filename, str, shim_strlen(str)) < 0) {
193193
if (carp) {
194194
pr_inf("ftrace: cannot set function tracing, cannot write '%s' to '%s', errno=%d (%s)\n",
195195
str, filename, errno, strerror(errno));

core-hash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ stress_hash_t *stress_hash_add(stress_hash_table_t *hash_table, const char *str)
768768
return hash;
769769

770770
/* Not found, so add a new hash */
771-
len = strlen(str) + 1;
771+
len = shim_strlen(str) + 1;
772772
hash = (stress_hash_t *)malloc(sizeof(*hash) + len);
773773
if (UNLIKELY(!hash))
774774
return NULL;

core-helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2075,7 +2075,7 @@ char *stress_env_ld_library_path_get(void)
20752075
*/
20762076
parent_ld_path = getenv("LD_LIBRARY_PATH");
20772077
if (parent_ld_path) {
2078-
const size_t len = strlen(parent_ld_path) + 17;
2078+
const size_t len = shim_strlen(parent_ld_path) + 17;
20792079

20802080
ld_library_path = (char *)malloc(len);
20812081
if (ld_library_path)

0 commit comments

Comments
 (0)