diff options
author | Lennart Poettering <lennart@poettering.net> | 2017-12-14 19:02:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-14 19:02:29 +0100 |
commit | fbd0b64f44a7bae678137d67ad5da202f6b8d809 (patch) | |
tree | 0402dca4e258583e009d07c0d8eb9c0fad19d5ac | |
parent | 1142cbd76a1db2adb2c382b76fc0a1c5a97c70cc (diff) | |
download | systemd-fbd0b64f44a7bae678137d67ad5da202f6b8d809.tar.gz |
tree-wide: make use of new STRLEN() macro everywhere (#7639)
Let's employ coccinelle to do this for us.
Follow-up for #7625.
63 files changed, 255 insertions, 221 deletions
diff --git a/CODING_STYLE b/CODING_STYLE index b090db370f..4119cfec23 100644 --- a/CODING_STYLE +++ b/CODING_STYLE @@ -350,8 +350,7 @@ proper event, instead of doing time-based poll loops. - To determine the length of a constant string "foo", don't bother - with sizeof("foo")-1, please use strlen("foo") directly. gcc knows - strlen() anyway and turns it into a constant expression if possible. + with sizeof("foo")-1, please use STRLEN() instead. - If you want to concatenate two or more strings, consider using strjoin() rather than asprintf(), as the latter is a lot diff --git a/coccinelle/const-strlen.cocci b/coccinelle/const-strlen.cocci new file mode 100644 index 0000000000..38bf9b118f --- /dev/null +++ b/coccinelle/const-strlen.cocci @@ -0,0 +1,10 @@ +@@ +constant s; +@@ +- sizeof(s)-1 ++ STRLEN(s) +@@ +constant s; +@@ +- strlen(s) ++ STRLEN(s) diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index 6dcd531025..f599d0f0f1 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -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) { diff --git a/src/basic/device-nodes.h b/src/basic/device-nodes.h index 6136526f84..7dd8a772a5 100644 --- a/src/basic/device-nodes.h +++ b/src/basic/device-nodes.h @@ -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)) diff --git a/src/basic/fd-util.c b/src/basic/fd-util.c index a0820a9667..a4a5c6b3f6 100644 --- a/src/basic/fd-util.c +++ b/src/basic/fd-util.c @@ -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; diff --git a/src/basic/fileio.c b/src/basic/fileio.c index 5296f1cff0..4e02d5b344 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -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); diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index aa33da48b0..4ca36faf09 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -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 */ diff --git a/src/basic/log.c b/src/basic/log.c index 1637a062d7..20d9588e2f 100644 --- a/src/basic/log.c +++ b/src/basic/log.c @@ -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); } diff --git a/src/basic/mount-util.c b/src/basic/mount-util.c index 455c50fc9f..a8947cefc2 100644 --- a/src/basic/mount-util.c +++ b/src/basic/mount-util.c @@ -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; diff --git a/src/basic/process-util.h b/src/basic/process-util.h index 39c194df0d..b413e7fee5 100644 --- a/src/basic/process-util.h +++ b/src/basic/process-util.h @@ -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_; \ diff --git a/src/basic/signal-util.c b/src/basic/signal-util.c index 3137f3d079..27caabe471 100644 --- a/src/basic/signal-util.c +++ b/src/basic/signal-util.c @@ -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); diff --git a/src/basic/socket-util.c b/src/basic/socket-util.c index b02af357ad..a458fc2902 100644 --- a/src/basic/socket-util.c +++ b/src/basic/socket-util.c @@ -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) diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index f6118ebc24..48ee799ad4 100644 --- a/src/basic/terminal-util.c +++ b/src/basic/terminal-util.c @@ -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; diff --git a/src/basic/util.c b/src/basic/util.c index f61d9013e6..8f9f2b902b 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -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; diff --git a/src/basic/xattr-util.c b/src/basic/xattr-util.c index 28214fcf49..12d04eeffb 100644 --- a/src/basic/xattr-util.c +++ b/src/basic/xattr-util.c @@ -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; diff --git a/src/boot/bootctl.c b/src/boot/bootctl.c index 468a655118..59c1af73de 100644 --- a/src/boot/bootctl.c +++ b/src/boot/bootctl.c @@ -497,7 +497,8 @@ static int copy_one_file(const char *esp_path, const char *name, bool force) { char *v; /* Create the EFI default boot loader name (specified for removable devices) */ - v = strjoina(esp_path, "/EFI/BOOT/BOOT", name + strlen("systemd-boot")); + v = strjoina(esp_path, "/EFI/BOOT/BOOT", + name + STRLEN("systemd-boot")); ascii_strupper(strrchr(v, '/') + 1); k = copy_file_with_version_check(p, v, force); diff --git a/src/busctl/busctl.c b/src/busctl/busctl.c index 7547695e68..7a8d6ba5ac 100644 --- a/src/busctl/busctl.c +++ b/src/busctl/busctl.c @@ -977,10 +977,10 @@ static int introspect(sd_bus *bus, char **argv) { pager_open(arg_no_pager, false); - name_width = strlen("NAME"); - type_width = strlen("TYPE"); - signature_width = strlen("SIGNATURE"); - result_width = strlen("RESULT/VALUE"); + name_width = STRLEN("NAME"); + type_width = STRLEN("TYPE"); + signature_width = STRLEN("SIGNATURE"); + result_width = STRLEN("RESULT/VALUE"); sorted = newa(Member*, set_size(members)); diff --git a/src/core/automount.c b/src/core/automount.c index cbcc8abb2b..28d5cc3917 100644 --- a/src/core/automount.c +++ b/src/core/automount.c @@ -565,8 +565,8 @@ static void automount_trigger_notify(Unit *u, Unit *other) { static void automount_enter_waiting(Automount *a) { _cleanup_close_ int ioctl_fd = -1; int p[2] = { -1, -1 }; - char name[sizeof("systemd-")-1 + DECIMAL_STR_MAX(pid_t) + 1]; - char options[sizeof("fd=,pgrp=,minproto=5,maxproto=5,direct")-1 + char name[STRLEN("systemd-") + DECIMAL_STR_MAX(pid_t) + 1]; + char options[STRLEN("fd=,pgrp=,minproto=5,maxproto=5,direct") + DECIMAL_STR_MAX(int) + DECIMAL_STR_MAX(gid_t) + 1]; bool mounted = false; int r, dev_autofs_fd; diff --git a/src/core/dynamic-user.c b/src/core/dynamic-user.c index c4198ac40e..3da31bf870 100644 --- a/src/core/dynamic-user.c +++ b/src/core/dynamic-user.c @@ -147,7 +147,7 @@ static int dynamic_user_acquire(Manager *m, const char *name, DynamicUser** ret) static int make_uid_symlinks(uid_t uid, const char *name, bool b) { - char path1[strlen("/run/systemd/dynamic-uid/direct:") + DECIMAL_STR_MAX(uid_t) + 1]; + char path1[STRLEN("/run/systemd/dynamic-uid/direct:") + DECIMAL_STR_MAX(uid_t) + 1]; const char *path2; int r = 0, k; @@ -175,7 +175,7 @@ static int make_uid_symlinks(uid_t uid, const char *name, bool b) { r = k; } - if (b && symlink(path1 + strlen("/run/systemd/dynamic-uid/direct:"), path2) < 0) { + if (b && symlink(path1 + STRLEN("/run/systemd/dynamic-uid/direct:"), path2) < 0) { k = log_warning_errno(errno, "Failed to symlink \"%s\": %m", path2); if (r == 0) r = k; @@ -218,7 +218,7 @@ static int pick_uid(char **suggested_paths, const char *name, uid_t *ret_uid) { (void) mkdir("/run/systemd/dynamic-uid", 0755); for (;;) { - char lock_path[strlen("/run/systemd/dynamic-uid/") + DECIMAL_STR_MAX(uid_t) + 1]; + char lock_path[STRLEN("/run/systemd/dynamic-uid/") + DECIMAL_STR_MAX(uid_t) + 1]; _cleanup_close_ int lock_fd = -1; uid_t candidate; ssize_t l; @@ -411,7 +411,7 @@ static int dynamic_user_push(DynamicUser *d, uid_t uid, int lock_fd) { } static void unlink_uid_lock(int lock_fd, uid_t uid, const char *name) { - char lock_path[strlen("/run/systemd/dynamic-uid/") + DECIMAL_STR_MAX(uid_t) + 1]; + char lock_path[STRLEN("/run/systemd/dynamic-uid/") + DECIMAL_STR_MAX(uid_t) + 1]; if (lock_fd < 0) return; @@ -744,7 +744,7 @@ void dynamic_user_vacuum(Manager *m, bool close_user) { } int dynamic_user_lookup_uid(Manager *m, uid_t uid, char **ret) { - char lock_path[strlen("/run/systemd/dynamic-uid/") + DECIMAL_STR_MAX(uid_t) + 1]; + char lock_path[STRLEN("/run/systemd/dynamic-uid/") + DECIMAL_STR_MAX(uid_t) + 1]; _cleanup_free_ char *user = NULL; uid_t check_uid; int r; diff --git a/src/core/ima-setup.c b/src/core/ima-setup.c index 4335b7aaa2..80319622ad 100644 --- a/src/core/ima-setup.c +++ b/src/core/ima-setup.c @@ -62,7 +62,7 @@ int ima_setup(void) { } /* attempt to write the name of the policy file into sysfs file */ - if (write(imafd, IMA_POLICY_PATH, strlen(IMA_POLICY_PATH)) > 0) + if (write(imafd, IMA_POLICY_PATH, STRLEN(IMA_POLICY_PATH)) > 0) goto done; /* fall back to copying the policy line-by-line */ diff --git a/src/core/manager.c b/src/core/manager.c index 7ac798348c..e85accbbca 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -140,7 +140,7 @@ static void manager_watch_jobs_in_progress(Manager *m) { (void) sd_event_source_set_description(m->jobs_in_progress_event_source, "manager-jobs-in-progress"); } -#define CYLON_BUFFER_EXTRA (2*(sizeof(ANSI_RED)-1) + sizeof(ANSI_HIGHLIGHT_RED)-1 + 2*(sizeof(ANSI_NORMAL)-1)) +#define CYLON_BUFFER_EXTRA (2*STRLEN(ANSI_RED) + STRLEN(ANSI_HIGHLIGHT_RED) + 2*STRLEN(ANSI_NORMAL)) static void draw_cylon(char buffer[], size_t buflen, unsigned width, unsigned pos) { char *p = buffer; @@ -2651,7 +2651,7 @@ int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool switching_root) { t = manager_timestamp_to_string(q); { - char field[strlen(t) + strlen("-timestamp") + 1]; + char field[strlen(t) + STRLEN("-timestamp") + 1]; strcpy(stpcpy(field, t), "-timestamp"); dual_timestamp_serialize(f, field, m->timestamps + q); } diff --git a/src/coredump/coredumpctl.c b/src/coredump/coredumpctl.c index b92f5d330d..0d420b2190 100644 --- a/src/coredump/coredumpctl.c +++ b/src/coredump/coredumpctl.c @@ -903,9 +903,9 @@ static int run_gdb(sd_journal *j) { if (r < 0) return log_error_errno(r, "Failed to retrieve COREDUMP_EXE field: %m"); - assert(len > strlen("COREDUMP_EXE=")); - data += strlen("COREDUMP_EXE="); - len -= strlen("COREDUMP_EXE="); + assert(len > STRLEN("COREDUMP_EXE=")); + data += STRLEN("COREDUMP_EXE="); + len -= STRLEN("COREDUMP_EXE="); exe = strndup(data, len); if (!exe) diff --git a/src/fsck/fsck.c b/src/fsck/fsck.c index 6290abdc1b..0091e388dc 100644 --- a/src/fsck/fsck.c +++ b/src/fsck/fsck.c @@ -398,7 +398,7 @@ int main(int argc, char *argv[]) { goto finish; } if (pid == 0) { - char dash_c[sizeof("-C")-1 + DECIMAL_STR_MAX(int) + 1]; + char dash_c[STRLEN("-C") + DECIMAL_STR_MAX(int) + 1]; int progress_socket = -1; const char *cmdline[9]; int i = 0; diff --git a/src/journal-remote/journal-remote.c b/src/journal-remote/journal-remote.c index 10dd3db270..e44989e1ba 100644 --- a/src/journal-remote/journal-remote.c +++ b/src/journal-remote/journal-remote.c @@ -422,7 +422,7 @@ static int add_source(RemoteServer *s, int fd, char* name, bool own_name) { static int add_raw_socket(RemoteServer *s, int fd) { int r; _cleanup_close_ int fd_ = fd; - char name[sizeof("raw-socket-")-1 + DECIMAL_STR_MAX(int) + 1]; + char name[STRLEN("raw-socket-") + DECIMAL_STR_MAX(int) + 1]; assert(fd >= 0); diff --git a/src/journal/audit-type.h b/src/journal/audit-type.h index 01f35c5285..603ad41cc7 100644 --- a/src/journal/audit-type.h +++ b/src/journal/audit-type.h @@ -31,7 +31,7 @@ int audit_type_from_string(const char *s); const char *_s_; \ _s_ = audit_type_to_string(type); \ if (!_s_) { \ - _s_ = alloca(strlen("AUDIT") + DECIMAL_STR_MAX(int)); \ + _s_ = alloca(STRLEN("AUDIT") + DECIMAL_STR_MAX(int)); \ sprintf((char*) _s_, "AUDIT%04i", type); \ } \ _s_; \ diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index 9d2e6dbb1b..7fef403391 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -2572,7 +2572,7 @@ static int find_data_object_by_boot_id( Object **o, uint64_t *b) { - char t[sizeof("_BOOT_ID=")-1 + 32 + 1] = "_BOOT_ID="; + char t[STRLEN("_BOOT_ID=") + 32 + 1] = "_BOOT_ID="; sd_id128_to_string(boot_id, t + 9); return journal_file_find_data_object(f, t, sizeof(t) - 1, o, b); diff --git a/src/journal/journal-send.c b/src/journal/journal-send.c index 5bca471c98..a78aa07032 100644 --- a/src/journal/journal-send.c +++ b/src/journal/journal-send.c @@ -96,7 +96,7 @@ _public_ int sd_journal_printv(int priority, const char *format, va_list ap) { /* FIXME: Instead of limiting things to LINE_MAX we could do a C99 variable-length array on the stack here in a loop. */ - char buffer[8 + LINE_MAX], p[sizeof("PRIORITY=")-1 + DECIMAL_STR_MAX(int) + 1]; + char buffer[8 + LINE_MAX], p[STRLEN("PRIORITY=") + DECIMAL_STR_MAX(int) + 1]; struct iovec iov[2]; assert_return(priority >= 0, -EINVAL); @@ -357,7 +357,7 @@ static int fill_iovec_perror_and_send(const char *message, int skip, struct iove errno = 0; j = strerror_r(_saved_errno_, buffer + 8 + k, n - 8 - k); if (errno == 0) { - char error[sizeof("ERRNO=")-1 + DECIMAL_STR_MAX(int) + 1]; + char error[STRLEN("ERRNO=") + DECIMAL_STR_MAX(int) + 1]; if (j != buffer + 8 + k) memmove(buffer + 8 + k, j, strlen(j)+1); @@ -459,7 +459,7 @@ _public_ int sd_journal_print_with_location(int priority, const char *file, cons } _public_ int sd_journal_printv_with_location(int priority, const char *file, const char *line, const char *func, const char *format, va_list ap) { - char buffer[8 + LINE_MAX], p[sizeof("PRIORITY=")-1 + DECIMAL_STR_MAX(int) + 1]; + char buffer[8 + LINE_MAX], p[STRLEN("PRIORITY=") + DECIMAL_STR_MAX(int) + 1]; struct iovec iov[5]; char *f; diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index e2fd031f83..956d85aff2 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -1343,7 +1343,8 @@ static int add_dmesg(sd_journal *j) { if (!arg_dmesg) return 0; - r = sd_journal_add_match(j, "_TRANSPORT=kernel", strlen("_TRANSPORT=kernel")); + r = sd_journal_add_match(j, "_TRANSPORT=kernel", + STRLEN("_TRANSPORT=kernel")); if (r < 0) return log_error_errno(r, "Failed to add match: %m"); diff --git a/src/journal/journald-console.c b/src/journal/journald-console.c index f093e468c3..98fbb83a0c 100644 --- a/src/journal/journald-console.c +++ b/src/journal/journald-console.c @@ -58,8 +58,8 @@ void server_forward_console( struct iovec iovec[5]; struct timespec ts; - char tbuf[sizeof("[] ")-1 + DECIMAL_STR_MAX(ts.tv_sec) + DECIMAL_STR_MAX(ts.tv_nsec)-3 + 1]; - char header_pid[sizeof("[]: ")-1 + DECIMAL_STR_MAX(pid_t)]; + char tbuf[STRLEN("[] ") + DECIMAL_STR_MAX(ts.tv_sec) + DECIMAL_STR_MAX(ts.tv_nsec)-3 + 1]; + char header_pid[STRLEN("[]: ") + DECIMAL_STR_MAX(pid_t)]; _cleanup_free_ char *ident_buf = NULL; _cleanup_close_ int fd = -1; const char *tty; diff --git a/src/journal/journald-kmsg.c b/src/journal/journald-kmsg.c index 5275f43b38..0fadc16fbd 100644 --- a/src/journal/journald-kmsg.c +++ b/src/journal/journald-kmsg.c @@ -50,7 +50,7 @@ void server_forward_kmsg( _cleanup_free_ char *ident_buf = NULL; struct iovec iovec[5]; char header_priority[DECIMAL_STR_MAX(priority) + 3], - header_pid[sizeof("[]: ")-1 + DECIMAL_STR_MAX(pid_t) + 1]; + header_pid[STRLEN("[]: ") + DECIMAL_STR_MAX(pid_t) + 1]; int n = 0; assert(s); diff --git a/src/journal/journald-native.c b/src/journal/journald-native.c index 5c8711fb7c..65fb6ab63a 100644 --- a/src/journal/journald-native.c +++ b/src/journal/journald-native.c @@ -95,13 +95,14 @@ static void server_process_entry_meta( *message = t; } - } else if (l > strlen("OBJECT_PID=") && - l < strlen("OBJECT_PID=") + DECIMAL_STR_MAX(pid_t) && + } else if (l > STRLEN("OBJECT_PID=") && + l < STRLEN("OBJECT_PID=") + DECIMAL_STR_MAX(pid_t) && startswith(p, "OBJECT_PID=") && allow_object_pid(ucred)) { char buf[DECIMAL_STR_MAX(pid_t)]; - memcpy(buf, p + strlen("OBJECT_PID="), l - strlen("OBJECT_PID=")); - buf[l-strlen("OBJECT_PID=")] = '\0'; + memcpy(buf, p + STRLEN("OBJECT_PID="), + l - STRLEN("OBJECT_PID=")); + buf[l-STRLEN("OBJECT_PID=")] = '\0'; (void) parse_pid(buf, object_pid); } @@ -252,7 +253,7 @@ static int server_process_entry( tn = n++; iovec[tn] = IOVEC_MAKE_STRING("_TRANSPORT=journal"); - entry_size += strlen("_TRANSPORT=journal"); + entry_size += STRLEN("_TRANSPORT=journal"); if (entry_size + n + 1 > ENTRY_SIZE_MAX) { /* data + separators + trailer */ log_debug("Entry is too big with %zu properties and %zu bytes, ignoring.", n, entry_size); diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index 3da3dad230..48375f9c3e 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -724,7 +724,7 @@ static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, unsigned #define IOVEC_ADD_NUMERIC_FIELD(iovec, n, value, type, isset, format, field) \ if (isset(value)) { \ char *k; \ - k = newa(char, strlen(field "=") + DECIMAL_STR_MAX(type) + 1); \ + k = newa(char, STRLEN(field "=") + DECIMAL_STR_MAX(type) + 1); \ sprintf(k, field "=" format, value); \ iovec[n++] = IOVEC_MAKE_STRING(k); \ } @@ -739,7 +739,7 @@ static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, unsigned #define IOVEC_ADD_ID128_FIELD(iovec, n, value, field) \ if (!sd_id128_is_null(value)) { \ char *k; \ - k = newa(char, strlen(field "=") + SD_ID128_STRING_MAX); \ + k = newa(char, STRLEN(field "=") + SD_ID128_STRING_MAX); \ sd_id128_to_string(value, stpcpy(k, field "=")); \ iovec[n++] = IOVEC_MAKE_STRING(k); \ } @@ -747,7 +747,7 @@ static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, unsigned #define IOVEC_ADD_SIZED_FIELD(iovec, n, value, value_size, field) \ if (value_size > 0) { \ char *k; \ - k = newa(char, strlen(field "=") + value_size + 1); \ + k = newa(char, STRLEN(field "=") + value_size + 1); \ *((char*) mempcpy(stpcpy(k, field "="), value, value_size)) = 0; \ iovec[n++] = IOVEC_MAKE_STRING(k); \ } \ diff --git a/src/journal/journald-server.h b/src/journal/journald-server.h index 8169bc9498..bf4ba6897a 100644 --- a/src/journal/journald-server.h +++ b/src/journal/journald-server.h @@ -180,7 +180,7 @@ struct Server { ClientContext *pid1_context; /* the context of PID 1 */ }; -#define SERVER_MACHINE_ID(s) ((s)->machine_id_field + strlen("_MACHINE_ID=")) +#define SERVER_MACHINE_ID(s) ((s)->machine_id_field + STRLEN("_MACHINE_ID=")) /* Extra fields for any log messages */ #define N_IOVEC_META_FIELDS 22 diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c index 1137d4eeed..671ada718c 100644 --- a/src/journal/journald-stream.c +++ b/src/journal/journald-stream.c @@ -106,7 +106,7 @@ struct StdoutStream { LIST_FIELDS(StdoutStream, stdout_stream); LIST_FIELDS(StdoutStream, stdout_stream_notify_queue); - char id_field[sizeof("_STREAM_ID=")-1 + SD_ID128_STRING_MAX]; + char id_field[STRLEN("_STREAM_ID=") + SD_ID128_STRING_MAX]; }; void stdout_stream_free(StdoutStream *s) { @@ -194,7 +194,7 @@ static int stdout_stream_save(StdoutStream *s) { s->forward_to_syslog, s->forward_to_kmsg, s->forward_to_console, - s->id_field + strlen("_STREAM_ID=")); + s->id_field + STRLEN("_STREAM_ID=")); if (!isempty(s->identifier)) { _cleanup_free_ char *escaped; @@ -255,7 +255,7 @@ static int stdout_stream_log(StdoutStream *s, const char *p, LineBreak line_brea struct iovec *iovec; int priority; char syslog_priority[] = "PRIORITY=\0"; - char syslog_facility[sizeof("SYSLOG_FACILITY=")-1 + DECIMAL_STR_MAX(int) + 1]; + char syslog_facility[STRLEN("SYSLOG_FACILITY=") + DECIMAL_STR_MAX(int) + 1]; _cleanup_free_ char *message = NULL, *syslog_identifier = NULL; size_t n = 0, m; int r; @@ -300,7 +300,7 @@ static int stdout_stream_log(StdoutStream *s, const char *p, LineBreak line_brea iovec[n++] = IOVEC_MAKE_STRING("_TRANSPORT=stdout"); iovec[n++] = IOVEC_MAKE_STRING(s->id_field); - syslog_priority[strlen("PRIORITY=")] = '0' + LOG_PRI(priority); + syslog_priority[STRLEN("PRIORITY=")] = '0' + LOG_PRI(priority); iovec[n++] = IOVEC_MAKE_STRING(syslog_priority); if (priority & LOG_FACMASK) { @@ -836,7 +836,7 @@ int server_open_stdout_socket(Server *s) { void stdout_stream_send_notify(StdoutStream *s) { struct iovec iovec = { .iov_base = (char*) "FDSTORE=1", - .iov_len = strlen("FDSTORE=1"), + .iov_len = STRLEN("FDSTORE=1"), }; struct msghdr msghdr = { .msg_iov = &iovec, diff --git a/src/journal/journald-syslog.c b/src/journal/journald-syslog.c index fae2cd59be..4018288b0c 100644 --- a/src/journal/journald-syslog.c +++ b/src/journal/journald-syslog.c @@ -132,7 +132,7 @@ static void forward_syslog_raw(Server *s, int priority, const char *buffer, cons void server_forward_syslog(Server *s, int priority, const char *identifier, const char *message, const struct ucred *ucred, const struct timeval *tv) { struct iovec iovec[5]; char header_priority[DECIMAL_STR_MAX(priority) + 3], header_time[64], - header_pid[sizeof("[]: ")-1 + DECIMAL_STR_MAX(pid_t) + 1]; + header_pid[STRLEN("[]: ") + DECIMAL_STR_MAX(pid_t) + 1]; int n = 0; time_t t; struct tm *tm; diff --git a/src/journal/test-journal-send.c b/src/journal/test-journal-send.c index 833ca415da..8e69a52e29 100644 --- a/src/journal/test-journal-send.c +++ b/src/journal/test-journal-send.c @@ -31,16 +31,16 @@ int main(int argc, char *argv[]) { /* utf-8 and non-utf-8, message-less and message-ful iovecs */ struct iovec graph1[] = { - {(char*) "GRAPH=graph", strlen("GRAPH=graph")} + {(char*) "GRAPH=graph", STRLEN("GRAPH=graph")} }; struct iovec graph2[] = { - {(char*) "GRAPH=graph\n", strlen("GRAPH=graph\n")} + {(char*) "GRAPH=graph\n", STRLEN("GRAPH=graph\n")} }; struct iovec message1[] = { - {(char*) "MESSAGE=graph", strlen("MESSAGE=graph")} + {(char*) "MESSAGE=graph", STRLEN("MESSAGE=graph")} }; struct iovec message2[] = { - {(char*) "MESSAGE=graph\n", strlen("MESSAGE=graph\n")} + {(char*) "MESSAGE=graph\n", STRLEN("MESSAGE=graph\n")} }; assert_se(sd_journal_print(LOG_INFO, "piepapo") == 0); diff --git a/src/libsystemd/sd-bus/bus-socket.c b/src/libsystemd/sd-bus/bus-socket.c index 80cec897c1..07a9c8affd 100644 --- a/src/libsystemd/sd-bus/bus-socket.c +++ b/src/libsystemd/sd-bus/bus-socket.c @@ -232,8 +232,9 @@ static int bus_socket_auth_verify_client(sd_bus *b) { if (f) b->can_fds = - (f - e == strlen("\r\nAGREE_UNIX_FD")) && - memcmp(e + 2, "AGREE_UNIX_FD", strlen("AGREE_UNIX_FD")) == 0; + (f - e == STRLEN("\r\nAGREE_UNIX_FD")) && + memcmp(e + 2, "AGREE_UNIX_FD", + STRLEN("AGREE_UNIX_FD")) == 0; b->rbuffer_size -= (start - (char*) b->rbuffer); memmove(b->rbuffer, start, b->rbuffer_size); diff --git a/src/libsystemd/sd-bus/bus-track.c b/src/libsystemd/sd-bus/bus-track.c index 5b55f304de..ab22d6e4de 100644 --- a/src/libsystemd/sd-bus/bus-track.c +++ b/src/libsystemd/sd-bus/bus-track.c @@ -63,7 +63,7 @@ struct sd_bus_track { ({ \ char *_x; \ size_t _l = strlen(name); \ - _x = alloca(strlen(MATCH_PREFIX)+_l+strlen(MATCH_SUFFIX)+1); \ + _x = alloca(STRLEN(MATCH_PREFIX)+_l+STRLEN(MATCH_SUFFIX)+1); \ strcpy(stpcpy(stpcpy(_x, MATCH_PREFIX), name), MATCH_SUFFIX); \ _x; \ }) diff --git a/src/libsystemd/sd-device/device-enumerator.c b/src/libsystemd/sd-device/device-enumerator.c index 04f50e2ad0..cd9ec042bf 100644 --- a/src/libsystemd/sd-device/device-enumerator.c +++ b/src/libsystemd/sd-device/device-enumerator.c @@ -293,7 +293,7 @@ static int device_compare(const void *_a, const void *_b) { * entire sound card completed. The kernel makes this guarantee * when creating those devices, and hence we should too when * enumerating them. */ - sound_a += strlen("/sound/card"); + sound_a += STRLEN("/sound/card"); sound_a = strchr(sound_a, '/'); if (sound_a) { diff --git a/src/libsystemd/sd-device/device-private.c b/src/libsystemd/sd-device/device-private.c index 424965ecd5..77f0f4b2ee 100644 --- a/src/libsystemd/sd-device/device-private.c +++ b/src/libsystemd/sd-device/device-private.c @@ -1050,7 +1050,7 @@ int device_update_db(sd_device *device) { const char *devlink; FOREACH_DEVICE_DEVLINK(device, devlink) - fprintf(f, "S:%s\n", devlink + strlen("/dev/")); + fprintf(f, "S:%s\n", devlink + STRLEN("/dev/")); if (device->devlink_priority != 0) fprintf(f, "L:%i\n", device->devlink_priority); diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index f8b9f9e3b0..a96d7445ce 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -209,7 +209,7 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) { return -ENOMEM; } - devpath = syspath + strlen("/sys"); + devpath = syspath + STRLEN("/sys"); r = device_add_property_internal(device, "DEVPATH", devpath); if (r < 0) @@ -700,7 +700,7 @@ static int device_new_from_child(sd_device **ret, sd_device *child) { path = strdup(syspath); if (!path) return -ENOMEM; - subdir = path + strlen("/sys"); + subdir = path + STRLEN("/sys"); for (;;) { char *pos; diff --git a/src/libsystemd/sd-network/sd-network.c b/src/libsystemd/sd-network/sd-network.c index f6460b9f7c..8f4814019e 100644 --- a/src/libsystemd/sd-network/sd-network.c +++ b/src/libsystemd/sd-network/sd-network.c @@ -104,7 +104,7 @@ _public_ int sd_network_get_route_domains(char ***ret) { } static int network_link_get_string(int ifindex, const char *field, char **ret) { - char path[strlen("/run/systemd/netif/links/") + DECIMAL_STR_MAX(ifindex) + 1]; + char path[STRLEN("/run/systemd/netif/links/") + DECIMAL_STR_MAX(ifindex) + 1]; _cleanup_free_ char *s = NULL; int r; @@ -128,7 +128,7 @@ static int network_link_get_string(int ifindex, const char *field, char **ret) { } static int network_link_get_strv(int ifindex, const char *key, char ***ret) { - char path[strlen("/run/systemd/netif/links/") + DECIMAL_STR_MAX(ifindex) + 1]; + char path[STRLEN("/run/systemd/netif/links/") + DECIMAL_STR_MAX(ifindex) + 1]; _cleanup_strv_free_ char **a = NULL; _cleanup_free_ char *s = NULL; int r; @@ -224,7 +224,7 @@ _public_ int sd_network_link_get_route_domains(int ifindex, char ***ret) { } static int network_link_get_ifindexes(int ifindex, const char *key, int **ret) { - char path[strlen("/run/systemd/netif/links/") + DECIMAL_STR_MAX(ifindex) + 1]; + char path[STRLEN("/run/systemd/netif/links/") + DECIMAL_STR_MAX(ifindex) + 1]; _cleanup_free_ int *ifis = NULL; _cleanup_free_ char *s = NULL; size_t allocated = 0, c = 0; diff --git a/src/machine/machine.c b/src/machine/machine.c index 0525c0cb03..7375d83a44 100644 --- a/src/machine/machine.c +++ b/src/machine/machine.c @@ -610,7 +610,7 @@ void machine_release_unit(Machine *m) { } int machine_get_uid_shift(Machine *m, uid_t *ret) { - char p[strlen("/proc//uid_map") + DECIMAL_STR_MAX(pid_t) + 1]; + char p[STRLEN("/proc//uid_map") + DECIMAL_STR_MAX(pid_t) + 1]; uid_t uid_base, uid_shift, uid_range; gid_t gid_base, gid_shift, gid_range; _cleanup_fclose_ FILE *f = NULL; diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c index b7285e419d..c435bb9b5a 100644 --- a/src/machine/machinectl.c +++ b/src/machine/machinectl.c @@ -194,8 +194,8 @@ static int call_get_os_release(sd_bus *bus, const char *method, const char *name static int list_machines(int argc, char *argv[], void *userdata) { - size_t max_name = strlen("MACHINE"), max_class = strlen("CLASS"), - max_service = strlen("SERVICE"), max_os = strlen("OS"), max_version_id = strlen("VERSION"); + size_t max_name = STRLEN("MACHINE"), max_class = STRLEN("CLASS"), + max_service = STRLEN("SERVICE"), max_os = STRLEN("OS"), max_version_id = STRLEN("VERSION"); _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; _cleanup_free_ char *prefix = NULL; @@ -284,13 +284,13 @@ static int list_machines(int argc, char *argv[], void *userdata) { qsort_safe(machines, n_machines, sizeof(MachineInfo), compare_machine_info); - /* Allocate for prefix max characters for all fields + spaces between them + strlen(",\n") */ + /* Allocate for prefix max characters for all fields + spaces between them + STRLEN(",\n") */ r = asprintf(&prefix, "%-*s", (int) (max_name + max_class + max_service + max_os + - max_version_id + 5 + strlen(",\n")), + max_version_id + 5 + STRLEN(",\n")), ",\n"); if (r < 0) { r = log_oom(); @@ -352,7 +352,7 @@ static int compare_image_info(const void *a, const void *b) { static int list_images(int argc, char *argv[], void *userdata) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; - size_t max_name = strlen("NAME"), max_type = strlen("TYPE"), max_size = strlen("USAGE"), max_crtime = strlen("CREATED"), max_mtime = strlen("MODIFIED"); + size_t max_name = STRLEN("NAME"), max_type = STRLEN("TYPE"), max_size = STRLEN("USAGE"), max_crtime = STRLEN("CREATED"), max_mtime = STRLEN("MODIFIED"); _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; _cleanup_free_ ImageInfo *images = NULL; size_t n_images = 0, n_allocated = 0, j; @@ -2527,7 +2527,7 @@ static int compare_transfer_info(const void *a, const void *b) { } static int list_transfers(int argc, char *argv[], void *userdata) { - size_t max_type = strlen("TYPE"), max_local = strlen("LOCAL"), max_remote = strlen("REMOTE"); + size_t max_type = STRLEN("TYPE"), max_local = STRLEN("LOCAL"), max_remote = STRLEN("REMOTE"); _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_free_ TransferInfo *transfers = NULL; diff --git a/src/machine/machined-dbus.c b/src/machine/machined-dbus.c index 8f460d0617..330d6b3d6e 100644 --- a/src/machine/machined-dbus.c +++ b/src/machine/machined-dbus.c @@ -1320,7 +1320,7 @@ static int method_map_to_machine_user(sd_bus_message *message, void *userdata, s HASHMAP_FOREACH(machine, m->machines, i) { _cleanup_fclose_ FILE *f = NULL; - char p[strlen("/proc//uid_map") + DECIMAL_STR_MAX(pid_t) + 1]; + char p[STRLEN("/proc//uid_map") + DECIMAL_STR_MAX(pid_t) + 1]; if (machine->class != MACHINE_CONTAINER) continue; @@ -1438,7 +1438,7 @@ static int method_map_to_machine_group(sd_bus_message *message, void *groupdata, HASHMAP_FOREACH(machine, m->machines, i) { _cleanup_fclose_ FILE *f = NULL; - char p[strlen("/proc//gid_map") + DECIMAL_STR_MAX(pid_t) + 1]; + char p[STRLEN("/proc//gid_map") + DECIMAL_STR_MAX(pid_t) + 1]; if (machine->class != MACHINE_CONTAINER) continue; diff --git a/src/network/networkctl.c b/src/network/networkctl.c index 262b715206..59ce098cd1 100644 --- a/src/network/networkctl.c +++ b/src/network/networkctl.c @@ -340,7 +340,7 @@ static int list_links(int argc, char *argv[], void *userdata) { /* IEEE Organizationally Unique Identifier vendor string */ static int ieee_oui(sd_hwdb *hwdb, const struct ether_addr *mac, char **ret) { const char *description; - char modalias[strlen("OUI:XXYYXXYYXXYY") + 1], *desc; + char modalias[STRLEN("OUI:XXYYXXYYXXYY") + 1], *desc; int r; assert(ret); diff --git a/src/nspawn/nspawn-patch-uid.c b/src/nspawn/nspawn-patch-uid.c index 9f2555a3f8..7081ed0db2 100644 --- a/src/nspawn/nspawn-patch-uid.c +++ b/src/nspawn/nspawn-patch-uid.c @@ -44,7 +44,7 @@ #if HAVE_ACL static int get_acl(int fd, const char *name, acl_type_t type, acl_t *ret) { - char procfs_path[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(int) + 1]; + char procfs_path[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int) + 1]; acl_t acl; assert(fd >= 0); @@ -73,7 +73,7 @@ static int get_acl(int fd, const char *name, acl_type_t type, acl_t *ret) { } static int set_acl(int fd, const char *name, acl_type_t type, acl_t acl) { - char procfs_path[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(int) + 1]; + char procfs_path[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int) + 1]; int r; assert(fd >= 0); diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 51663e28dc..f85856c077 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -2856,7 +2856,7 @@ static int uid_shift_pick(uid_t *shift, LockFile *ret_lock_file) { (void) mkdir("/run/systemd/nspawn-uid", 0755); for (;;) { - char lock_path[strlen("/run/systemd/nspawn-uid/") + DECIMAL_STR_MAX(uid_t) + 1]; + char lock_path[STRLEN("/run/systemd/nspawn-uid/") + DECIMAL_STR_MAX(uid_t) + 1]; _cleanup_release_lock_file_ LockFile lf = LOCK_FILE_INIT; if (--n_tries <= 0) @@ -2910,7 +2910,7 @@ static int uid_shift_pick(uid_t *shift, LockFile *ret_lock_file) { } static int setup_uid_map(pid_t pid) { - char uid_map[strlen("/proc//uid_map") + DECIMAL_STR_MAX(uid_t) + 1], line[DECIMAL_STR_MAX(uid_t)*3+3+1]; + char uid_map[STRLEN("/proc//uid_map") + DECIMAL_STR_MAX(uid_t) + 1], line[DECIMAL_STR_MAX(uid_t)*3+3+1]; int r; assert(pid > 1); diff --git a/src/nss-systemd/nss-systemd.c b/src/nss-systemd/nss-systemd.c index cd6479573b..cc641e1615 100644 --- a/src/nss-systemd/nss-systemd.c +++ b/src/nss-systemd/nss-systemd.c @@ -92,7 +92,7 @@ static int direct_lookup_name(const char *name, uid_t *ret) { } static int direct_lookup_uid(uid_t uid, char **ret) { - char path[strlen("/run/systemd/dynamic-uid/direct:") + DECIMAL_STR_MAX(uid_t) + 1], *s; + char path[STRLEN("/run/systemd/dynamic-uid/direct:") + DECIMAL_STR_MAX(uid_t) + 1], *s; int r; xsprintf(path, "/run/systemd/dynamic-uid/direct:" UID_FMT, uid); diff --git a/src/resolve/resolved-dns-rr.c b/src/resolve/resolved-dns-rr.c index 26d2cbcc20..eb5592d3cf 100644 --- a/src/resolve/resolved-dns-rr.c +++ b/src/resolve/resolved-dns-rr.c @@ -766,7 +766,7 @@ static int format_timestamp_dns(char *buf, size_t l, time_t sec) { struct tm tm; assert(buf); - assert(l > strlen("YYYYMMDDHHmmSS")); + assert(l > STRLEN("YYYYMMDDHHmmSS")); if (!gmtime_r(&sec, &tm)) return -EINVAL; @@ -1035,7 +1035,7 @@ const char *dns_resource_record_to_string(DnsResourceRecord *rr) { case DNS_TYPE_RRSIG: { _cleanup_free_ char *alg = NULL; - char expiration[strlen("YYYYMMDDHHmmSS") + 1], inception[strlen("YYYYMMDDHHmmSS") + 1]; + char expiration[STRLEN("YYYYMMDDHHmmSS") + 1], inception[STRLEN("YYYYMMDDHHmmSS") + 1]; const char *type; int n; diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c index a0c76eddbe..17928a9732 100644 --- a/src/shared/ask-password-api.c +++ b/src/shared/ask-password-api.c @@ -252,11 +252,13 @@ int ask_password_tty( } if (colors_enabled()) - loop_write(ttyfd, ANSI_HIGHLIGHT, strlen(ANSI_HIGHLIGHT), false); + loop_write(ttyfd, ANSI_HIGHLIGHT, + STRLEN(ANSI_HIGHLIGHT), false); loop_write(ttyfd, message, strlen(message), false); loop_write(ttyfd, " ", 1, false); if (colors_enabled()) - loop_write(ttyfd, ANSI_NORMAL, strlen(ANSI_NORMAL), false); + loop_write(ttyfd, ANSI_NORMAL, STRLEN(ANSI_NORMAL), + false); new_termios = old_termios; new_termios.c_lflag &= ~(ICANON|ECHO); diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index 8789fd163a..e8d7db8f0c 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -1186,7 +1186,7 @@ int root_hash_load(const char *image, void **ret, size_t *ret_size) { if (!IN_SET(r, -ENODATA, -EOPNOTSUPP, -ENOENT)) return r; - fn = newa(char, strlen(image) + strlen(".roothash") + 1); + fn = newa(char, strlen(image) + STRLEN(".roothash") + 1); n = stpcpy(fn, image); e = endswith(fn, ".raw"); if (e) diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index 420c4d3e37..afc3dcd219 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -506,7 +506,9 @@ static int output_verbose( else { _cleanup_free_ char *value = NULL; - r = parse_field(data, length, "_SOURCE_REALTIME_TIMESTAMP=", strlen("_SOURCE_REALTIME_TIMESTAMP="), &value, NULL); + r = parse_field(data, length, "_SOURCE_REALTIME_TIMESTAMP=", + STRLEN("_SOURCE_REALTIME_TIMESTAMP="), &value, + NULL); if (r < 0) return r; assert(r > 0); diff --git a/src/shared/utmp-wtmp.c b/src/shared/utmp-wtmp.c index 40910876c9..1715c0fb24 100644 --- a/src/shared/utmp-wtmp.c +++ b/src/shared/utmp-wtmp.c @@ -425,7 +425,7 @@ int utmp_wall( if (u->ut_type != USER_PROCESS || u->ut_user[0] == 0) continue; - /* this access is fine, because strlen("/dev/") << 32 (UT_LINESIZE) */ + /* this access is fine, because STRLEN("/dev/") << 32 (UT_LINESIZE) */ if (path_startswith(u->ut_line, "/dev/")) path = u->ut_line; else { diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index ef76af817c..18c64241ba 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -428,12 +428,12 @@ static int output_units_list(const UnitInfo *unit_infos, unsigned c) { unsigned n_shown = 0; int job_count = 0; - max_id_len = strlen("UNIT"); - load_len = strlen("LOAD"); - active_len = strlen("ACTIVE"); - sub_len = strlen("SUB"); - job_len = strlen("JOB"); - max_desc_len = strlen("DESCRIPTION"); + max_id_len = STRLEN("UNIT"); + load_len = STRLEN("LOAD"); + active_len = STRLEN("ACTIVE"); + sub_len = STRLEN("SUB"); + job_len = STRLEN("JOB"); + max_desc_len = STRLEN("DESCRIPTION"); for (u = unit_infos; u < unit_infos + c; u++) { max_id_len = MAX(max_id_len, strlen(u->id) + (u->machine ? strlen(u->machine)+1 : 0)); @@ -914,10 +914,10 @@ static int socket_info_compare(const struct socket_info *a, const struct socket_ static int output_sockets_list(struct socket_info *socket_infos, unsigned cs) { struct socket_info *s; - unsigned pathlen = strlen("LISTEN"), - typelen = strlen("TYPE") * arg_show_types, - socklen = strlen("UNIT"), - servlen = strlen("ACTIVATES"); + unsigned pathlen = STRLEN("LISTEN"), + typelen = STRLEN("TYPE") * arg_show_types, + socklen = STRLEN("UNIT"), + servlen = STRLEN("ACTIVATES"); const char *on, *off; for (s = socket_infos; s < socket_infos + cs; s++) { @@ -1165,12 +1165,12 @@ static int timer_info_compare(const struct timer_info *a, const struct timer_inf static int output_timers_list(struct timer_info *timer_infos, unsigned n) { struct timer_info *t; unsigned - nextlen = strlen("NEXT"), - leftlen = strlen("LEFT"), - lastlen = strlen("LAST"), - passedlen = strlen("PASSED"), - unitlen = strlen("UNIT"), - activatelen = strlen("ACTIVATES"); + nextlen = STRLEN("NEXT"), + leftlen = STRLEN("LEFT"), + lastlen = STRLEN("LAST"), + passedlen = STRLEN("PASSED"), + unitlen = STRLEN("UNIT"), + activatelen = STRLEN("ACTIVATES"); const char *on, *off; @@ -1410,8 +1410,8 @@ static void output_unit_file_list(const UnitFileList *units, unsigned c) { unsigned max_id_len, id_cols, state_cols; const UnitFileList *u; - max_id_len = strlen("UNIT FILE"); - state_cols = strlen("STATE"); + max_id_len = STRLEN("UNIT FILE"); + state_cols = STRLEN("STATE"); for (u = units; u < units + c; u++) { max_id_len = MAX(max_id_len, strlen(basename(u->path))); @@ -1999,15 +1999,16 @@ static void output_machines_list(struct machine_info *machine_infos, unsigned n) struct machine_info *m; unsigned circle_len = 0, - namelen = sizeof("NAME") - 1, - statelen = sizeof("STATE") - 1, - failedlen = sizeof("FAILED") - 1, - jobslen = sizeof("JOBS") - 1; + namelen = STRLEN("NAME"), + statelen = STRLEN("STATE"), + failedlen = STRLEN("FAILED"), + jobslen = STRLEN("JOBS"); assert(machine_infos || n == 0); for (m = machine_infos; m < machine_infos + n; m++) { - namelen = MAX(namelen, strlen(m->name) + (m->is_host ? sizeof(" (host)") - 1 : 0)); + namelen = MAX(namelen, + strlen(m->name) + (m->is_host ? STRLEN(" (host)") : 0)); statelen = MAX(statelen, strlen_ptr(m->state)); failedlen = MAX(failedlen, DECIMAL_STR_WIDTH(m->n_failed_units)); jobslen = MAX(jobslen, DECIMAL_STR_WIDTH(m->n_jobs)); @@ -2053,7 +2054,8 @@ static void output_machines_list(struct machine_info *machine_infos, unsigned n) if (m->is_host) printf("%-*s (host) %s%-*s%s %s%*" PRIu32 "%s %*" PRIu32 "\n", - (int) (namelen - (sizeof(" (host)")-1)), strna(m->name), + (int) (namelen - (STRLEN(" (host)"))), + strna(m->name), on_state, statelen, strna(m->state), off_state, on_failed, failedlen, m->n_failed_units, off_failed, jobslen, m->n_jobs); @@ -2256,10 +2258,10 @@ static void output_jobs_list(sd_bus *bus, const struct job_info* jobs, unsigned pager_open(arg_no_pager, false); - id_len = strlen("JOB"); - unit_len = strlen("UNIT"); - type_len = strlen("TYPE"); - state_len = strlen("STATE"); + id_len = STRLEN("JOB"); + unit_len = STRLEN("UNIT"); + type_len = STRLEN("TYPE"); + state_len = STRLEN("STATE"); for (j = jobs; j < jobs + n; j++) { uint32_t id = j->id; @@ -6086,7 +6088,7 @@ static int enable_sysv_units(const char *verb, char **args) { if (!p) return log_oom(); - p[strlen(p) - strlen(".service")] = 0; + p[strlen(p) - STRLEN(".service")] = 0; found_sysv = access(p, F_OK) >= 0; if (!found_sysv) continue; diff --git a/src/test/test-fileio.c b/src/test/test-fileio.c index e71beb135a..286867d2dc 100644 --- a/src/test/test-fileio.c +++ b/src/test/test-fileio.c @@ -466,7 +466,7 @@ static void test_write_string_file_no_create(void) { assert_se(write_string_file("/a/file/which/does/not/exists/i/guess", "boohoo", 0) < 0); assert_se(write_string_file(fn, "boohoo", 0) == 0); - assert_se(read(fd, buf, sizeof(buf)) == strlen("boohoo\n")); + assert_se(read(fd, buf, sizeof(buf)) == STRLEN("boohoo\n")); assert_se(streq(buf, "boohoo\n")); unlink(fn); diff --git a/src/test/test-hexdecoct.c b/src/test/test-hexdecoct.c index 7675d0cba7..4f19cb406f 100644 --- a/src/test/test-hexdecoct.c +++ b/src/test/test-hexdecoct.c @@ -107,72 +107,72 @@ static void test_unhexmem(void) { static void test_base32hexmem(void) { char *b32; - b32 = base32hexmem("", strlen(""), true); + b32 = base32hexmem("", STRLEN(""), true); assert_se(b32); assert_se(streq(b32, "")); free(b32); - b32 = base32hexmem("f", strlen("f"), true); + b32 = base32hexmem("f", STRLEN("f"), true); assert_se(b32); assert_se(streq(b32, "CO======")); free(b32); - b32 = base32hexmem("fo", strlen("fo"), true); + b32 = base32hexmem("fo", STRLEN("fo"), true); assert_se(b32); assert_se(streq(b32, "CPNG====")); free(b32); - b32 = base32hexmem("foo", strlen("foo"), true); + b32 = base32hexmem("foo", STRLEN("foo"), true); assert_se(b32); assert_se(streq(b32, "CPNMU===")); free(b32); - b32 = base32hexmem("foob", strlen("foob"), true); + b32 = base32hexmem("foob", STRLEN("foob"), true); assert_se(b32); assert_se(streq(b32, "CPNMUOG=")); free(b32); - b32 = base32hexmem("fooba", strlen("fooba"), true); + b32 = base32hexmem("fooba", STRLEN("fooba"), true); assert_se(b32); assert_se(streq(b32, "CPNMUOJ1")); free(b32); - b32 = base32hexmem("foobar", strlen("foobar"), true); + b32 = base32hexmem("foobar", STRLEN("foobar"), true); assert_se(b32); assert_se(streq(b32, "CPNMUOJ1E8======")); free(b32); - b32 = base32hexmem("", strlen(""), false); + b32 = base32hexmem("", STRLEN(""), false); assert_se(b32); assert_se(streq(b32, "")); free(b32); - b32 = base32hexmem("f", strlen("f"), false); + b32 = base32hexmem("f", STRLEN("f"), false); assert_se(b32); assert_se(streq(b32, "CO")); free(b32); - b32 = base32hexmem("fo", strlen("fo"), false); + b32 = base32hexmem("fo", STRLEN("fo"), false); assert_se(b32); assert_se(streq(b32, "CPNG")); free(b32); - b32 = base32hexmem("foo", strlen("foo"), false); + b32 = base32hexmem("foo", STRLEN("foo"), false); assert_se(b32); assert_se(streq(b32, "CPNMU")); free(b32); - b32 = base32hexmem("foob", strlen("foob"), false); + b32 = base32hexmem("foob", STRLEN("foob"), false); assert_se(b32); assert_se(streq(b32, "CPNMUOG")); free(b32); - b32 = base32hexmem("fooba", strlen("fooba"), false); + b32 = base32hexmem("fooba", STRLEN("fooba"), false); assert_se(b32); assert_se(streq(b32, "CPNMUOJ1")); free(b32); - b32 = base32hexmem("foobar", strlen("foobar"), false); + b32 = base32hexmem("foobar", STRLEN("foobar"), false); assert_se(b32); assert_se(streq(b32, "CPNMUOJ1E8")); free(b32); @@ -182,121 +182,121 @@ static void test_unbase32hexmem(void) { void *mem; size_t len; - assert_se(unbase32hexmem("", strlen(""), true, &mem, &len) == 0); + assert_se(unbase32hexmem("", STRLEN(""), true, &mem, &len) == 0); assert_se(streq(strndupa(mem, len), "")); free(mem); - assert_se(unbase32hexmem("CO======", strlen("CO======"), true, &mem, &len) == 0); + assert_se(unbase32hexmem("CO======", STRLEN("CO======"), true, &mem, &len) == 0); assert_se(streq(strndupa(mem, len), "f")); free(mem); - assert_se(unbase32hexmem("CPNG====", strlen("CPNG===="), true, &mem, &len) == 0); + assert_se(unbase32hexmem("CPNG====", STRLEN("CPNG===="), true, &mem, &len) == 0); assert_se(streq(strndupa(mem, len), "fo")); free(mem); - assert_se(unbase32hexmem("CPNMU===", strlen("CPNMU==="), true, &mem, &len) == 0); + assert_se(unbase32hexmem("CPNMU===", STRLEN("CPNMU==="), true, &mem, &len) == 0); assert_se(streq(strndupa(mem, len), "foo")); free(mem); - assert_se(unbase32hexmem("CPNMUOG=", strlen("CPNMUOG="), true, &mem, &len) == 0); + assert_se(unbase32hexmem("CPNMUOG=", STRLEN("CPNMUOG="), true, &mem, &len) == 0); assert_se(streq(strndupa(mem, len), "foob")); free(mem); - assert_se(unbase32hexmem("CPNMUOJ1", strlen("CPNMUOJ1"), true, &mem, &len) == 0); + assert_se(unbase32hexmem("CPNMUOJ1", STRLEN("CPNMUOJ1"), true, &mem, &len) == 0); assert_se(streq(strndupa(mem, len), "fooba")); free(mem); - assert_se(unbase32hexmem("CPNMUOJ1E8======", strlen("CPNMUOJ1E8======"), true, &mem, &len) == 0); + assert_se(unbase32hexmem("CPNMUOJ1E8======", STRLEN("CPNMUOJ1E8======"), true, &mem, &len) == 0); assert_se(streq(strndupa(mem, len), "foobar")); free(mem); - assert_se(unbase32hexmem("A", strlen("A"), true, &mem, &len) == -EINVAL); - assert_se(unbase32hexmem("A=======", strlen("A======="), true, &mem, &len) == -EINVAL); - assert_se(unbase32hexmem("AAA=====", strlen("AAA====="), true, &mem, &len) == -EINVAL); - assert_se(unbase32hexmem("AAAAAA==", strlen("AAAAAA=="), true, &mem, &len) == -EINVAL); - assert_se(unbase32hexmem("AB======", strlen("AB======"), true, &mem, &len) == -EINVAL); - assert_se(unbase32hexmem("AAAB====", strlen("AAAB===="), true, &mem, &len) == -EINVAL); - assert_se(unbase32hexmem("AAAAB===", strlen("AAAAB==="), true, &mem, &len) == -EINVAL); - assert_se(unbase32hexmem("AAAAAAB=", strlen("AAAAAAB="), true, &mem, &len) == -EINVAL); - - assert_se(unbase32hexmem("XPNMUOJ1", strlen("CPNMUOJ1"), true, &mem, &len) == -EINVAL); - assert_se(unbase32hexmem("CXNMUOJ1", strlen("CPNMUOJ1"), true, &mem, &len) == -EINVAL); - assert_se(unbase32hexmem("CPXMUOJ1", strlen("CPNMUOJ1"), true, &mem, &len) == -EINVAL); - assert_se(unbase32hexmem("CPNXUOJ1", strlen("CPNMUOJ1"), true, &mem, &len) == -EINVAL); - assert_se(unbase32hexmem("CPNMXOJ1", strlen("CPNMUOJ1"), true, &mem, &len) == -EINVAL); - assert_se(unbase32hexmem("CPNMUXJ1", strlen("CPNMUOJ1"), true, &mem, &len) == -EINVAL); - assert_se(unbase32hexmem("CPNMUOX1", strlen("CPNMUOJ1"), true, &mem, &len) == -EINVAL); - assert_se(unbase32hexmem("CPNMUOJX", strlen("CPNMUOJ1"), true, &mem, &len) == -EINVAL); - - assert_se(unbase32hexmem("", strlen(""), false, &mem, &len) == 0); + assert_se(unbase32hexmem("A", STRLEN("A"), true, &mem, &len) == -EINVAL); + assert_se(unbase32hexmem("A=======", STRLEN("A======="), true, &mem, &len) == -EINVAL); + assert_se(unbase32hexmem("AAA=====", STRLEN("AAA====="), true, &mem, &len) == -EINVAL); + assert_se(unbase32hexmem("AAAAAA==", STRLEN("AAAAAA=="), true, &mem, &len) == -EINVAL); + assert_se(unbase32hexmem("AB======", STRLEN("AB======"), true, &mem, &len) == -EINVAL); + assert_se(unbase32hexmem("AAAB====", STRLEN("AAAB===="), true, &mem, &len) == -EINVAL); + assert_se(unbase32hexmem("AAAAB===", STRLEN("AAAAB==="), true, &mem, &len) == -EINVAL); + assert_se(unbase32hexmem("AAAAAAB=", STRLEN("AAAAAAB="), true, &mem, &len) == -EINVAL); + + assert_se(unbase32hexmem("XPNMUOJ1", STRLEN("CPNMUOJ1"), true, &mem, &len) == -EINVAL); + assert_se(unbase32hexmem("CXNMUOJ1", STRLEN("CPNMUOJ1"), true, &mem, &len) == -EINVAL); + assert_se(unbase32hexmem("CPXMUOJ1", STRLEN("CPNMUOJ1"), true, &mem, &len) == -EINVAL); + assert_se(unbase32hexmem("CPNXUOJ1", STRLEN("CPNMUOJ1"), true, &mem, &len) == -EINVAL); + assert_se(unbase32hexmem("CPNMXOJ1", STRLEN("CPNMUOJ1"), true, &mem, &len) == -EINVAL); + assert_se(unbase32hexmem("CPNMUXJ1", STRLEN("CPNMUOJ1"), true, &mem, &len) == -EINVAL); + assert_se(unbase32hexmem("CPNMUOX1", STRLEN("CPNMUOJ1"), true, &mem, &len) == -EINVAL); + assert_se(unbase32hexmem("CPNMUOJX", STRLEN("CPNMUOJ1"), true, &mem, &len) == -EINVAL); + + assert_se(unbase32hexmem("", STRLEN(""), false, &mem, &len) == 0); assert_se(streq(strndupa(mem, len), "")); free(mem); - assert_se(unbase32hexmem("CO", strlen("CO"), false, &mem, &len) == 0); + assert_se(unbase32hexmem("CO", STRLEN("CO"), false, &mem, &len) == 0); assert_se(streq(strndupa(mem, len), "f")); free(mem); - assert_se(unbase32hexmem("CPNG", strlen("CPNG"), false, &mem, &len) == 0); + assert_se(unbase32hexmem("CPNG", STRLEN("CPNG"), false, &mem, &len) == 0); assert_se(streq(strndupa(mem, len), "fo")); free(mem); - assert_se(unbase32hexmem("CPNMU", strlen("CPNMU"), false, &mem, &len) == 0); + assert_se(unbase32hexmem("CPNMU", STRLEN("CPNMU"), false, &mem, &len) == 0); assert_se(streq(strndupa(mem, len), "foo")); free(mem); - assert_se(unbase32hexmem("CPNMUOG", strlen("CPNMUOG"), false, &mem, &len) == 0); + assert_se(unbase32hexmem("CPNMUOG", STRLEN("CPNMUOG"), false, &mem, &len) == 0); assert_se(streq(strndupa(mem, len), "foob")); free(mem); - assert_se(unbase32hexmem("CPNMUOJ1", strlen("CPNMUOJ1"), false, &mem, &len) == 0); + assert_se(unbase32hexmem("CPNMUOJ1", STRLEN("CPNMUOJ1"), false, &mem, &len) == 0); assert_se(streq(strndupa(mem, len), "fooba")); free(mem); - assert_se(unbase32hexmem("CPNMUOJ1E8", strlen("CPNMUOJ1E8"), false, &mem, &len) == 0); + assert_se(unbase32hexmem("CPNMUOJ1E8", STRLEN("CPNMUOJ1E8"), false, &mem, &len) == 0); assert_se(streq(strndupa(mem, len), "foobar")); free(mem); - assert_se(unbase32hexmem("CPNMUOG=", strlen("CPNMUOG="), false, &mem, &len) == -EINVAL); - assert_se(unbase32hexmem("CPNMUOJ1E8======", strlen("CPNMUOJ1E8======"), false, &mem, &len) == -EINVAL); - assert_se(unbase32hexmem("A", strlen("A"), false, &mem, &len) == -EINVAL); - assert_se(unbase32hexmem("A", strlen("A"), false, &mem, &len) == -EINVAL); - assert_se(unbase32hexmem("AAA", strlen("AAA"), false, &mem, &len) == -EINVAL); - assert_se(unbase32hexmem("AAAAAA", strlen("AAAAAA"), false, &mem, &len) == -EINVAL); - assert_se(unbase32hexmem("AB", strlen("AB"), false, &mem, &len) == -EINVAL); - assert_se(unbase32hexmem("AAAB", strlen("AAAB"), false, &mem, &len) == -EINVAL); - assert_se(unbase32hexmem("AAAAB", strlen("AAAAB"), false, &mem, &len) == -EINVAL); - assert_se(unbase32hexmem("AAAAAAB", strlen("AAAAAAB"), false, &mem, &len) == -EINVAL); + assert_se(unbase32hexmem("CPNMUOG=", STRLEN("CPNMUOG="), false, &mem, &len) == -EINVAL); + assert_se(unbase32hexmem("CPNMUOJ1E8======", STRLEN("CPNMUOJ1E8======"), false, &mem, &len) == -EINVAL); + assert_se(unbase32hexmem("A", STRLEN("A"), false, &mem, &len) == -EINVAL); + assert_se(unbase32hexmem("A", STRLEN("A"), false, &mem, &len) == -EINVAL); + assert_se(unbase32hexmem("AAA", STRLEN("AAA"), false, &mem, &len) == -EINVAL); + assert_se(unbase32hexmem("AAAAAA", STRLEN("AAAAAA"), false, &mem, &len) == -EINVAL); + assert_se(unbase32hexmem("AB", STRLEN("AB"), false, &mem, &len) == -EINVAL); + assert_se(unbase32hexmem("AAAB", STRLEN("AAAB"), false, &mem, &len) == -EINVAL); + assert_se(unbase32hexmem("AAAAB", STRLEN("AAAAB"), false, &mem, &len) == -EINVAL); + assert_se(unbase32hexmem("AAAAAAB", STRLEN("AAAAAAB"), false, &mem, &len) == -EINVAL); } /* https://tools.ietf.org/html/rfc4648#section-10 */ static void test_base64mem(void) { char *b64; - assert_se(base64mem("", strlen(""), &b64) == 0); + assert_se(base64mem("", STRLEN(""), &b64) == 0); assert_se(streq(b64, "")); free(b64); - assert_se(base64mem("f", strlen("f"), &b64) == 4); + assert_se(base64mem("f", STRLEN("f"), &b64) == 4); assert_se(streq(b64, "Zg==")); free(b64); - assert_se(base64mem("fo", strlen("fo"), &b64) == 4); + assert_se(base64mem("fo", STRLEN("fo"), &b64) == 4); assert_se(streq(b64, "Zm8=")); free(b64); - assert_se(base64mem("foo", strlen("foo"), &b64) == 4); + assert_se(base64mem("foo", STRLEN("foo"), &b64) == 4); assert_se(streq(b64, "Zm9v")); free(b64); - assert_se(base64mem("foob", strlen("foob"), &b64) == 8); + assert_se(base64mem("foob", STRLEN("foob"), &b64) == 8); assert_se(streq(b64, "Zm9vYg==")); free(b64); - assert_se(base64mem("fooba", strlen("fooba"), &b64) == 8); + assert_se(base64mem("fooba", STRLEN("fooba"), &b64) == 8); assert_se(streq(b64, "Zm9vYmE=")); free(b64); - assert_se(base64mem("foobar", strlen("foobar"), &b64) == 8); + assert_se(base64mem("foobar", STRLEN("foobar"), &b64) == 8); assert_se(streq(b64, "Zm9vYmFy")); free(b64); } diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c index 9b65f103d7..a38f917961 100644 --- a/src/test/test-process-util.c +++ b/src/test/test-process-util.c @@ -49,7 +49,7 @@ static void test_get_process_comm(pid_t pid) { struct stat st; _cleanup_free_ char *a = NULL, *c = NULL, *d = NULL, *f = NULL, *i = NULL; _cleanup_free_ char *env = NULL; - char path[strlen("/proc//comm") + DECIMAL_STR_MAX(pid_t)]; + char path[STRLEN("/proc//comm") + DECIMAL_STR_MAX(pid_t)]; pid_t e; uid_t u; gid_t g; @@ -382,7 +382,7 @@ static void test_rename_process_now(const char *p, int ret) { /* we cannot expect cmdline to be renamed properly without privileges */ if (geteuid() == 0) { log_info("cmdline = <%s>", cmdline); - assert_se(strneq(p, cmdline, strlen("test-process-util"))); + assert_se(strneq(p, cmdline, STRLEN("test-process-util"))); assert_se(startswith(p, cmdline)); } else log_info("cmdline = <%s> (not verified)", cmdline); diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 2344189426..a7ce1a8049 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -777,7 +777,7 @@ static int path_set_perms(Item *i, const char *path) { if (S_ISLNK(st.st_mode)) log_debug("Skipping mode and owner fix for symlink %s.", path); else { - char fn[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(int)]; + char fn[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int)]; xsprintf(fn, "/proc/self/fd/%i", fd); /* not using i->path directly because it may be a glob */ @@ -946,7 +946,7 @@ static int path_set_acl(const char *path, const char *pretty, acl_type_t type, a static int path_set_acls(Item *item, const char *path) { int r = 0; #if HAVE_ACL - char fn[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(int)]; + char fn[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int)]; _cleanup_close_ int fd = -1; struct stat st; diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c index 07064e2597..8f7c28f03d 100644 --- a/src/udev/udev-event.c +++ b/src/udev/udev-event.c @@ -231,7 +231,7 @@ static size_t subst_format_var(struct udev_event *event, struct udev_device *dev break; devnode = udev_device_get_devnode(dev_parent); if (devnode != NULL) - l = strpcpy(&s, l, devnode + strlen("/dev/")); + l = strpcpy(&s, l, devnode + STRLEN("/dev/")); break; } case SUBST_DEVNODE: @@ -242,7 +242,8 @@ static size_t subst_format_var(struct udev_event *event, struct udev_device *dev if (event->name != NULL) l = strpcpy(&s, l, event->name); else if (udev_device_get_devnode(dev) != NULL) - l = strpcpy(&s, l, udev_device_get_devnode(dev) + strlen("/dev/")); + l = strpcpy(&s, l, + udev_device_get_devnode(dev) + STRLEN("/dev/")); else l = strpcpy(&s, l, udev_device_get_sysname(dev)); break; @@ -252,9 +253,12 @@ static size_t subst_format_var(struct udev_event *event, struct udev_device *dev list_entry = udev_device_get_devlinks_list_entry(dev); if (list_entry == NULL) break; - l = strpcpy(&s, l, udev_list_entry_get_name(list_entry) + strlen("/dev/")); + l = strpcpy(&s, l, + udev_list_entry_get_name(list_entry) + STRLEN("/dev/")); udev_list_entry_foreach(list_entry, udev_list_entry_get_next(list_entry)) - l = strpcpyl(&s, l, " ", udev_list_entry_get_name(list_entry) + strlen("/dev/"), NULL); + l = strpcpyl(&s, l, " ", + udev_list_entry_get_name(list_entry) + STRLEN("/dev/"), + NULL); break; } case SUBST_ROOT: diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c index ef893247ad..bb845889cc 100644 --- a/src/udev/udev-node.c +++ b/src/udev/udev-node.c @@ -187,7 +187,7 @@ static void link_update(struct udev_device *dev, const char *slink, bool add) { const char *target; char buf[UTIL_PATH_SIZE]; - util_path_encode(slink + strlen("/dev"), name_enc, sizeof(name_enc)); + util_path_encode(slink + STRLEN("/dev"), name_enc, sizeof(name_enc)); strscpyl(dirname, sizeof(dirname), "/run/udev/links/", name_enc, NULL); strscpyl(filename, sizeof(filename), dirname, "/", udev_device_get_id_filename(dev), NULL); diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index e9588abd69..f4708bb066 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -1098,7 +1098,8 @@ static void add_rule(struct udev_rules *rules, char *line, rule_add_key(&rule_tmp, TK_M_DRIVER, op, value, NULL); } else if (startswith(key, "ATTR{")) { - attr = get_key_attribute(rules->udev, key + strlen("ATTR")); + attr = get_key_attribute(rules->udev, + key + STRLEN("ATTR")); if (attr == NULL) LOG_AND_RETURN("error parsing %s attribute", "ATTR"); @@ -1111,7 +1112,8 @@ static void add_rule(struct udev_rules *rules, char *line, rule_add_key(&rule_tmp, TK_A_ATTR, op, value, attr); } else if (startswith(key, "SYSCTL{")) { - attr = get_key_attribute(rules->udev, key + strlen("SYSCTL")); + attr = get_key_attribute(rules->udev, + key + STRLEN("SYSCTL")); if (attr == NULL) LOG_AND_RETURN("error parsing %s attribute", "ATTR"); @@ -1124,7 +1126,8 @@ static void add_rule(struct udev_rules *rules, char *line, rule_add_key(&rule_tmp, TK_A_SYSCTL, op, value, attr); } else if (startswith(key, "SECLABEL{")) { - attr = get_key_attribute(rules->udev, key + strlen("SECLABEL")); + attr = get_key_attribute(rules->udev, + key + STRLEN("SECLABEL")); if (attr == NULL) LOG_AND_RETURN("error parsing %s attribute", "SECLABEL"); @@ -1155,7 +1158,8 @@ static void add_rule(struct udev_rules *rules, char *line, if (op > OP_MATCH_MAX) LOG_AND_RETURN("invalid %s operation", "ATTRS"); - attr = get_key_attribute(rules->udev, key + strlen("ATTRS")); + attr = get_key_attribute(rules->udev, + key + STRLEN("ATTRS")); if (attr == NULL) LOG_AND_RETURN("error parsing %s attribute", "ATTRS"); @@ -1172,7 +1176,8 @@ static void add_rule(struct udev_rules *rules, char *line, rule_add_key(&rule_tmp, TK_M_TAGS, op, value, NULL); } else if (startswith(key, "ENV{")) { - attr = get_key_attribute(rules->udev, key + strlen("ENV")); + attr = get_key_attribute(rules->udev, + key + STRLEN("ENV")); if (attr == NULL) LOG_AND_RETURN("error parsing %s attribute", "ENV"); @@ -1218,7 +1223,8 @@ static void add_rule(struct udev_rules *rules, char *line, rule_add_key(&rule_tmp, TK_M_RESULT, op, value, NULL); } else if (startswith(key, "IMPORT")) { - attr = get_key_attribute(rules->udev, key + strlen("IMPORT")); + attr = get_key_attribute(rules->udev, + key + STRLEN("IMPORT")); if (attr == NULL) { LOG_RULE_WARNING("ignoring IMPORT{} with missing type"); continue; @@ -1262,7 +1268,8 @@ static void add_rule(struct udev_rules *rules, char *line, if (op > OP_MATCH_MAX) LOG_AND_RETURN("invalid %s operation", "TEST"); - attr = get_key_attribute(rules->udev, key + strlen("TEST")); + attr = get_key_attribute(rules->udev, + key + STRLEN("TEST")); if (attr != NULL) { mode = strtol(attr, NULL, 8); rule_add_key(&rule_tmp, TK_M_TEST, op, value, &mode); @@ -1270,7 +1277,8 @@ static void add_rule(struct udev_rules *rules, char *line, rule_add_key(&rule_tmp, TK_M_TEST, op, value, NULL); } else if (startswith(key, "RUN")) { - attr = get_key_attribute(rules->udev, key + strlen("RUN")); + attr = get_key_attribute(rules->udev, + key + STRLEN("RUN")); if (attr == NULL) attr = "program"; if (op == OP_REMOVE) @@ -1389,14 +1397,14 @@ static void add_rule(struct udev_rules *rules, char *line, pos = strstr(value, "link_priority="); if (pos != NULL) { - int prio = atoi(pos + strlen("link_priority=")); + int prio = atoi(pos + STRLEN("link_priority=")); rule_add_key(&rule_tmp, TK_A_DEVLINK_PRIO, op, NULL, &prio); } pos = strstr(value, "string_escape="); if (pos != NULL) { - pos += strlen("string_escape="); + pos += STRLEN("string_escape="); if (startswith(pos, "none")) rule_add_key(&rule_tmp, TK_A_STRING_ESCAPE_NONE, op, NULL, NULL); else if (startswith(pos, "replace")) @@ -1423,7 +1431,7 @@ static void add_rule(struct udev_rules *rules, char *line, pos = strstr(value, "static_node="); if (pos != NULL) { - pos += strlen("static_node="); + pos += STRLEN("static_node="); rule_add_key(&rule_tmp, TK_A_STATIC_NODE, op, pos, NULL); rule_tmp.rule.rule.has_static_node = true; } @@ -1784,7 +1792,7 @@ void udev_rules_apply_to_event(struct udev_rules *rules, udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(event->dev)) { const char *devlink; - devlink = udev_list_entry_get_name(list_entry) + strlen("/dev/"); + devlink = udev_list_entry_get_name(list_entry) + STRLEN("/dev/"); if (match_key(rules, cur, devlink) == 0) { match = true; break; @@ -2295,7 +2303,7 @@ void udev_rules_apply_to_event(struct udev_rules *rules, log_debug("%i character(s) replaced", count); } if (major(udev_device_get_devnum(event->dev)) && - !streq(name_str, udev_device_get_devnode(event->dev) + strlen("/dev/"))) { + !streq(name_str, udev_device_get_devnode(event->dev) + STRLEN("/dev/"))) { log_error("NAME=\"%s\" ignored, kernel device nodes cannot be renamed; please fix it in %s:%u\n", name, rules_str(rules, rule->rule.filename_off), diff --git a/src/udev/udevadm-info.c b/src/udev/udevadm-info.c index 396ccfb4e2..580e95095b 100644 --- a/src/udev/udevadm-info.c +++ b/src/udev/udevadm-info.c @@ -137,14 +137,15 @@ static void print_record(struct udev_device *device) { str = udev_device_get_devnode(device); if (str != NULL) - printf("N: %s\n", str + strlen("/dev/")); + printf("N: %s\n", str + STRLEN("/dev/")); i = udev_device_get_devlink_priority(device); if (i != 0) printf("L: %i\n", i); udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(device)) - printf("S: %s\n", udev_list_entry_get_name(list_entry) + strlen("/dev/")); + printf("S: %s\n", + udev_list_entry_get_name(list_entry) + STRLEN("/dev/")); udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(device)) printf("E: %s=%s\n", @@ -412,7 +413,8 @@ static int uinfo(struct udev *udev, int argc, char *argv[]) { if (root) printf("%s\n", udev_device_get_devnode(device)); else - printf("%s\n", udev_device_get_devnode(device) + strlen("/dev/")); + printf("%s\n", + udev_device_get_devnode(device) + STRLEN("/dev/")); break; } case QUERY_SYMLINK: @@ -421,7 +423,8 @@ static int uinfo(struct udev *udev, int argc, char *argv[]) { if (root) printf("%s", udev_list_entry_get_name(list_entry)); else - printf("%s", udev_list_entry_get_name(list_entry) + strlen("/dev/")); + printf("%s", + udev_list_entry_get_name(list_entry) + STRLEN("/dev/")); list_entry = udev_list_entry_get_next(list_entry); if (list_entry != NULL) printf(" "); |