diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-04-27 14:09:31 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2018-04-27 14:29:06 +0200 |
commit | da6053d0a7c16795e7fac1f9ba6694863918a597 (patch) | |
tree | 0bf9555c57e4770f9ac3c189fbfdddc8265432d7 | |
parent | test: add tests for %j and %J specifier in test-execute (#8838) (diff) | |
download | systemd-da6053d0a7c16795e7fac1f9ba6694863918a597.tar.gz systemd-da6053d0a7c16795e7fac1f9ba6694863918a597.tar.bz2 systemd-da6053d0a7c16795e7fac1f9ba6694863918a597.zip |
tree-wide: be more careful with the type of array sizes
Previously we were a bit sloppy with the index and size types of arrays,
we'd regularly use unsigned. While I don't think this ever resulted in
real issues I think we should be more careful there and follow a
stricter regime: unless there's a strong reason not to use size_t for
array sizes and indexes, size_t it should be. Any allocations we do
ultimately will use size_t anyway, and converting forth and back between
unsigned and size_t will always be a source of problems.
Note that on 32bit machines "unsigned" and "size_t" are equivalent, and
on 64bit machines our arrays shouldn't grow that large anyway, and if
they do we have a problem, however that kind of overly large allocation
we have protections for usually, but for overflows we do not have that
so much, hence let's add it.
So yeah, it's a story of the current code being already "good enough",
but I think some extra type hygiene is better.
This patch tries to be comprehensive, but it probably isn't and I missed
a few cases. But I guess we can cover that later as we notice it. Among
smaller fixes, this changes:
1. strv_length()' return type becomes size_t
2. the unit file changes array size becomes size_t
3. DNS answer and query array sizes become size_t
Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=76745
57 files changed, 288 insertions, 290 deletions
diff --git a/src/activate/activate.c b/src/activate/activate.c index d598965b4..9d027432f 100644 --- a/src/activate/activate.c +++ b/src/activate/activate.c @@ -116,11 +116,11 @@ static int open_sockets(int *epoll_fd, bool accept) { return count; } -static int exec_process(const char* name, char **argv, char **env, int start_fd, int n_fds) { +static int exec_process(const char* name, char **argv, char **env, int start_fd, size_t n_fds) { _cleanup_strv_free_ char **envp = NULL; _cleanup_free_ char *joined = NULL; - unsigned n_env = 0, length; + size_t n_env = 0, length; const char *tocopy; char **s; int r; @@ -199,7 +199,7 @@ static int exec_process(const char* name, char **argv, char **env, int start_fd, start_fd = SD_LISTEN_FDS_START; } - if (asprintf((char**)(envp + n_env++), "LISTEN_FDS=%i", n_fds) < 0) + if (asprintf((char**)(envp + n_env++), "LISTEN_FDS=%zu", n_fds) < 0) return log_oom(); if (asprintf((char**)(envp + n_env++), "LISTEN_PID=" PID_FMT, getpid_cached()) < 0) @@ -209,18 +209,18 @@ static int exec_process(const char* name, char **argv, char **env, int start_fd, _cleanup_free_ char *names = NULL; size_t len; char *e; - int i; len = strv_length(arg_fdnames); - if (len == 1) + if (len == 1) { + size_t i; + for (i = 1; i < n_fds; i++) { r = strv_extend(&arg_fdnames, arg_fdnames[0]); if (r < 0) return log_error_errno(r, "Failed to extend strv: %m"); } - else if (len != (unsigned) n_fds) - log_warning("The number of fd names is different than number of fds: %zu vs %d", - len, n_fds); + } else if (len != n_fds) + log_warning("The number of fd names is different than number of fds: %zu vs %zu", len, n_fds); names = strv_join(arg_fdnames, ":"); if (!names) @@ -501,7 +501,7 @@ int main(int argc, char **argv, char **envp) { break; } - exec_process(argv[optind], argv + optind, envp, SD_LISTEN_FDS_START, n); + exec_process(argv[optind], argv + optind, envp, SD_LISTEN_FDS_START, (size_t) n); return EXIT_SUCCESS; } diff --git a/src/basic/calendarspec.c b/src/basic/calendarspec.c index 20db9181d..24867f807 100644 --- a/src/basic/calendarspec.c +++ b/src/basic/calendarspec.c @@ -84,8 +84,8 @@ static int component_compare(const void *_a, const void *_b) { } static void normalize_chain(CalendarComponent **c) { - unsigned n = 0, k; CalendarComponent **b, *i, **j, *next; + size_t n = 0, k; assert(c); @@ -420,7 +420,7 @@ static int parse_weekdays(const char **p, CalendarSpec *c) { assert(c); for (;;) { - unsigned i; + size_t i; for (i = 0; i < ELEMENTSOF(day_nr); i++) { size_t skip; diff --git a/src/basic/conf-files.c b/src/basic/conf-files.c index 8e0fb06ad..b5cad5a6e 100644 --- a/src/basic/conf-files.c +++ b/src/basic/conf-files.c @@ -152,8 +152,8 @@ int conf_files_insert(char ***strv, const char *root, char **dirs, const char *p * - do nothing if our new entry matches the existing entry, * - replace the existing entry if our new entry has higher priority. */ + size_t i; char *t; - unsigned i; int r; for (i = 0; i < strv_length(*strv); i++) { diff --git a/src/basic/env-util.c b/src/basic/env-util.c index 105fa7973..0ebf66c57 100644 --- a/src/basic/env-util.c +++ b/src/basic/env-util.c @@ -196,11 +196,11 @@ static int env_append(char **r, char ***k, char **a) { return 0; } -char **strv_env_merge(unsigned n_lists, ...) { +char **strv_env_merge(size_t n_lists, ...) { size_t n = 0; char **l, **k, **r; va_list ap; - unsigned i; + size_t i; /* Merges an arbitrary number of environment sets */ @@ -275,7 +275,7 @@ static bool env_entry_has_name(const char *entry, const char *name) { return *t == '='; } -char **strv_env_delete(char **x, unsigned n_lists, ...) { +char **strv_env_delete(char **x, size_t n_lists, ...) { size_t n, i = 0; char **k, **r; va_list ap; @@ -290,7 +290,7 @@ char **strv_env_delete(char **x, unsigned n_lists, ...) { return NULL; STRV_FOREACH(k, x) { - unsigned v; + size_t v; va_start(ap, n_lists); for (v = 0; v < n_lists; v++) { @@ -676,7 +676,7 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) { char **replace_env_argv(char **argv, char **env) { char **ret, **i; - unsigned k = 0, l = 0; + size_t k = 0, l = 0; l = strv_length(argv); @@ -690,7 +690,7 @@ char **replace_env_argv(char **argv, char **env) { if ((*i)[0] == '$' && !IN_SET((*i)[1], '{', '$')) { char *e; char **w, **m = NULL; - unsigned q; + size_t q; e = strv_env_get(env, *i+1); if (e) { diff --git a/src/basic/env-util.h b/src/basic/env-util.h index 5aa352509..3d7e14ccb 100644 --- a/src/basic/env-util.h +++ b/src/basic/env-util.h @@ -37,8 +37,8 @@ char **strv_env_clean_with_callback(char **l, void (*invalid_callback)(const cha bool strv_env_name_is_valid(char **l); bool strv_env_name_or_assignment_is_valid(char **l); -char **strv_env_merge(unsigned n_lists, ...); -char **strv_env_delete(char **x, unsigned n_lists, ...); /* New copy */ +char **strv_env_merge(size_t n_lists, ...); +char **strv_env_delete(char **x, size_t n_lists, ...); /* New copy */ char **strv_env_set(char **x, const char *p); /* New copy ... */ char **strv_env_unset(char **l, const char *p); /* In place ... */ diff --git a/src/basic/escape.c b/src/basic/escape.c index 8b39d53f8..fe951e3db 100644 --- a/src/basic/escape.c +++ b/src/basic/escape.c @@ -188,7 +188,7 @@ int cunescape_one(const char *p, size_t length, char32_t *ret, bool *eight_bit) /* C++11 style 16bit unicode */ int a[4]; - unsigned i; + size_t i; uint32_t c; if (length != (size_t) -1 && length < 5) @@ -215,7 +215,7 @@ int cunescape_one(const char *p, size_t length, char32_t *ret, bool *eight_bit) /* C++11 style 32bit unicode */ int a[8]; - unsigned i; + size_t i; char32_t c; if (length != (size_t) -1 && length < 9) diff --git a/src/basic/fd-util.c b/src/basic/fd-util.c index 1159f8307..4b3e7ed55 100644 --- a/src/basic/fd-util.c +++ b/src/basic/fd-util.c @@ -85,8 +85,8 @@ void safe_close_pair(int p[]) { p[1] = safe_close(p[1]); } -void close_many(const int fds[], unsigned n_fd) { - unsigned i; +void close_many(const int fds[], size_t n_fd) { + size_t i; assert(fds || n_fd <= 0); @@ -178,8 +178,8 @@ int fd_cloexec(int fd, bool cloexec) { return 0; } -_pure_ static bool fd_in_set(int fd, const int fdset[], unsigned n_fdset) { - unsigned i; +_pure_ static bool fd_in_set(int fd, const int fdset[], size_t n_fdset) { + size_t i; assert(n_fdset == 0 || fdset); @@ -190,7 +190,7 @@ _pure_ static bool fd_in_set(int fd, const int fdset[], unsigned n_fdset) { return false; } -int close_all_fds(const int except[], unsigned n_except) { +int close_all_fds(const int except[], size_t n_except) { _cleanup_closedir_ DIR *d = NULL; struct dirent *de; int r = 0; diff --git a/src/basic/fd-util.h b/src/basic/fd-util.h index ded022f73..89c3f34c7 100644 --- a/src/basic/fd-util.h +++ b/src/basic/fd-util.h @@ -29,7 +29,7 @@ static inline int safe_close_above_stdio(int fd) { return safe_close(fd); } -void close_many(const int fds[], unsigned n_fd); +void close_many(const int fds[], size_t n_fd); int fclose_nointr(FILE *f); FILE* safe_fclose(FILE *f); @@ -59,7 +59,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(DIR*, closedir); int fd_nonblock(int fd, bool nonblock); int fd_cloexec(int fd, bool cloexec); -int close_all_fds(const int except[], unsigned n_except); +int close_all_fds(const int except[], size_t n_except); int same_fd(int a, int b); diff --git a/src/basic/io-util.h b/src/basic/io-util.h index c34d97c65..e4717b6f3 100644 --- a/src/basic/io-util.h +++ b/src/basic/io-util.h @@ -28,9 +28,8 @@ int fd_wait_for_event(int fd, int event, usec_t timeout); ssize_t sparse_write(int fd, const void *p, size_t sz, size_t run_length); -static inline size_t IOVEC_TOTAL_SIZE(const struct iovec *i, unsigned n) { - unsigned j; - size_t r = 0; +static inline size_t IOVEC_TOTAL_SIZE(const struct iovec *i, size_t n) { + size_t j, r = 0; for (j = 0; j < n; j++) r += i[j].iov_len; @@ -38,8 +37,8 @@ static inline size_t IOVEC_TOTAL_SIZE(const struct iovec *i, unsigned n) { return r; } -static inline size_t IOVEC_INCREMENT(struct iovec *i, unsigned n, size_t k) { - unsigned j; +static inline size_t IOVEC_INCREMENT(struct iovec *i, size_t n, size_t k) { + size_t j; for (j = 0; j < n; j++) { size_t sub; diff --git a/src/basic/locale-util.c b/src/basic/locale-util.c index 9c3f757da..0a32bca8e 100644 --- a/src/basic/locale-util.c +++ b/src/basic/locale-util.c @@ -71,7 +71,7 @@ static int add_locales_from_archive(Set *locales) { _cleanup_close_ int fd = -1; size_t sz = 0; struct stat st; - unsigned i; + size_t i; int r; fd = open("/usr/lib/locale/locale-archive", O_RDONLY|O_NOCTTY|O_CLOEXEC); diff --git a/src/basic/log.c b/src/basic/log.c index bab61d314..77d016ecb 100644 --- a/src/basic/log.c +++ b/src/basic/log.c @@ -341,8 +341,8 @@ static int write_to_console( char location[256], prefix[1 + DECIMAL_STR_MAX(int) + 2]; struct iovec iovec[6] = {}; - unsigned n = 0; bool highlight; + size_t n = 0; if (console_fd < 0) return 0; diff --git a/src/basic/mempool.c b/src/basic/mempool.c index de04215ee..4be4a3d38 100644 --- a/src/basic/mempool.c +++ b/src/basic/mempool.c @@ -15,12 +15,12 @@ struct pool { struct pool *next; - unsigned n_tiles; - unsigned n_used; + size_t n_tiles; + size_t n_used; }; void* mempool_alloc_tile(struct mempool *mp) { - unsigned i; + size_t i; /* When a tile is released we add it to the list and simply * place the next pointer at its offset 0. */ @@ -38,8 +38,7 @@ void* mempool_alloc_tile(struct mempool *mp) { if (_unlikely_(!mp->first_pool) || _unlikely_(mp->first_pool->n_used >= mp->first_pool->n_tiles)) { - unsigned n; - size_t size; + size_t size, n; struct pool *p; n = mp->first_pool ? mp->first_pool->n_tiles : 0; diff --git a/src/basic/process-util.c b/src/basic/process-util.c index 76bc9a0cb..960920d3d 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -880,7 +880,7 @@ int getenv_for_pid(pid_t pid, const char *field, char **ret) { do { char line[LINE_MAX]; - unsigned i; + size_t i; for (i = 0; i < sizeof(line)-1; i++) { int c; @@ -1375,9 +1375,9 @@ int safe_fork_full( return 0; } -int fork_agent(const char *name, const int except[], unsigned n_except, pid_t *ret_pid, const char *path, ...) { +int fork_agent(const char *name, const int except[], size_t n_except, pid_t *ret_pid, const char *path, ...) { bool stdout_is_tty, stderr_is_tty; - unsigned n, i; + size_t n, i; va_list ap; char **l; int r; diff --git a/src/basic/process-util.h b/src/basic/process-util.h index 49d28cdf4..f8d1b5e3e 100644 --- a/src/basic/process-util.h +++ b/src/basic/process-util.h @@ -171,7 +171,7 @@ static inline int safe_fork(const char *name, ForkFlags flags, pid_t *ret_pid) { return safe_fork_full(name, NULL, 0, flags, ret_pid); } -int fork_agent(const char *name, const int except[], unsigned n_except, pid_t *pid, const char *path, ...); +int fork_agent(const char *name, const int except[], size_t n_except, pid_t *pid, const char *path, ...); #if SIZEOF_PID_T == 4 /* The highest possibly (theoretic) pid_t value on this architecture. */ diff --git a/src/basic/random-util.c b/src/basic/random-util.c index 1623932f1..0750083b8 100644 --- a/src/basic/random-util.c +++ b/src/basic/random-util.c @@ -35,7 +35,7 @@ int acquire_random_bytes(void *p, size_t n, bool high_quality_required) { static int have_syscall = -1; _cleanup_close_ int fd = -1; - unsigned already_done = 0; + size_t already_done = 0; int r; /* Gathers some randomness from the kernel. This call will never block. If diff --git a/src/basic/string-util.h b/src/basic/string-util.h index 4f500c87d..3004b924b 100644 --- a/src/basic/string-util.h +++ b/src/basic/string-util.h @@ -109,7 +109,7 @@ char *strjoin_real(const char *x, ...) _sentinel_; const char *_appendees_[] = { a, __VA_ARGS__ }; \ char *_d_, *_p_; \ size_t _len_ = 0; \ - unsigned _i_; \ + size_t _i_; \ for (_i_ = 0; _i_ < ELEMENTSOF(_appendees_) && _appendees_[_i_]; _i_++) \ _len_ += strlen(_appendees_[_i_]); \ _p_ = _d_ = alloca(_len_ + 1); \ diff --git a/src/basic/strv.c b/src/basic/strv.c index 07ac8834b..cb91f239e 100644 --- a/src/basic/strv.c +++ b/src/basic/strv.c @@ -107,8 +107,8 @@ char **strv_copy(char * const *l) { return r; } -unsigned strv_length(char * const *l) { - unsigned n = 0; +size_t strv_length(char * const *l) { + size_t n = 0; if (!l) return 0; @@ -122,7 +122,7 @@ unsigned strv_length(char * const *l) { char **strv_new_ap(const char *x, va_list ap) { const char *s; char **a; - unsigned n = 0, i = 0; + size_t n = 0, i = 0; va_list aq; /* As a special trick we ignore all listed strings that equal @@ -257,7 +257,7 @@ int strv_extend_strv_concat(char ***a, char **b, const char *suffix) { char **strv_split(const char *s, const char *separator) { const char *word, *state; size_t l; - unsigned n, i; + size_t n, i; char **r; assert(s); @@ -287,7 +287,7 @@ char **strv_split(const char *s, const char *separator) { char **strv_split_newlines(const char *s) { char **l; - unsigned n; + size_t n; assert(s); @@ -380,7 +380,7 @@ char *strv_join(char **l, const char *separator) { int strv_push(char ***l, char *value) { char **c; - unsigned n, m; + size_t n, m; if (!value) return 0; @@ -405,7 +405,7 @@ int strv_push(char ***l, char *value) { int strv_push_pair(char ***l, char *a, char *b) { char **c; - unsigned n, m; + size_t n, m; if (!a && !b) return 0; @@ -431,9 +431,9 @@ int strv_push_pair(char ***l, char *a, char *b) { return 0; } -int strv_insert(char ***l, unsigned position, char *value) { +int strv_insert(char ***l, size_t position, char *value) { char **c; - unsigned n, m, i; + size_t n, m, i; if (!value) return 0; @@ -601,7 +601,7 @@ char **strv_parse_nulstr(const char *s, size_t l) { */ const char *p; - unsigned c = 0, i = 0; + size_t c = 0, i = 0; char **v; assert(s || l <= 0); @@ -765,7 +765,7 @@ int strv_extendf(char ***l, const char *format, ...) { } char **strv_reverse(char **l) { - unsigned n, i; + size_t n, i; n = strv_length(l); if (n <= 1) diff --git a/src/basic/strv.h b/src/basic/strv.h index 79512c0ce..958c5f3a9 100644 --- a/src/basic/strv.h +++ b/src/basic/strv.h @@ -32,7 +32,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(char**, strv_free_erase); void strv_clear(char **l); char **strv_copy(char * const *l); -unsigned strv_length(char * const *l) _pure_; +size_t strv_length(char * const *l) _pure_; int strv_extend_strv(char ***a, char **b, bool filter_duplicates); int strv_extend_strv_concat(char ***a, char **b, const char *suffix); @@ -41,7 +41,7 @@ int strv_extendf(char ***l, const char *format, ...) _printf_(2,0); int strv_extend_front(char ***l, const char *value); int strv_push(char ***l, char *value); int strv_push_pair(char ***l, char *a, char *b); -int strv_insert(char ***l, unsigned position, char *value); +int strv_insert(char ***l, size_t position, char *value); static inline int strv_push_prepend(char ***l, char *value) { return strv_insert(l, 0, value); @@ -113,7 +113,7 @@ void strv_print(char **l); if (!first) \ _l = (char**) &first; \ else { \ - unsigned _n; \ + size_t _n; \ va_list _ap; \ \ _n = 1; \ diff --git a/src/basic/time-util.c b/src/basic/time-util.c index f7067e9d0..0880d00ef 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -434,7 +434,7 @@ char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) { { "us", 1 }, }; - unsigned i; + size_t i; char *p = buf; bool something = false; @@ -612,7 +612,7 @@ static int parse_timestamp_impl(const char *t, usec_t *usec, bool with_tz) { time_t x; usec_t x_usec, plus = 0, minus = 0, ret; int r, weekday = -1, dst = -1; - unsigned i; + size_t i; /* * Allowed syntaxes: @@ -960,7 +960,7 @@ static char* extract_multiplier(char *p, usec_t *multiplier) { { "us", 1ULL }, { "µs", 1ULL }, }; - unsigned i; + size_t i; for (i = 0; i < ELEMENTSOF(table); i++) { char *e; @@ -1134,8 +1134,8 @@ int parse_nsec(const char *t, nsec_t *nsec) { for (;;) { long long l, z = 0; + size_t n = 0, i; char *e; - unsigned i, n = 0; p += strspn(p, WHITESPACE); diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index 2d651a219..5e1741d2b 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -1972,9 +1972,10 @@ static int install_error( sd_bus_error *error, int c, UnitFileChange *changes, - unsigned n_changes) { + size_t n_changes) { + + size_t i; int r; - unsigned i; for (i = 0; i < n_changes; i++) @@ -2030,12 +2031,12 @@ static int reply_unit_file_changes_and_free( sd_bus_message *message, int carries_install_info, UnitFileChange *changes, - unsigned n_changes, + size_t n_changes, sd_bus_error *error) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; bool bad = false, good = false; - unsigned i; + size_t i; int r; if (unit_file_changes_have_modification(changes, n_changes)) { @@ -2096,13 +2097,13 @@ fail: static int method_enable_unit_files_generic( sd_bus_message *message, Manager *m, - int (*call)(UnitFileScope scope, UnitFileFlags flags, const char *root_dir, char *files[], UnitFileChange **changes, unsigned *n_changes), + int (*call)(UnitFileScope scope, UnitFileFlags flags, const char *root_dir, char *files[], UnitFileChange **changes, size_t *n_changes), bool carries_install_info, sd_bus_error *error) { _cleanup_strv_free_ char **l = NULL; UnitFileChange *changes = NULL; - unsigned n_changes = 0; + size_t n_changes = 0; UnitFileFlags flags; int runtime, force, r; @@ -2144,7 +2145,7 @@ static int method_link_unit_files(sd_bus_message *message, void *userdata, sd_bu return method_enable_unit_files_generic(message, userdata, unit_file_link, false, error); } -static int unit_file_preset_without_mode(UnitFileScope scope, UnitFileFlags flags, const char *root_dir, char **files, UnitFileChange **changes, unsigned *n_changes) { +static int unit_file_preset_without_mode(UnitFileScope scope, UnitFileFlags flags, const char *root_dir, char **files, UnitFileChange **changes, size_t *n_changes) { return unit_file_preset(scope, flags, root_dir, files, UNIT_FILE_PRESET_FULL, changes, n_changes); } @@ -2160,7 +2161,7 @@ static int method_preset_unit_files_with_mode(sd_bus_message *message, void *use _cleanup_strv_free_ char **l = NULL; UnitFileChange *changes = NULL; - unsigned n_changes = 0; + size_t n_changes = 0; Manager *m = userdata; UnitFilePresetMode mm; int runtime, force, r; @@ -2204,12 +2205,12 @@ static int method_preset_unit_files_with_mode(sd_bus_message *message, void *use static int method_disable_unit_files_generic( sd_bus_message *message, Manager *m, - int (*call)(UnitFileScope scope, UnitFileFlags flags, const char *root_dir, char *files[], UnitFileChange **changes, unsigned *n_changes), + int (*call)(UnitFileScope scope, UnitFileFlags flags, const char *root_dir, char *files[], UnitFileChange **changes, size_t *n_changes), sd_bus_error *error) { _cleanup_strv_free_ char **l = NULL; UnitFileChange *changes = NULL; - unsigned n_changes = 0; + size_t n_changes = 0; int r, runtime; assert(message); @@ -2247,7 +2248,7 @@ static int method_unmask_unit_files(sd_bus_message *message, void *userdata, sd_ static int method_revert_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { _cleanup_strv_free_ char **l = NULL; UnitFileChange *changes = NULL; - unsigned n_changes = 0; + size_t n_changes = 0; Manager *m = userdata; int r; @@ -2273,7 +2274,7 @@ static int method_revert_unit_files(sd_bus_message *message, void *userdata, sd_ static int method_set_default_target(sd_bus_message *message, void *userdata, sd_bus_error *error) { UnitFileChange *changes = NULL; - unsigned n_changes = 0; + size_t n_changes = 0; Manager *m = userdata; const char *name; int force, r; @@ -2304,7 +2305,7 @@ static int method_set_default_target(sd_bus_message *message, void *userdata, sd static int method_preset_all_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) { UnitFileChange *changes = NULL; - unsigned n_changes = 0; + size_t n_changes = 0; Manager *m = userdata; UnitFilePresetMode mm; const char *mode; @@ -2349,7 +2350,7 @@ static int method_add_dependency_unit_files(sd_bus_message *message, void *userd _cleanup_strv_free_ char **l = NULL; Manager *m = userdata; UnitFileChange *changes = NULL; - unsigned n_changes = 0; + size_t n_changes = 0; int runtime, force, r; char *target, *type; UnitDependency dep; @@ -2388,7 +2389,7 @@ static int method_add_dependency_unit_files(sd_bus_message *message, void *userd static int method_get_unit_file_links(sd_bus_message *message, void *userdata, sd_bus_error *error) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; UnitFileChange *changes = NULL; - unsigned n_changes = 0, i; + size_t n_changes = 0, i; UnitFileFlags flags; const char *name; char **p; diff --git a/src/core/execute.c b/src/core/execute.c index be44166ce..e9d244a9a 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -106,7 +106,7 @@ #define SNDBUF_SIZE (8*1024*1024) -static int shift_fds(int fds[], unsigned n_fds) { +static int shift_fds(int fds[], size_t n_fds) { int start, restart_from; if (n_fds <= 0) @@ -151,8 +151,8 @@ static int shift_fds(int fds[], unsigned n_fds) { return 0; } -static int flags_fds(const int fds[], unsigned n_storage_fds, unsigned n_socket_fds, bool nonblock) { - unsigned i, n_fds; +static int flags_fds(const int fds[], size_t n_storage_fds, size_t n_socket_fds, bool nonblock) { + size_t i, n_fds; int r; n_fds = n_storage_fds + n_socket_fds; @@ -1113,7 +1113,7 @@ static int setup_pam( gid_t gid, const char *tty, char ***env, - int fds[], unsigned n_fds) { + int fds[], size_t n_fds) { #if HAVE_PAM @@ -1596,7 +1596,7 @@ static int build_environment( const Unit *u, const ExecContext *c, const ExecParameters *p, - unsigned n_fds, + size_t n_fds, const char *home, const char *username, const char *shell, @@ -1605,7 +1605,7 @@ static int build_environment( char ***ret) { _cleanup_strv_free_ char **our_env = NULL; - unsigned n_env = 0; + size_t n_env = 0; char *x; assert(u); @@ -1623,7 +1623,7 @@ static int build_environment( return -ENOMEM; our_env[n_env++] = x; - if (asprintf(&x, "LISTEN_FDS=%u", n_fds) < 0) + if (asprintf(&x, "LISTEN_FDS=%zu", n_fds) < 0) return -ENOMEM; our_env[n_env++] = x; @@ -2152,12 +2152,12 @@ static int compile_bind_mounts( const ExecContext *context, const ExecParameters *params, BindMount **ret_bind_mounts, - unsigned *ret_n_bind_mounts, + size_t *ret_n_bind_mounts, char ***ret_empty_directories) { _cleanup_strv_free_ char **empty_directories = NULL; BindMount *bind_mounts; - unsigned n, h = 0, i; + size_t n, h = 0, i; ExecDirectoryType t; int r; @@ -2303,7 +2303,7 @@ static int apply_mount_namespace( }; bool needs_sandboxing; BindMount *bind_mounts = NULL; - unsigned n_bind_mounts = 0; + size_t n_bind_mounts = 0; int r; assert(context); @@ -2526,7 +2526,7 @@ out: return r; } -static void append_socket_pair(int *array, unsigned *n, const int pair[2]) { +static void append_socket_pair(int *array, size_t *n, const int pair[2]) { assert(array); assert(n); @@ -2545,9 +2545,9 @@ static int close_remaining_fds( const DynamicCreds *dcreds, int user_lookup_fd, int socket_fd, - int *fds, unsigned n_fds) { + int *fds, size_t n_fds) { - unsigned n_dont_close = 0; + size_t n_dont_close = 0; int dont_close[n_fds + 12]; assert(params); @@ -2697,8 +2697,8 @@ static int exec_child( int socket_fd, int named_iofds[3], int *fds, - unsigned n_storage_fds, - unsigned n_socket_fds, + size_t n_storage_fds, + size_t n_socket_fds, char **files_env, int user_lookup_fd, int *exit_status) { @@ -2727,7 +2727,7 @@ static int exec_child( uid_t uid = UID_INVALID; gid_t gid = GID_INVALID; int i, r, ngids = 0; - unsigned n_fds; + size_t n_fds; ExecDirectoryType dt; int secure_bits; @@ -3433,7 +3433,7 @@ int exec_spawn(Unit *unit, _cleanup_strv_free_ char **files_env = NULL; int *fds = NULL; - unsigned n_storage_fds = 0, n_socket_fds = 0; + size_t n_storage_fds = 0, n_socket_fds = 0; _cleanup_free_ char *line = NULL; int socket_fd, r; int named_iofds[3] = { -1, -1, -1 }; @@ -3658,8 +3658,8 @@ static void exec_command_done(ExecCommand *c) { c->argv = strv_free(c->argv); } -void exec_command_done_array(ExecCommand *c, unsigned n) { - unsigned i; +void exec_command_done_array(ExecCommand *c, size_t n) { + size_t i; for (i = 0; i < n; i++) exec_command_done(c+i); @@ -3677,8 +3677,8 @@ ExecCommand* exec_command_free_list(ExecCommand *c) { return NULL; } -void exec_command_free_array(ExecCommand **c, unsigned n) { - unsigned i; +void exec_command_free_array(ExecCommand **c, size_t n) { + size_t i; for (i = 0; i < n; i++) c[i] = exec_command_free_list(c[i]); @@ -3724,9 +3724,9 @@ const char* exec_context_fdname(const ExecContext *c, int fd_index) { } static int exec_context_named_iofds(const ExecContext *c, const ExecParameters *p, int named_iofds[3]) { - unsigned i, targets; + size_t i, targets; const char* stdio_fdname[3]; - unsigned n_fds; + size_t n_fds; assert(c); assert(p); diff --git a/src/core/execute.h b/src/core/execute.h index 69f596efe..ace94338e 100644 --- a/src/core/execute.h +++ b/src/core/execute.h @@ -205,9 +205,9 @@ struct ExecContext { char **read_write_paths, **read_only_paths, **inaccessible_paths; unsigned long mount_flags; BindMount *bind_mounts; - unsigned n_bind_mounts; + size_t n_bind_mounts; TemporaryFileSystem *temporary_filesystems; - unsigned n_temporary_filesystems; + size_t n_temporary_filesystems; uint64_t capability_bounding_set; uint64_t capability_ambient_set; @@ -301,8 +301,8 @@ struct ExecParameters { int *fds; char **fd_names; - unsigned n_storage_fds; - unsigned n_socket_fds; + size_t n_storage_fds; + size_t n_socket_fds; ExecFlags flags; bool selinux_context_net:1; @@ -334,10 +334,10 @@ int exec_spawn(Unit *unit, DynamicCreds *dynamic_creds, pid_t *ret); -void exec_command_done_array(ExecCommand *c, unsigned n); +void exec_command_done_array(ExecCommand *c, size_t n); ExecCommand* exec_command_free_list(ExecCommand *c); -void exec_command_free_array(ExecCommand **c, unsigned n); +void exec_command_free_array(ExecCommand **c, size_t n); void exec_command_dump_list(ExecCommand *c, FILE *f, const char *prefix); void exec_command_append_list(ExecCommand **l, ExecCommand *e); diff --git a/src/core/manager.c b/src/core/manager.c index 656bdbb76..6412fee47 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -2103,7 +2103,7 @@ static int manager_dispatch_notify_fd(sd_event_source *source, int fd, uint32_t _cleanup_free_ Unit **array_copy = NULL; Unit *u1, *u2, **array; int r, *fd_array = NULL; - unsigned n_fds = 0; + size_t n_fds = 0; bool found = false; ssize_t n; diff --git a/src/core/namespace.c b/src/core/namespace.c index cb34a7985..4a7fea920 100644 --- a/src/core/namespace.c +++ b/src/core/namespace.c @@ -275,8 +275,8 @@ static int append_empty_dir_mounts(MountEntry **p, char **strv) { return 0; } -static int append_bind_mounts(MountEntry **p, const BindMount *binds, unsigned n) { - unsigned i; +static int append_bind_mounts(MountEntry **p, const BindMount *binds, size_t n) { + size_t i; assert(p); @@ -295,8 +295,8 @@ static int append_bind_mounts(MountEntry **p, const BindMount *binds, unsigned n return 0; } -static int append_tmpfs_mounts(MountEntry **p, const TemporaryFileSystem *tmpfs, unsigned n) { - unsigned i; +static int append_tmpfs_mounts(MountEntry **p, const TemporaryFileSystem *tmpfs, size_t n) { + size_t i; int r; assert(p); @@ -338,8 +338,8 @@ static int append_tmpfs_mounts(MountEntry **p, const TemporaryFileSystem *tmpfs, return 0; } -static int append_static_mounts(MountEntry **p, const MountEntry *mounts, unsigned n, bool ignore_protect) { - unsigned i; +static int append_static_mounts(MountEntry **p, const MountEntry *mounts, size_t n, bool ignore_protect) { + size_t i; assert(p); assert(mounts); @@ -418,8 +418,8 @@ static int mount_path_compare(const void *a, const void *b) { return 0; } -static int prefix_where_needed(MountEntry *m, unsigned n, const char *root_directory) { - unsigned i; +static int prefix_where_needed(MountEntry *m, size_t n, const char *root_directory) { + size_t i; /* Prefixes all paths in the bind mount table with the root directory if it is specified and the entry needs * that. */ @@ -444,7 +444,7 @@ static int prefix_where_needed(MountEntry *m, unsigned n, const char *root_direc return 0; } -static void drop_duplicates(MountEntry *m, unsigned *n) { +static void drop_duplicates(MountEntry *m, size_t *n) { MountEntry *f, *t, *previous; assert(m); @@ -473,7 +473,7 @@ static void drop_duplicates(MountEntry *m, unsigned *n) { *n = t - m; } -static void drop_inaccessible(MountEntry *m, unsigned *n) { +static void drop_inaccessible(MountEntry *m, size_t *n) { MountEntry *f, *t; const char *clear = NULL; @@ -502,7 +502,7 @@ static void drop_inaccessible(MountEntry *m, unsigned *n) { *n = t - m; } -static void drop_nop(MountEntry *m, unsigned *n) { +static void drop_nop(MountEntry *m, size_t *n) { MountEntry *f, *t; assert(m); @@ -541,7 +541,7 @@ static void drop_nop(MountEntry *m, unsigned *n) { *n = t - m; } -static void drop_outside_root(const char *root_directory, MountEntry *m, unsigned *n) { +static void drop_outside_root(const char *root_directory, MountEntry *m, size_t *n) { MountEntry *f, *t; assert(m); @@ -1047,22 +1047,22 @@ static bool namespace_info_mount_apivfs(const char *root_directory, const Namesp ns_info->protect_kernel_tunables); } -static unsigned namespace_calculate_mounts( +static size_t namespace_calculate_mounts( const char* root_directory, const NamespaceInfo *ns_info, char** read_write_paths, char** read_only_paths, char** inaccessible_paths, char** empty_directories, - unsigned n_bind_mounts, - unsigned n_temporary_filesystems, + size_t n_bind_mounts, + size_t n_temporary_filesystems, const char* tmp_dir, const char* var_tmp_dir, ProtectHome protect_home, ProtectSystem protect_system) { - unsigned protect_home_cnt; - unsigned protect_system_cnt = + size_t protect_home_cnt; + size_t protect_system_cnt = (protect_system == PROTECT_SYSTEM_STRICT ? ELEMENTSOF(protect_system_strict_table) : ((protect_system == PROTECT_SYSTEM_FULL) ? @@ -1093,7 +1093,7 @@ static unsigned namespace_calculate_mounts( (namespace_info_mount_apivfs(root_directory, ns_info) ? ELEMENTSOF(apivfs_table) : 0); } -static void normalize_mounts(const char *root_directory, MountEntry *mounts, unsigned *n_mounts) { +static void normalize_mounts(const char *root_directory, MountEntry *mounts, size_t *n_mounts) { assert(n_mounts); assert(mounts || *n_mounts == 0); @@ -1114,9 +1114,9 @@ int setup_namespace( char** inaccessible_paths, char** empty_directories, const BindMount *bind_mounts, - unsigned n_bind_mounts, + size_t n_bind_mounts, const TemporaryFileSystem *temporary_filesystems, - unsigned n_temporary_filesystems, + size_t n_temporary_filesystems, const char* tmp_dir, const char* var_tmp_dir, ProtectHome protect_home, @@ -1132,7 +1132,7 @@ int setup_namespace( size_t root_hash_size = 0; bool make_slave = false; const char *root; - unsigned n_mounts; + size_t n_mounts; bool require_prefix = false; int r = 0; @@ -1349,7 +1349,7 @@ int setup_namespace( if (n_mounts > 0) { _cleanup_fclose_ FILE *proc_self_mountinfo = NULL; char **blacklist; - unsigned j; + size_t j; /* Open /proc/self/mountinfo now as it may become unavailable if we mount anything on top of /proc. * For example, this is the case with the option: 'InaccessiblePaths=/proc' */ @@ -1431,8 +1431,8 @@ finish: return r; } -void bind_mount_free_many(BindMount *b, unsigned n) { - unsigned i; +void bind_mount_free_many(BindMount *b, size_t n) { + size_t i; assert(b || n == 0); @@ -1444,7 +1444,7 @@ void bind_mount_free_many(BindMount *b, unsigned n) { free(b); } -int bind_mount_add(BindMount **b, unsigned *n, const BindMount *item) { +int bind_mount_add(BindMount **b, size_t *n, const BindMount *item) { _cleanup_free_ char *s = NULL, *d = NULL; BindMount *c; @@ -1477,8 +1477,8 @@ int bind_mount_add(BindMount **b, unsigned *n, const BindMount *item) { return 0; } -void temporary_filesystem_free_many(TemporaryFileSystem *t, unsigned n) { - unsigned i; +void temporary_filesystem_free_many(TemporaryFileSystem *t, size_t n) { + size_t i; assert(t || n == 0); @@ -1492,7 +1492,7 @@ void temporary_filesystem_free_many(TemporaryFileSystem *t, unsigned n) { int temporary_filesystem_add( TemporaryFileSystem **t, - unsigned *n, + size_t *n, const char *path, const char *options) { diff --git a/src/core/namespace.h b/src/core/namespace.h index ac97f9f37..d8e468225 100644 --- a/src/core/namespace.h +++ b/src/core/namespace.h @@ -78,9 +78,9 @@ int setup_namespace( char **inaccessible_paths, char **empty_directories, const BindMount *bind_mounts, - unsigned n_bind_mounts, + size_t n_bind_mounts, const TemporaryFileSystem *temporary_filesystems, - unsigned n_temporary_filesystems, + size_t n_temporary_filesystems, const char *tmp_dir, const char *var_tmp_dir, ProtectHome protect_home, @@ -103,11 +103,11 @@ const char* protect_system_to_string(ProtectSystem p) _const_; ProtectSystem protect_system_from_string(const char *s) _pure_; ProtectSystem parse_protect_system_or_bool(const char *s); -void bind_mount_free_many(BindMount *b, unsigned n); -int bind_mount_add(BindMount **b, unsigned *n, const BindMount *item); +void bind_mount_free_many(BindMount *b, size_t n); +int bind_mount_add(BindMount **b, size_t *n, const BindMount *item); -void temporary_filesystem_free_many(TemporaryFileSystem *t, unsigned n); -int temporary_filesystem_add(TemporaryFileSystem **t, unsigned *n, +void temporary_filesystem_free_many(TemporaryFileSystem *t, size_t n); +int temporary_filesystem_add(TemporaryFileSystem **t, size_t *n, const char *path, const char *options); const char* namespace_type_to_string(NamespaceType t) _const_; diff --git a/src/core/service.c b/src/core/service.c index 4503c03d2..bf4f27880 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -866,7 +866,7 @@ static void service_dump(Unit *u, FILE *f, const char *prefix) { if (s->n_fd_store_max > 0) fprintf(f, "%sFile Descriptor Store Max: %u\n" - "%sFile Descriptor Store Current: %u\n", + "%sFile Descriptor Store Current: %zu\n", prefix, s->n_fd_store_max, prefix, s->n_fd_store); diff --git a/src/core/service.h b/src/core/service.h index 083084c9a..116d5d119 100644 --- a/src/core/service.h +++ b/src/core/service.h @@ -170,7 +170,7 @@ struct Service { NotifyState notify_state; ServiceFDStore *fd_store; - unsigned n_fd_store; + size_t n_fd_store; unsigned n_fd_store_max; unsigned n_keep_fd_store; diff --git a/src/core/socket.c b/src/core/socket.c index 5b7ae5cd1..15a7c1314 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -1366,13 +1366,14 @@ static int usbffs_select_ep(const struct dirent *d) { static int usbffs_dispatch_eps(SocketPort *p) { _cleanup_free_ struct dirent **ent = NULL; - int r, i, n, k; + size_t n, k, i; + int r; r = scandir(p->path, &ent, usbffs_select_ep, alphasort); if (r < 0) return -errno; - n = r; + n = (size_t) r; p->auxiliary_fds = new(int, n); if (!p->auxiliary_fds) return -ENOMEM; @@ -1393,9 +1394,7 @@ static int usbffs_dispatch_eps(SocketPort *p) { if (r < 0) goto fail; - p->auxiliary_fds[k] = r; - - ++k; + p->auxiliary_fds[k++] = r; free(ent[i]); } @@ -3097,8 +3096,9 @@ static int socket_dispatch_timer(sd_event_source *source, usec_t usec, void *use } int socket_collect_fds(Socket *s, int **fds) { - int *rfds, k = 0, n = 0; + size_t k = 0, n = 0; SocketPort *p; + int *rfds; assert(s); assert(fds); @@ -3121,7 +3121,7 @@ int socket_collect_fds(Socket *s, int **fds) { return -ENOMEM; LIST_FOREACH(port, p, s->ports) { - int i; + size_t i; if (p->fd >= 0) rfds[k++] = p->fd; @@ -3132,7 +3132,7 @@ int socket_collect_fds(Socket *s, int **fds) { assert(k == n); *fds = rfds; - return n; + return (int) n; } static void socket_reset_failed(Unit *u) { diff --git a/src/core/socket.h b/src/core/socket.h index d26416b70..ce9452dbd 100644 --- a/src/core/socket.h +++ b/src/core/socket.h @@ -54,7 +54,7 @@ typedef struct SocketPort { SocketType type; int fd; int *auxiliary_fds; - int n_auxiliary_fds; + size_t n_auxiliary_fds; SocketAddress address; char *path; diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c index 6d1b1b238..ce3733930 100644 --- a/src/firstboot/firstboot.c +++ b/src/firstboot/firstboot.c @@ -110,8 +110,8 @@ static void print_welcome(void) { } static int show_menu(char **x, unsigned n_columns, unsigned width, unsigned percentage) { - unsigned n, per_column, i, j; unsigned break_lines, break_modulo; + size_t n, per_column, i, j; assert(n_columns > 0); @@ -140,7 +140,7 @@ static int show_menu(char **x, unsigned n_columns, unsigned width, unsigned perc if (!e) return log_oom(); - printf("%4u) %-*s", j * per_column + i + 1, width, e); + printf("%4zu) %-*s", j * per_column + i + 1, width, e); } putchar('\n'); diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index 391fc417e..554cf20de 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -644,7 +644,7 @@ static bool shall_try_append_again(JournalFile *f, int r) { } } -static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, unsigned n, int priority) { +static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, size_t n, int priority) { bool vacuumed = false, rotate = false; struct dual_timestamp ts; JournalFile *f; @@ -699,7 +699,7 @@ static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, unsigned } if (vacuumed || !shall_try_append_again(f, r)) { - log_error_errno(r, "Failed to write entry (%d items, %zu bytes), ignoring: %m", n, IOVEC_TOTAL_SIZE(iovec, n)); + log_error_errno(r, "Failed to write entry (%zu items, %zu bytes), ignoring: %m", n, IOVEC_TOTAL_SIZE(iovec, n)); return; } @@ -713,7 +713,7 @@ static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, unsigned log_debug("Retrying write."); r = journal_file_append_entry(f, &ts, iovec, n, &s->seqnum, NULL, NULL); if (r < 0) - log_error_errno(r, "Failed to write entry (%d items, %zu bytes) despite vacuuming, ignoring: %m", n, IOVEC_TOTAL_SIZE(iovec, n)); + log_error_errno(r, "Failed to write entry (%zu items, %zu bytes) despite vacuuming, ignoring: %m", n, IOVEC_TOTAL_SIZE(iovec, n)); else server_schedule_sync(s, priority); } @@ -1069,7 +1069,7 @@ int server_process_datagram(sd_event_source *es, int fd, uint32_t revents, void struct iovec iovec; ssize_t n; int *fds = NULL, v = 0; - unsigned n_fds = 0; + size_t n_fds = 0; union { struct cmsghdr cmsghdr; diff --git a/src/libsystemd-network/network-internal.c b/src/libsystemd-network/network-internal.c index 78ef1eb3c..620f71154 100644 --- a/src/libsystemd-network/network-internal.c +++ b/src/libsystemd-network/network-internal.c @@ -83,7 +83,7 @@ static bool net_condition_test_strv(char * const *raw_patterns, /* If the patterns begin with "!", edit it out and negate the test. */ if (raw_patterns[0][0] == '!') { char **patterns; - unsigned i, length; + size_t i, length; length = strv_length(raw_patterns) + 1; /* Include the NULL. */ patterns = newa(char*, length); diff --git a/src/libsystemd-network/sd-dhcp-lease.c b/src/libsystemd-network/sd-dhcp-lease.c index 724876d6d..c4670503c 100644 --- a/src/libsystemd-network/sd-dhcp-lease.c +++ b/src/libsystemd-network/sd-dhcp-lease.c @@ -221,7 +221,7 @@ int sd_dhcp_lease_get_routes(sd_dhcp_lease *lease, sd_dhcp_route ***routes) { } int sd_dhcp_lease_get_search_domains(sd_dhcp_lease *lease, char ***domains) { - unsigned r; + size_t r; assert_return(lease, -EINVAL); assert_return(domains, -EINVAL); diff --git a/src/libsystemd/sd-bus/bus-internal.h b/src/libsystemd/sd-bus/bus-internal.h index 492e32c48..428e02612 100644 --- a/src/libsystemd/sd-bus/bus-internal.h +++ b/src/libsystemd/sd-bus/bus-internal.h @@ -265,7 +265,7 @@ struct sd_bus { uint64_t creds_mask; int *fds; - unsigned n_fds; + size_t n_fds; char *exec_path; char **exec_argv; diff --git a/src/libsystemd/sd-bus/bus-message.c b/src/libsystemd/sd-bus/bus-message.c index 3f4a2ba2b..61df50e43 100644 --- a/src/libsystemd/sd-bus/bus-message.c +++ b/src/libsystemd/sd-bus/bus-message.c @@ -399,7 +399,7 @@ int bus_message_from_header( size_t footer_accessible, size_t message_size, int *fds, - unsigned n_fds, + size_t n_fds, const char *label, size_t extra, sd_bus_message **ret) { @@ -510,7 +510,7 @@ int bus_message_from_malloc( void *buffer, size_t length, int *fds, - unsigned n_fds, + size_t n_fds, const char *label, sd_bus_message **ret) { @@ -1651,7 +1651,7 @@ _public_ int sd_bus_message_append_string_space( _public_ int sd_bus_message_append_string_iovec( sd_bus_message *m, const struct iovec *iov, - unsigned n) { + unsigned n /* should be size_t, but is API now… 😞 */) { size_t size; unsigned i; @@ -2575,7 +2575,7 @@ _public_ int sd_bus_message_append_array_iovec( sd_bus_message *m, char type, const struct iovec *iov, - unsigned n) { + unsigned n /* should be size_t, but is API now… 😞 */) { size_t size; unsigned i; @@ -5485,7 +5485,7 @@ _public_ int sd_bus_message_set_sender(sd_bus_message *m, const char *sender) { int bus_message_get_blob(sd_bus_message *m, void **buffer, size_t *sz) { size_t total; void *p, *e; - unsigned i; + size_t i; struct bus_body_part *part; assert(m); diff --git a/src/libsystemd/sd-bus/bus-message.h b/src/libsystemd/sd-bus/bus-message.h index 82bbb9aed..510f93be1 100644 --- a/src/libsystemd/sd-bus/bus-message.h +++ b/src/libsystemd/sd-bus/bus-message.h @@ -182,7 +182,7 @@ int bus_message_from_header( size_t footer_accessible, size_t message_size, int *fds, - unsigned n_fds, + size_t n_fds, const char *label, size_t extra, sd_bus_message **ret); @@ -192,7 +192,7 @@ int bus_message_from_malloc( void *buffer, size_t length, int *fds, - unsigned n_fds, + size_t n_fds, const char *label, sd_bus_message **ret); diff --git a/src/libsystemd/sd-login/sd-login.c b/src/libsystemd/sd-login/sd-login.c index 855f040c7..3f73dadc2 100644 --- a/src/libsystemd/sd-login/sd-login.c +++ b/src/libsystemd/sd-login/sd-login.c @@ -402,7 +402,7 @@ static int uid_get_array(uid_t uid, const char *variable, char ***array) { return -ENOMEM; strv_uniq(a); - r = strv_length(a); + r = (int) strv_length(a); if (array) *array = a; @@ -726,7 +726,7 @@ _public_ int sd_seat_get_sessions(const char *seat, char ***sessions, uid_t **ui } } - r = strv_length(a); + r = (int) strv_length(a); if (sessions) *sessions = TAKE_PTR(a); diff --git a/src/libsystemd/sd-network/sd-network.c b/src/libsystemd/sd-network/sd-network.c index 116ceba3b..286e92bc2 100644 --- a/src/libsystemd/sd-network/sd-network.c +++ b/src/libsystemd/sd-network/sd-network.c @@ -65,7 +65,7 @@ static int network_get_strv(const char *key, char ***ret) { return -ENOMEM; strv_uniq(a); - r = strv_length(a); + r = (int) strv_length(a); *ret = TAKE_PTR(a); @@ -136,7 +136,7 @@ static int network_link_get_strv(int ifindex, const char *key, char ***ret) { return -ENOMEM; strv_uniq(a); - r = strv_length(a); + r = (int) strv_length(a); *ret = TAKE_PTR(a); diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c index d038e78d1..508d3775d 100644 --- a/src/machine/machinectl.c +++ b/src/machine/machinectl.c @@ -1800,7 +1800,7 @@ static int enable_machine(int argc, char *argv[], void *userdata) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL, *reply = NULL; _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; UnitFileChange *changes = NULL; - unsigned n_changes = 0; + size_t n_changes = 0; int carries_install_info = 0; const char *method = NULL; sd_bus *bus = userdata; diff --git a/src/resolve/resolvectl.c b/src/resolve/resolvectl.c index 1b7c64a83..0b58e9b57 100644 --- a/src/resolve/resolvectl.c +++ b/src/resolve/resolvectl.c @@ -2865,9 +2865,9 @@ static int native_main(int argc, char *argv[], sd_bus *bus) { return dispatch_verb(argc, argv, verbs, bus); } -static int translate(const char *verb, const char *single_arg, unsigned num_args, char **args, sd_bus *bus) { +static int translate(const char *verb, const char *single_arg, size_t num_args, char **args, sd_bus *bus) { char **fake, **p; - unsigned num, i; + size_t num, i; assert(verb); assert(num_args == 0 || args); @@ -2882,7 +2882,7 @@ static int translate(const char *verb, const char *single_arg, unsigned num_args *p++ = args[i]; optind = 0; - return native_main(num, fake, bus); + return native_main((int) num, fake, bus); } static int compat_main(int argc, char *argv[], sd_bus *bus) { diff --git a/src/resolve/resolved-dns-answer.c b/src/resolve/resolved-dns-answer.c index 252e8cee4..d95343f46 100644 --- a/src/resolve/resolved-dns-answer.c +++ b/src/resolve/resolved-dns-answer.c @@ -11,7 +11,7 @@ #include "resolved-dns-dnssec.h" #include "string-util.h" -DnsAnswer *dns_answer_new(unsigned n) { +DnsAnswer *dns_answer_new(size_t n) { DnsAnswer *a; a = malloc0(offsetof(DnsAnswer, items) + sizeof(DnsAnswerItem) * n); @@ -93,7 +93,7 @@ static int dns_answer_add_raw_all(DnsAnswer *a, DnsAnswer *source) { } int dns_answer_add(DnsAnswer *a, DnsResourceRecord *rr, int ifindex, DnsAnswerFlags flags) { - unsigned i; + size_t i; int r; assert(rr); @@ -453,7 +453,7 @@ int dns_answer_extend(DnsAnswer **a, DnsAnswer *b) { int dns_answer_remove_by_key(DnsAnswer **a, const DnsResourceKey *key) { bool found = false, other = false; DnsResourceRecord *rr; - unsigned i; + size_t i; int r; assert(a); @@ -538,7 +538,7 @@ int dns_answer_remove_by_key(DnsAnswer **a, const DnsResourceKey *key) { int dns_answer_remove_by_rr(DnsAnswer **a, DnsResourceRecord *rm) { bool found = false, other = false; DnsResourceRecord *rr; - unsigned i; + size_t i; int r; assert(a); @@ -667,7 +667,7 @@ int dns_answer_move_by_key(DnsAnswer **to, DnsAnswer **from, const DnsResourceKe void dns_answer_order_by_scope(DnsAnswer *a, bool prefer_link_local) { DnsAnswerItem *items; - unsigned i, start, end; + size_t i, start, end; if (!a) return; @@ -698,7 +698,7 @@ void dns_answer_order_by_scope(DnsAnswer *a, bool prefer_link_local) { memcpy(a->items, items, sizeof(DnsAnswerItem) * a->n_rrs); } -int dns_answer_reserve(DnsAnswer **a, unsigned n_free) { +int dns_answer_reserve(DnsAnswer **a, size_t n_free) { DnsAnswer *n; assert(a); @@ -707,7 +707,7 @@ int dns_answer_reserve(DnsAnswer **a, unsigned n_free) { return 0; if (*a) { - unsigned ns; + size_t ns; if ((*a)->n_ref > 1) return -EBUSY; @@ -735,7 +735,7 @@ int dns_answer_reserve(DnsAnswer **a, unsigned n_free) { return 0; } -int dns_answer_reserve_or_clone(DnsAnswer **a, unsigned n_free) { +int dns_answer_reserve_or_clone(DnsAnswer **a, size_t n_free) { _cleanup_(dns_answer_unrefp) DnsAnswer *n = NULL; int r; diff --git a/src/resolve/resolved-dns-answer.h b/src/resolve/resolved-dns-answer.h index c492d1c15..ca1e266f1 100644 --- a/src/resolve/resolved-dns-answer.h +++ b/src/resolve/resolved-dns-answer.h @@ -36,11 +36,11 @@ struct DnsAnswerItem { struct DnsAnswer { unsigned n_ref; - unsigned n_rrs, n_allocated; + size_t n_rrs, n_allocated; DnsAnswerItem items[0]; }; -DnsAnswer *dns_answer_new(unsigned n); +DnsAnswer *dns_answer_new(size_t n); DnsAnswer *dns_answer_ref(DnsAnswer *a); DnsAnswer *dns_answer_unref(DnsAnswer *a); @@ -62,8 +62,8 @@ int dns_answer_extend(DnsAnswer **a, DnsAnswer *b); void dns_answer_order_by_scope(DnsAnswer *a, bool prefer_link_local); -int dns_answer_reserve(DnsAnswer **a, unsigned n_free); -int dns_answer_reserve_or_clone(DnsAnswer **a, unsigned n_free); +int dns_answer_reserve(DnsAnswer **a, size_t n_free); +int dns_answer_reserve_or_clone(DnsAnswer **a, size_t n_free); int dns_answer_remove_by_key(DnsAnswer **a, const DnsResourceKey *key); int dns_answer_remove_by_rr(DnsAnswer **a, DnsResourceRecord *rr); @@ -73,7 +73,7 @@ int dns_answer_move_by_key(DnsAnswer **to, DnsAnswer **from, const DnsResourceKe bool dns_answer_has_dname_for_cname(DnsAnswer *a, DnsResourceRecord *cname); -static inline unsigned dns_answer_size(DnsAnswer *a) { +static inline size_t dns_answer_size(DnsAnswer *a) { return a ? a->n_rrs : 0; } @@ -86,7 +86,7 @@ void dns_answer_dump(DnsAnswer *answer, FILE *f); DEFINE_TRIVIAL_CLEANUP_FUNC(DnsAnswer*, dns_answer_unref); #define _DNS_ANSWER_FOREACH(q, kk, a) \ - for (unsigned UNIQ_T(i, q) = ({ \ + for (size_t UNIQ_T(i, q) = ({ \ (kk) = ((a) && (a)->n_rrs > 0) ? (a)->items[0].rr : NULL; \ 0; \ }); \ @@ -96,7 +96,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(DnsAnswer*, dns_answer_unref); #define DNS_ANSWER_FOREACH(kk, a) _DNS_ANSWER_FOREACH(UNIQ, kk, a) #define _DNS_ANSWER_FOREACH_IFINDEX(q, kk, ifi, a) \ - for (unsigned UNIQ_T(i, q) = ({ \ + for (size_t UNIQ_T(i, q) = ({ \ (kk) = ((a) && (a)->n_rrs > 0) ? (a)->items[0].rr : NULL; \ (ifi) = ((a) && (a)->n_rrs > 0) ? (a)->items[0].ifindex : 0; \ 0; \ @@ -109,7 +109,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(DnsAnswer*, dns_answer_unref); #define DNS_ANSWER_FOREACH_IFINDEX(kk, ifindex, a) _DNS_ANSWER_FOREACH_IFINDEX(UNIQ, kk, ifindex, a) #define _DNS_ANSWER_FOREACH_FLAGS(q, kk, fl, a) \ - for (unsigned UNIQ_T(i, q) = ({ \ + for (size_t UNIQ_T(i, q) = ({ \ (kk) = ((a) && (a)->n_rrs > 0) ? (a)->items[0].rr : NULL; \ (fl) = ((a) && (a)->n_rrs > 0) ? (a)->items[0].flags : 0; \ 0; \ @@ -122,7 +122,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(DnsAnswer*, dns_answer_unref); #define DNS_ANSWER_FOREACH_FLAGS(kk, flags, a) _DNS_ANSWER_FOREACH_FLAGS(UNIQ, kk, flags, a) #define _DNS_ANSWER_FOREACH_FULL(q, kk, ifi, fl, a) \ - for (unsigned UNIQ_T(i, q) = ({ \ + for (size_t UNIQ_T(i, q) = ({ \ (kk) = ((a) && (a)->n_rrs > 0) ? (a)->items[0].rr : NULL; \ (ifi) = ((a) && (a)->n_rrs > 0) ? (a)->items[0].ifindex : 0; \ (fl) = ((a) && (a)->n_rrs > 0) ? (a)->items[0].flags : 0; \ diff --git a/src/resolve/resolved-dns-question.c b/src/resolve/resolved-dns-question.c index ac3e55f57..5416c474b 100644 --- a/src/resolve/resolved-dns-question.c +++ b/src/resolve/resolved-dns-question.c @@ -10,7 +10,7 @@ #include "dns-type.h" #include "resolved-dns-question.h" -DnsQuestion *dns_question_new(unsigned n) { +DnsQuestion *dns_question_new(size_t n) { DnsQuestion *q; assert(n > 0); @@ -41,7 +41,7 @@ DnsQuestion *dns_question_unref(DnsQuestion *q) { assert(q->n_ref > 0); if (q->n_ref == 1) { - unsigned i; + size_t i; for (i = 0; i < q->n_keys; i++) dns_resource_key_unref(q->keys[i]); @@ -53,7 +53,7 @@ DnsQuestion *dns_question_unref(DnsQuestion *q) { } int dns_question_add(DnsQuestion *q, DnsResourceKey *key) { - unsigned i; + size_t i; int r; assert(key); @@ -77,7 +77,7 @@ int dns_question_add(DnsQuestion *q, DnsResourceKey *key) { } int dns_question_matches_rr(DnsQuestion *q, DnsResourceRecord *rr, const char *search_domain) { - unsigned i; + size_t i; int r; assert(rr); @@ -95,7 +95,7 @@ int dns_question_matches_rr(DnsQuestion *q, DnsResourceRecord *rr, const char *s } int dns_question_matches_cname_or_dname(DnsQuestion *q, DnsResourceRecord *rr, const char *search_domain) { - unsigned i; + size_t i; int r; assert(rr); @@ -121,7 +121,7 @@ int dns_question_matches_cname_or_dname(DnsQuestion *q, DnsResourceRecord *rr, c int dns_question_is_valid_for_query(DnsQuestion *q) { const char *name; - unsigned i; + size_t i; int r; if (!q) @@ -155,7 +155,7 @@ int dns_question_is_valid_for_query(DnsQuestion *q) { } int dns_question_contains(DnsQuestion *a, const DnsResourceKey *k) { - unsigned j; + size_t j; int r; assert(k); @@ -173,7 +173,7 @@ int dns_question_contains(DnsQuestion *a, const DnsResourceKey *k) { } int dns_question_is_equal(DnsQuestion *a, DnsQuestion *b) { - unsigned j; + size_t j; int r; if (a == b) diff --git a/src/resolve/resolved-dns-question.h b/src/resolve/resolved-dns-question.h index fdedefe6c..fcfa16f86 100644 --- a/src/resolve/resolved-dns-question.h +++ b/src/resolve/resolved-dns-question.h @@ -16,11 +16,11 @@ typedef struct DnsQuestion DnsQuestion; struct DnsQuestion { unsigned n_ref; - unsigned n_keys, n_allocated; + size_t n_keys, n_allocated; DnsResourceKey* keys[0]; }; -DnsQuestion *dns_question_new(unsigned n); +DnsQuestion *dns_question_new(size_t n); DnsQuestion *dns_question_ref(DnsQuestion *q); DnsQuestion *dns_question_unref(DnsQuestion *q); @@ -40,7 +40,7 @@ int dns_question_cname_redirect(DnsQuestion *q, const DnsResourceRecord *cname, const char *dns_question_first_name(DnsQuestion *q); -static inline unsigned dns_question_size(DnsQuestion *q) { +static inline size_t dns_question_size(DnsQuestion *q) { return q ? q->n_keys : 0; } @@ -51,7 +51,7 @@ static inline bool dns_question_isempty(DnsQuestion *q) { DEFINE_TRIVIAL_CLEANUP_FUNC(DnsQuestion*, dns_question_unref); #define _DNS_QUESTION_FOREACH(u, key, q) \ - for (unsigned UNIQ_T(i, u) = ({ \ + for (size_t UNIQ_T(i, u) = ({ \ (key) = ((q) && (q)->n_keys > 0) ? (q)->keys[0] : NULL; \ 0; \ }); \ diff --git a/src/resolve/resolved-mdns.c b/src/resolve/resolved-mdns.c index aa6daf297..e27b0f4b7 100644 --- a/src/resolve/resolved-mdns.c +++ b/src/resolve/resolved-mdns.c @@ -133,7 +133,7 @@ static int mdns_packet_extract_matching_rrs(DnsPacket *p, DnsResourceKey *key, D assert(ret_rrs); assert_return(DNS_PACKET_NSCOUNT(p) > 0, -EINVAL); - for (unsigned i = DNS_PACKET_ANCOUNT(p); i < (DNS_PACKET_ANCOUNT(p) + DNS_PACKET_NSCOUNT(p)); i++) { + for (size_t i = DNS_PACKET_ANCOUNT(p); i < (DNS_PACKET_ANCOUNT(p) + DNS_PACKET_NSCOUNT(p)); i++) { r = dns_resource_key_match_rr(key, p->answer->items[i].rr, NULL); if (r < 0) return r; @@ -148,7 +148,7 @@ static int mdns_packet_extract_matching_rrs(DnsPacket *p, DnsResourceKey *key, D if (!list) return -ENOMEM; - for (unsigned i = DNS_PACKET_ANCOUNT(p); i < (DNS_PACKET_ANCOUNT(p) + DNS_PACKET_NSCOUNT(p)); i++) { + for (size_t i = DNS_PACKET_ANCOUNT(p); i < (DNS_PACKET_ANCOUNT(p) + DNS_PACKET_NSCOUNT(p)); i++) { r = dns_resource_key_match_rr(key, p->answer->items[i].rr, NULL); if (r < 0) return r; @@ -166,8 +166,7 @@ static int mdns_packet_extract_matching_rrs(DnsPacket *p, DnsResourceKey *key, D static int mdns_do_tiebreak(DnsResourceKey *key, DnsAnswer *answer, DnsPacket *p) { _cleanup_free_ DnsResourceRecord **our = NULL, **remote = NULL; DnsResourceRecord *rr; - unsigned i = 0; - unsigned size; + size_t i = 0, size; int r; size = dns_answer_size(answer); diff --git a/src/shared/base-filesystem.c b/src/shared/base-filesystem.c index 53091b800..5bc10de9f 100644 --- a/src/shared/base-filesystem.c +++ b/src/shared/base-filesystem.c @@ -50,8 +50,8 @@ static const BaseFilesystem table[] = { int base_filesystem_create(const char *root, uid_t uid, gid_t gid) { _cleanup_close_ int fd = -1; - unsigned i; int r = 0; + size_t i; fd = open(root, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW); if (fd < 0) diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c index de232309c..a0d1f81df 100644 --- a/src/shared/bootspec.c +++ b/src/shared/bootspec.c @@ -125,7 +125,7 @@ int boot_entry_load(const char *path, BootEntry *entry) { } void boot_config_free(BootConfig *config) { - unsigned i; + size_t i; assert(config); @@ -247,7 +247,7 @@ int boot_entries_find(const char *dir, BootEntry **ret_entries, size_t *ret_n_en } static bool find_nonunique(BootEntry *entries, size_t n_entries, bool *arr) { - unsigned i, j; + size_t i, j; bool non_unique = false; assert(entries || n_entries == 0); @@ -267,7 +267,7 @@ static bool find_nonunique(BootEntry *entries, size_t n_entries, bool *arr) { static int boot_entries_uniquify(BootEntry *entries, size_t n_entries) { char *s; - unsigned i; + size_t i; int r; bool arr[n_entries]; diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index 49cee2939..1d3f991be 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -2003,7 +2003,7 @@ int bus_wait_for_jobs_one(BusWaitForJobs *d, const char *path, bool quiet) { return bus_wait_for_jobs(d, quiet, NULL); } -int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet, UnitFileChange **changes, unsigned *n_changes) { +int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet, UnitFileChange **changes, size_t *n_changes) { const char *type, *path, *source; int r; diff --git a/src/shared/bus-unit-util.h b/src/shared/bus-unit-util.h index e243b0c72..934ca21fc 100644 --- a/src/shared/bus-unit-util.h +++ b/src/shared/bus-unit-util.h @@ -41,7 +41,7 @@ int bus_wait_for_jobs_one(BusWaitForJobs *d, const char *path, bool quiet); DEFINE_TRIVIAL_CLEANUP_FUNC(BusWaitForJobs*, bus_wait_for_jobs_free); -int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet, UnitFileChange **changes, unsigned *n_changes); +int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet, UnitFileChange **changes, size_t *n_changes); int unit_show_processes(sd_bus *bus, const char *unit, const char *cgroup_path, const char *prefix, unsigned n_columns, OutputFlags flags, sd_bus_error *error); diff --git a/src/shared/fdset.c b/src/shared/fdset.c index e97a52619..a6eccff69 100644 --- a/src/shared/fdset.c +++ b/src/shared/fdset.c @@ -29,8 +29,8 @@ FDSet *fdset_new(void) { return MAKE_FDSET(set_new(NULL)); } -int fdset_new_array(FDSet **ret, const int *fds, unsigned n_fds) { - unsigned i; +int fdset_new_array(FDSet **ret, const int *fds, size_t n_fds) { + size_t i; FDSet *s; int r; @@ -217,10 +217,10 @@ int fdset_close_others(FDSet *fds) { void *e; Iterator i; int *a; - unsigned j, m; + size_t j = 0, m; - j = 0, m = fdset_size(fds); - a = alloca(sizeof(int) * m); + m = fdset_size(fds); + a = newa(int, m); SET_FOREACH(e, MAKE_SET(fds), i) a[j++] = PTR_TO_FD(e); diff --git a/src/shared/fdset.h b/src/shared/fdset.h index 4691bd51d..178b9abf7 100644 --- a/src/shared/fdset.h +++ b/src/shared/fdset.h @@ -24,7 +24,7 @@ int fdset_put_dup(FDSet *s, int fd); bool fdset_contains(FDSet *s, int fd); int fdset_remove(FDSet *s, int fd); -int fdset_new_array(FDSet **ret, const int *fds, unsigned n_fds); +int fdset_new_array(FDSet **ret, const int *fds, size_t n_fds); int fdset_new_fill(FDSet **ret); int fdset_new_listen_fds(FDSet **ret, bool unset); diff --git a/src/shared/install.c b/src/shared/install.c index 98a289cc6..550c55311 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -285,7 +285,7 @@ static int path_is_vendor(const LookupPaths *p, const char *path) { int unit_file_changes_add( UnitFileChange **changes, - unsigned *n_changes, + size_t *n_changes, UnitFileChangeType type, const char *path, const char *source) { @@ -321,8 +321,8 @@ int unit_file_changes_add( return 0; } -void unit_file_changes_free(UnitFileChange *changes, unsigned n_changes) { - unsigned i; +void unit_file_changes_free(UnitFileChange *changes, size_t n_changes) { + size_t i; assert(changes || n_changes == 0); @@ -334,8 +334,8 @@ void unit_file_changes_free(UnitFileChange *changes, unsigned n_changes) { free(changes); } -void unit_file_dump_changes(int r, const char *verb, const UnitFileChange *changes, unsigned n_changes, bool quiet) { - unsigned i; +void unit_file_dump_changes(int r, const char *verb, const UnitFileChange *changes, size_t n_changes, bool quiet) { + size_t i; bool logged = false; assert(changes || n_changes == 0); @@ -434,7 +434,7 @@ static int create_symlink( const char *new_path, bool force, UnitFileChange **changes, - unsigned *n_changes) { + size_t *n_changes) { _cleanup_free_ char *dest = NULL, *dirname = NULL; const char *rp; @@ -538,7 +538,7 @@ static int remove_marked_symlinks_fd( bool dry_run, bool *restart, UnitFileChange **changes, - unsigned *n_changes) { + size_t *n_changes) { _cleanup_closedir_ DIR *d = NULL; struct dirent *de; @@ -655,7 +655,7 @@ static int remove_marked_symlinks( const LookupPaths *lp, bool dry_run, UnitFileChange **changes, - unsigned *n_changes) { + size_t *n_changes) { _cleanup_close_ int fd = -1; bool restart; @@ -1001,7 +1001,7 @@ static int install_info_may_process( UnitFileInstallInfo *i, const LookupPaths *paths, UnitFileChange **changes, - unsigned *n_changes) { + size_t *n_changes) { assert(i); assert(paths); @@ -1669,7 +1669,7 @@ static int install_info_discover( SearchFlags flags, UnitFileInstallInfo **ret, UnitFileChange **changes, - unsigned *n_changes) { + size_t *n_changes) { UnitFileInstallInfo *i; int r; @@ -1693,7 +1693,7 @@ static int install_info_symlink_alias( const char *config_path, bool force, UnitFileChange **changes, - unsigned *n_changes) { + size_t *n_changes) { char **s; int r = 0, q; @@ -1728,7 +1728,7 @@ static int install_info_symlink_wants( char **list, const char *suffix, UnitFileChange **changes, - unsigned *n_changes) { + size_t *n_changes) { _cleanup_free_ char *buf = NULL; const char *n; @@ -1798,7 +1798,7 @@ static int install_info_symlink_link( const char *config_path, bool force, UnitFileChange **changes, - unsigned *n_changes) { + size_t *n_changes) { _cleanup_free_ char *path = NULL; int r; @@ -1827,7 +1827,7 @@ static int install_info_apply( const char *config_path, bool force, UnitFileChange **changes, - unsigned *n_changes) { + size_t *n_changes) { int r, q; @@ -1864,7 +1864,7 @@ static int install_context_apply( bool force, SearchFlags flags, UnitFileChange **changes, - unsigned *n_changes) { + size_t *n_changes) { UnitFileInstallInfo *i; int r; @@ -1927,7 +1927,7 @@ static int install_context_mark_for_removal( Set **remove_symlinks_to, const char *config_path, UnitFileChange **changes, - unsigned *n_changes) { + size_t *n_changes) { UnitFileInstallInfo *i; int r; @@ -1990,7 +1990,7 @@ int unit_file_mask( const char *root_dir, char **files, UnitFileChange **changes, - unsigned *n_changes) { + size_t *n_changes) { _cleanup_(lookup_paths_free) LookupPaths paths = {}; const char *config_path; @@ -2036,7 +2036,7 @@ int unit_file_unmask( const char *root_dir, char **files, UnitFileChange **changes, - unsigned *n_changes) { + size_t *n_changes) { _cleanup_(lookup_paths_free) LookupPaths paths = {}; _cleanup_set_free_free_ Set *remove_symlinks_to = NULL; @@ -2130,7 +2130,7 @@ int unit_file_link( const char *root_dir, char **files, UnitFileChange **changes, - unsigned *n_changes) { + size_t *n_changes) { _cleanup_(lookup_paths_free) LookupPaths paths = {}; _cleanup_strv_free_ char **todo = NULL; @@ -2230,7 +2230,7 @@ int unit_file_revert( const char *root_dir, char **files, UnitFileChange **changes, - unsigned *n_changes) { + size_t *n_changes) { _cleanup_set_free_free_ Set *remove_symlinks_to = NULL; _cleanup_(lookup_paths_free) LookupPaths paths = {}; @@ -2387,7 +2387,7 @@ int unit_file_add_dependency( const char *target, UnitDependency dep, UnitFileChange **changes, - unsigned *n_changes) { + size_t *n_changes) { _cleanup_(lookup_paths_free) LookupPaths paths = {}; _cleanup_(install_context_done) InstallContext c = {}; @@ -2461,7 +2461,7 @@ int unit_file_enable( const char *root_dir, char **files, UnitFileChange **changes, - unsigned *n_changes) { + size_t *n_changes) { _cleanup_(lookup_paths_free) LookupPaths paths = {}; _cleanup_(install_context_done) InstallContext c = {}; @@ -2507,7 +2507,7 @@ int unit_file_disable( const char *root_dir, char **files, UnitFileChange **changes, - unsigned *n_changes) { + size_t *n_changes) { _cleanup_(lookup_paths_free) LookupPaths paths = {}; _cleanup_(install_context_done) InstallContext c = {}; @@ -2549,7 +2549,7 @@ int unit_file_reenable( const char *root_dir, char **files, UnitFileChange **changes, - unsigned *n_changes) { + size_t *n_changes) { char **n; int r; @@ -2576,7 +2576,7 @@ int unit_file_set_default( const char *root_dir, const char *name, UnitFileChange **changes, - unsigned *n_changes) { + size_t *n_changes) { _cleanup_(lookup_paths_free) LookupPaths paths = {}; _cleanup_(install_context_done) InstallContext c = {}; @@ -2928,7 +2928,7 @@ static int execute_preset( UnitFilePresetMode mode, bool force, UnitFileChange **changes, - unsigned *n_changes) { + size_t *n_changes) { int r; @@ -2972,7 +2972,7 @@ static int preset_prepare_one( const char *name, Presets presets, UnitFileChange **changes, - unsigned *n_changes) { + size_t *n_changes) { _cleanup_(install_context_done) InstallContext tmp = {}; UnitFileInstallInfo *i; @@ -3017,7 +3017,7 @@ int unit_file_preset( char **files, UnitFilePresetMode mode, UnitFileChange **changes, - unsigned *n_changes) { + size_t *n_changes) { _cleanup_(install_context_done) InstallContext plus = {}, minus = {}; _cleanup_(lookup_paths_free) LookupPaths paths = {}; @@ -3057,7 +3057,7 @@ int unit_file_preset_all( const char *root_dir, UnitFilePresetMode mode, UnitFileChange **changes, - unsigned *n_changes) { + size_t *n_changes) { _cleanup_(install_context_done) InstallContext plus = {}, minus = {}; _cleanup_(lookup_paths_free) LookupPaths paths = {}; diff --git a/src/shared/install.h b/src/shared/install.h index 495fa3b1d..9dc91429d 100644 --- a/src/shared/install.h +++ b/src/shared/install.h @@ -83,8 +83,8 @@ struct UnitFileChange { char *source; }; -static inline bool unit_file_changes_have_modification(const UnitFileChange* changes, unsigned n_changes) { - unsigned i; +static inline bool unit_file_changes_have_modification(const UnitFileChange* changes, size_t n_changes) { + size_t i; for (i = 0; i < n_changes; i++) if (IN_SET(changes[i].type, UNIT_FILE_SYMLINK, UNIT_FILE_UNLINK)) return true; @@ -129,21 +129,21 @@ int unit_file_enable( const char *root_dir, char **files, UnitFileChange **changes, - unsigned *n_changes); + size_t *n_changes); int unit_file_disable( UnitFileScope scope, UnitFileFlags flags, const char *root_dir, char **files, UnitFileChange **changes, - unsigned *n_changes); + size_t *n_changes); int unit_file_reenable( UnitFileScope scope, UnitFileFlags flags, const char *root_dir, char **files, UnitFileChange **changes, - unsigned *n_changes); + size_t *n_changes); int unit_file_preset( UnitFileScope scope, UnitFileFlags flags, @@ -151,48 +151,48 @@ int unit_file_preset( char **files, UnitFilePresetMode mode, UnitFileChange **changes, - unsigned *n_changes); + size_t *n_changes); int unit_file_preset_all( UnitFileScope scope, UnitFileFlags flags, const char *root_dir, UnitFilePresetMode mode, UnitFileChange **changes, - unsigned *n_changes); + size_t *n_changes); int unit_file_mask( UnitFileScope scope, UnitFileFlags flags, const char *root_dir, char **files, UnitFileChange **changes, - unsigned *n_changes); + size_t *n_changes); int unit_file_unmask( UnitFileScope scope, UnitFileFlags flags, const char *root_dir, char **files, UnitFileChange **changes, - unsigned *n_changes); + size_t *n_changes); int unit_file_link( UnitFileScope scope, UnitFileFlags flags, const char *root_dir, char **files, UnitFileChange **changes, - unsigned *n_changes); + size_t *n_changes); int unit_file_revert( UnitFileScope scope, const char *root_dir, char **files, UnitFileChange **changes, - unsigned *n_changes); + size_t *n_changes); int unit_file_set_default( UnitFileScope scope, UnitFileFlags flags, const char *root_dir, const char *file, UnitFileChange **changes, - unsigned *n_changes); + size_t *n_changes); int unit_file_get_default( UnitFileScope scope, const char *root_dir, @@ -205,7 +205,7 @@ int unit_file_add_dependency( const char *target, UnitDependency dep, UnitFileChange **changes, - unsigned *n_changes); + size_t *n_changes); int unit_file_get_state(UnitFileScope scope, const char *root_dir, const char *filename, UnitFileState *ret); int unit_file_exists(UnitFileScope scope, const LookupPaths *paths, const char *name); @@ -213,9 +213,9 @@ int unit_file_exists(UnitFileScope scope, const LookupPaths *paths, const char * int unit_file_get_list(UnitFileScope scope, const char *root_dir, Hashmap *h, char **states, char **patterns); Hashmap* unit_file_list_free(Hashmap *h); -int unit_file_changes_add(UnitFileChange **changes, unsigned *n_changes, UnitFileChangeType type, const char *path, const char *source); -void unit_file_changes_free(UnitFileChange *changes, unsigned n_changes); -void unit_file_dump_changes(int r, const char *verb, const UnitFileChange *changes, unsigned n_changes, bool quiet); +int unit_file_changes_add(UnitFileChange **changes, size_t *n_changes, UnitFileChangeType type, const char *path, const char *source); +void unit_file_changes_free(UnitFileChange *changes, size_t n_changes); +void unit_file_dump_changes(int r, const char *verb, const UnitFileChange *changes, size_t n_changes, bool quiet); int unit_file_query_preset(UnitFileScope scope, const char *root_dir, const char *name); diff --git a/src/shared/path-lookup.c b/src/shared/path-lookup.c index 554ba73bf..95c40cc91 100644 --- a/src/shared/path-lookup.c +++ b/src/shared/path-lookup.c @@ -717,7 +717,7 @@ void lookup_paths_free(LookupPaths *p) { int lookup_paths_reduce(LookupPaths *p) { _cleanup_free_ struct stat *stats = NULL; size_t n_stats = 0, allocated = 0; - unsigned c = 0; + size_t c = 0; int r; assert(p); @@ -730,7 +730,7 @@ int lookup_paths_reduce(LookupPaths *p) { while (p->search_path[c]) { struct stat st; - unsigned k; + size_t k; /* Never strip the transient and control directories from the path */ if (path_equal_ptr(p->search_path[c], p->transient) || diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 69a6d940e..c6342243f 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -2098,7 +2098,7 @@ static int get_default(int argc, char *argv[], void *userdata) { static int set_default(int argc, char *argv[], void *userdata) { _cleanup_free_ char *unit = NULL; UnitFileChange *changes = NULL; - unsigned n_changes = 0; + size_t n_changes = 0; int r; assert(argc >= 2); @@ -6115,7 +6115,7 @@ static int enable_unit(int argc, char *argv[], void *userdata) { _cleanup_strv_free_ char **names = NULL; const char *verb = argv[0]; UnitFileChange *changes = NULL; - unsigned n_changes = 0; + size_t n_changes = 0; int carries_install_info = -1; bool ignore_carries_install_info = arg_quiet; int r; @@ -6311,7 +6311,7 @@ static int enable_unit(int argc, char *argv[], void *userdata) { if (arg_now && STR_IN_SET(argv[0], "enable", "disable", "mask")) { sd_bus *bus; - unsigned len, i; + size_t len, i; r = acquire_bus(BUS_MANAGER, &bus); if (r < 0) @@ -6341,7 +6341,7 @@ static int add_dependency(int argc, char *argv[], void *userdata) { _cleanup_free_ char *target = NULL; const char *verb = argv[0]; UnitFileChange *changes = NULL; - unsigned n_changes = 0; + size_t n_changes = 0; UnitDependency dep; int r = 0; @@ -6422,7 +6422,7 @@ finish: static int preset_all(int argc, char *argv[], void *userdata) { UnitFileChange *changes = NULL; - unsigned n_changes = 0; + size_t n_changes = 0; int r; if (install_client_side()) { @@ -6477,7 +6477,7 @@ finish: static int show_installation_targets_client_side(const char *name) { UnitFileChange *changes = NULL; - unsigned n_changes = 0, i; + size_t n_changes = 0, i; UnitFileFlags flags; char **p; int r; @@ -6809,7 +6809,7 @@ static int run_editor(char **paths) { const char **args; char *editor, **editor_args = NULL; char **tmp_path, **original_path, *p; - unsigned n_editor_args = 0, i = 1; + size_t n_editor_args = 0, i = 1; size_t argc; argc = strv_length(paths)/2 + 1; diff --git a/src/test/test-install-root.c b/src/test/test-install-root.c index 24eda9c44..194e48329 100644 --- a/src/test/test-install-root.c +++ b/src/test/test-install-root.c @@ -17,7 +17,7 @@ static void test_basic_mask_and_enable(const char *root) { const char *p; UnitFileState state; UnitFileChange *changes = NULL; - unsigned n_changes = 0; + size_t n_changes = 0; log_set_max_level(LOG_DEBUG); @@ -158,7 +158,7 @@ static void test_linked_units(const char *root) { const char *p, *q; UnitFileState state; UnitFileChange *changes = NULL; - unsigned n_changes = 0, i; + size_t n_changes = 0, i; /* * We'll test three cases here: @@ -303,7 +303,7 @@ static void test_linked_units(const char *root) { static void test_default(const char *root) { _cleanup_free_ char *def = NULL; UnitFileChange *changes = NULL; - unsigned n_changes = 0; + size_t n_changes = 0; const char *p; p = strjoina(root, "/usr/lib/systemd/system/test-default-real.target"); @@ -338,7 +338,7 @@ static void test_default(const char *root) { static void test_add_dependency(const char *root) { UnitFileChange *changes = NULL; - unsigned n_changes = 0; + size_t n_changes = 0; const char *p; p = strjoina(root, "/usr/lib/systemd/system/real-add-dependency-test-target.target"); @@ -365,7 +365,7 @@ static void test_add_dependency(const char *root) { static void test_template_enable(const char *root) { UnitFileChange *changes = NULL; - unsigned n_changes = 0; + size_t n_changes = 0; UnitFileState state; const char *p; @@ -479,7 +479,7 @@ static void test_template_enable(const char *root) { static void test_indirect(const char *root) { UnitFileChange *changes = NULL; - unsigned n_changes = 0; + size_t n_changes = 0; UnitFileState state; const char *p; @@ -528,7 +528,7 @@ static void test_indirect(const char *root) { static void test_preset_and_list(const char *root) { UnitFileChange *changes = NULL; - unsigned n_changes = 0, i; + size_t n_changes = 0, i; const char *p, *q; UnitFileState state; bool got_yes = false, got_no = false; @@ -638,7 +638,7 @@ static void test_revert(const char *root) { const char *p; UnitFileState state; UnitFileChange *changes = NULL; - unsigned n_changes = 0; + size_t n_changes = 0; assert(root); @@ -687,7 +687,7 @@ static void test_revert(const char *root) { static void test_preset_order(const char *root) { UnitFileChange *changes = NULL; - unsigned n_changes = 0; + size_t n_changes = 0; const char *p; UnitFileState state; @@ -758,7 +758,7 @@ static void test_with_dropin(const char *root) { const char *p; UnitFileState state; UnitFileChange *changes = NULL; - unsigned n_changes = 0; + size_t n_changes = 0; assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "with-dropin-1.service", &state) == -ENOENT); assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "with-dropin-2.service", &state) == -ENOENT); @@ -891,7 +891,7 @@ static void test_with_dropin_template(const char *root) { const char *p; UnitFileState state; UnitFileChange *changes = NULL; - unsigned n_changes = 0; + size_t n_changes = 0; assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "with-dropin-1@.service", &state) == -ENOENT); assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "with-dropin-2@.service", &state) == -ENOENT); diff --git a/src/test/test-install.c b/src/test/test-install.c index a5328c923..ab83a6aa0 100644 --- a/src/test/test-install.c +++ b/src/test/test-install.c @@ -31,7 +31,7 @@ int main(int argc, char* argv[]) { const char *const files[] = { "avahi-daemon.service", NULL }; const char *const files2[] = { "/home/lennart/test.service", NULL }; UnitFileChange *changes = NULL; - unsigned n_changes = 0; + size_t n_changes = 0; UnitFileState state = 0; log_set_max_level(LOG_DEBUG); |