tree-wide: make use of new STRLEN() macro everywhere (#7639)
Let's employ coccinelle to do this for us. Follow-up for #7625.
This commit is contained in:
@@ -1474,7 +1474,7 @@ static bool valid_slice_name(const char *p, size_t n) {
|
||||
if (!p)
|
||||
return false;
|
||||
|
||||
if (n < strlen("x.slice"))
|
||||
if (n < STRLEN("x.slice"))
|
||||
return false;
|
||||
|
||||
if (memcmp(p + n - 6, ".slice", 6) == 0) {
|
||||
@@ -1558,7 +1558,7 @@ static const char *skip_session(const char *p) {
|
||||
p += strspn(p, "/");
|
||||
|
||||
n = strcspn(p, "/");
|
||||
if (n < strlen("session-x.scope"))
|
||||
if (n < STRLEN("session-x.scope"))
|
||||
return NULL;
|
||||
|
||||
if (memcmp(p, "session-", 8) == 0 && memcmp(p + n - 6, ".scope", 6) == 0) {
|
||||
@@ -1595,7 +1595,7 @@ static const char *skip_user_manager(const char *p) {
|
||||
p += strspn(p, "/");
|
||||
|
||||
n = strcspn(p, "/");
|
||||
if (n < strlen("user@x.service"))
|
||||
if (n < STRLEN("user@x.service"))
|
||||
return NULL;
|
||||
|
||||
if (memcmp(p, "user@", 5) == 0 && memcmp(p + n - 8, ".service", 8) == 0) {
|
||||
|
||||
@@ -30,11 +30,11 @@ int encode_devnode_name(const char *str, char *str_enc, size_t len);
|
||||
int whitelisted_char_for_devnode(char c, const char *additional);
|
||||
|
||||
#define SYS_BLOCK_PATH_MAX(suffix) \
|
||||
(strlen("/sys/dev/block/") + DECIMAL_STR_MAX(dev_t) + 1 + DECIMAL_STR_MAX(dev_t) + strlen_ptr(suffix))
|
||||
(STRLEN("/sys/dev/block/") + DECIMAL_STR_MAX(dev_t) + 1 + DECIMAL_STR_MAX(dev_t) + strlen_ptr(suffix))
|
||||
#define xsprintf_sys_block_path(buf, suffix, devno) \
|
||||
xsprintf(buf, "/sys/dev/block/%u:%u%s", major(devno), minor(devno), strempty(suffix))
|
||||
|
||||
#define DEV_NUM_PATH_MAX \
|
||||
(strlen("/dev/block/") + DECIMAL_STR_MAX(dev_t) + 1 + DECIMAL_STR_MAX(dev_t))
|
||||
(STRLEN("/dev/block/") + DECIMAL_STR_MAX(dev_t) + 1 + DECIMAL_STR_MAX(dev_t))
|
||||
#define xsprintf_dev_num_path(buf, type, devno) \
|
||||
xsprintf(buf, "/dev/%s/%u:%u", type, major(devno), minor(devno))
|
||||
|
||||
+1
-1
@@ -427,7 +427,7 @@ int move_fd(int from, int to, int cloexec) {
|
||||
|
||||
int acquire_data_fd(const void *data, size_t size, unsigned flags) {
|
||||
|
||||
char procfs_path[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(int)];
|
||||
char procfs_path[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int)];
|
||||
_cleanup_close_pair_ int pipefds[2] = { -1, -1 };
|
||||
char pattern[] = "/dev/shm/data-fd-XXXXXX";
|
||||
_cleanup_close_ int fd = -1;
|
||||
|
||||
+1
-1
@@ -1472,7 +1472,7 @@ int link_tmpfile(int fd, const char *path, const char *target) {
|
||||
if (rename_noreplace(AT_FDCWD, path, AT_FDCWD, target) < 0)
|
||||
return -errno;
|
||||
} else {
|
||||
char proc_fd_path[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(fd) + 1];
|
||||
char proc_fd_path[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(fd) + 1];
|
||||
|
||||
xsprintf(proc_fd_path, "/proc/self/fd/%i", fd);
|
||||
|
||||
|
||||
+2
-2
@@ -580,7 +580,7 @@ int tmp_dir(const char **ret) {
|
||||
}
|
||||
|
||||
int inotify_add_watch_fd(int fd, int what, uint32_t mask) {
|
||||
char path[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(int) + 1];
|
||||
char path[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int) + 1];
|
||||
int r;
|
||||
|
||||
/* This is like inotify_add_watch(), except that the file to watch is not referenced by a path, but by an fd */
|
||||
@@ -825,7 +825,7 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags,
|
||||
}
|
||||
|
||||
int access_fd(int fd, int mode) {
|
||||
char p[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(fd) + 1];
|
||||
char p[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(fd) + 1];
|
||||
int r;
|
||||
|
||||
/* Like access() but operates on an already open fd */
|
||||
|
||||
+4
-4
@@ -1047,18 +1047,18 @@ int log_struct_iovec_internal(
|
||||
}
|
||||
|
||||
for (i = 0; i < n_input_iovec; i++) {
|
||||
if (input_iovec[i].iov_len < strlen("MESSAGE="))
|
||||
if (input_iovec[i].iov_len < STRLEN("MESSAGE="))
|
||||
continue;
|
||||
|
||||
if (memcmp(input_iovec[i].iov_base, "MESSAGE=", strlen("MESSAGE=")) == 0)
|
||||
if (memcmp(input_iovec[i].iov_base, "MESSAGE=", STRLEN("MESSAGE=")) == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if (_unlikely_(i >= n_input_iovec)) /* Couldn't find MESSAGE=? */
|
||||
return -error;
|
||||
|
||||
m = strndupa(input_iovec[i].iov_base + strlen("MESSAGE="),
|
||||
input_iovec[i].iov_len - strlen("MESSAGE="));
|
||||
m = strndupa(input_iovec[i].iov_base + STRLEN("MESSAGE="),
|
||||
input_iovec[i].iov_len - STRLEN("MESSAGE="));
|
||||
|
||||
return log_dispatch_internal(level, error, file, line, func, NULL, NULL, NULL, NULL, m);
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ int name_to_handle_at_loop(
|
||||
}
|
||||
|
||||
static int fd_fdinfo_mnt_id(int fd, const char *filename, int flags, int *mnt_id) {
|
||||
char path[strlen("/proc/self/fdinfo/") + DECIMAL_STR_MAX(int)];
|
||||
char path[STRLEN("/proc/self/fdinfo/") + DECIMAL_STR_MAX(int)];
|
||||
_cleanup_free_ char *fdinfo = NULL;
|
||||
_cleanup_close_ int subfd = -1;
|
||||
char *p;
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
if (_pid_ == 0) { \
|
||||
_r_ = ("/proc/self/" field); \
|
||||
} else { \
|
||||
_r_ = alloca(strlen("/proc/") + DECIMAL_STR_MAX(pid_t) + 1 + sizeof(field)); \
|
||||
_r_ = alloca(STRLEN("/proc/") + DECIMAL_STR_MAX(pid_t) + 1 + sizeof(field)); \
|
||||
sprintf((char*) _r_, "/proc/"PID_FMT"/" field, _pid_); \
|
||||
} \
|
||||
_r_; \
|
||||
|
||||
@@ -226,7 +226,7 @@ static const char *const __signal_table[] = {
|
||||
DEFINE_PRIVATE_STRING_TABLE_LOOKUP(__signal, int);
|
||||
|
||||
const char *signal_to_string(int signo) {
|
||||
static thread_local char buf[sizeof("RTMIN+")-1 + DECIMAL_STR_MAX(int) + 1];
|
||||
static thread_local char buf[STRLEN("RTMIN+") + DECIMAL_STR_MAX(int) + 1];
|
||||
const char *name;
|
||||
|
||||
name = __signal_to_string(signo);
|
||||
|
||||
@@ -122,7 +122,7 @@ int socket_address_parse(SocketAddress *a, const char *s) {
|
||||
|
||||
} else if (startswith(s, "vsock:")) {
|
||||
/* AF_VSOCK socket in vsock:cid:port notation */
|
||||
const char *cid_start = s + strlen("vsock:");
|
||||
const char *cid_start = s + STRLEN("vsock:");
|
||||
|
||||
e = strchr(cid_start, ':');
|
||||
if (!e)
|
||||
|
||||
@@ -992,7 +992,7 @@ int get_ctty_devnr(pid_t pid, dev_t *d) {
|
||||
}
|
||||
|
||||
int get_ctty(pid_t pid, dev_t *_devnr, char **r) {
|
||||
char fn[sizeof("/dev/char/")-1 + 2*DECIMAL_STR_MAX(unsigned) + 1 + 1], *b = NULL;
|
||||
char fn[STRLEN("/dev/char/") + 2*DECIMAL_STR_MAX(unsigned) + 1 + 1], *b = NULL;
|
||||
_cleanup_free_ char *s = NULL;
|
||||
const char *p;
|
||||
dev_t devnr;
|
||||
|
||||
+1
-1
@@ -105,7 +105,7 @@ int socket_from_display(const char *display, char **path) {
|
||||
|
||||
k = strspn(display+1, "0123456789");
|
||||
|
||||
f = new(char, strlen("/tmp/.X11-unix/X") + k + 1);
|
||||
f = new(char, STRLEN("/tmp/.X11-unix/X") + k + 1);
|
||||
if (!f)
|
||||
return -ENOMEM;
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ int fgetxattr_malloc(int fd, const char *name, char **value) {
|
||||
}
|
||||
|
||||
ssize_t fgetxattrat_fake(int dirfd, const char *filename, const char *attribute, void *value, size_t size, int flags) {
|
||||
char fn[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(int) + 1];
|
||||
char fn[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int) + 1];
|
||||
_cleanup_close_ int fd = -1;
|
||||
ssize_t l;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user