summaryrefslogtreecommitdiffstats
path: root/src/libsystemd/sd-bus
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsystemd/sd-bus')
-rw-r--r--src/libsystemd/sd-bus/bus-control.c2
-rw-r--r--src/libsystemd/sd-bus/bus-dump.c2
-rw-r--r--src/libsystemd/sd-bus/bus-message.c50
-rw-r--r--src/libsystemd/sd-bus/bus-socket.c2
-rw-r--r--src/libsystemd/sd-bus/sd-bus.c26
-rw-r--r--src/libsystemd/sd-bus/test-bus-chat.c4
-rw-r--r--src/libsystemd/sd-bus/test-bus-objects.c2
-rw-r--r--src/libsystemd/sd-bus/test-bus-server.c2
8 files changed, 46 insertions, 44 deletions
diff --git a/src/libsystemd/sd-bus/bus-control.c b/src/libsystemd/sd-bus/bus-control.c
index 943877f0ea..d96b7256a1 100644
--- a/src/libsystemd/sd-bus/bus-control.c
+++ b/src/libsystemd/sd-bus/bus-control.c
@@ -741,7 +741,7 @@ _public_ int sd_bus_get_owner_creds(sd_bus *bus, uint64_t mask, sd_bus_creds **r
mask &= ~SD_BUS_CREDS_AUGMENT;
do_label = bus->label && (mask & SD_BUS_CREDS_SELINUX_CONTEXT);
- do_groups = bus->n_groups != (size_t) -1 && (mask & SD_BUS_CREDS_SUPPLEMENTARY_GIDS);
+ do_groups = bus->n_groups != SIZE_MAX && (mask & SD_BUS_CREDS_SUPPLEMENTARY_GIDS);
/* Avoid allocating anything if we have no chance of returning useful data */
if (!bus->ucred_valid && !do_label && !do_groups)
diff --git a/src/libsystemd/sd-bus/bus-dump.c b/src/libsystemd/sd-bus/bus-dump.c
index 7ee6e7012f..d5d22b0d8c 100644
--- a/src/libsystemd/sd-bus/bus-dump.c
+++ b/src/libsystemd/sd-bus/bus-dump.c
@@ -81,7 +81,7 @@ _public_ int sd_bus_message_dump(sd_bus_message *m, FILE *f, uint64_t flags) {
m->header->version);
/* Display synthetic message serial number in a more readable
- * format than (uint32_t) -1 */
+ * format than UINT32_MAX */
if (BUS_MESSAGE_COOKIE(m) == 0xFFFFFFFFULL)
fprintf(f, " Cookie=-1");
else
diff --git a/src/libsystemd/sd-bus/bus-message.c b/src/libsystemd/sd-bus/bus-message.c
index 894d681260..fba1dbbd7d 100644
--- a/src/libsystemd/sd-bus/bus-message.c
+++ b/src/libsystemd/sd-bus/bus-message.c
@@ -162,7 +162,7 @@ static void *message_extend_fields(sd_bus_message *m, size_t align, size_t sz, b
new_size = start + sz;
if (new_size < start ||
- new_size > (size_t) ((uint32_t) -1))
+ new_size > (size_t) (UINT32_MAX))
goto poison;
if (old_size == new_size)
@@ -1337,7 +1337,7 @@ static void *message_extend_body(
added = padding + sz;
/* Check for 32bit overflows */
- if (end_body > (size_t) ((uint32_t) -1) ||
+ if (end_body > (size_t) (UINT32_MAX) ||
end_body < start_body) {
m->poisoned = true;
return NULL;
@@ -2340,13 +2340,13 @@ _public_ int sd_bus_message_appendv(
assert_return(!m->sealed, -EPERM);
assert_return(!m->poisoned, -ESTALE);
- n_array = (unsigned) -1;
+ n_array = UINT_MAX;
n_struct = strlen(types);
for (;;) {
const char *t;
- if (n_array == 0 || (n_array == (unsigned) -1 && n_struct == 0)) {
+ if (n_array == 0 || (n_array == UINT_MAX && n_struct == 0)) {
r = type_stack_pop(stack, ELEMENTSOF(stack), &stack_ptr, &types, &n_struct, &n_array);
if (r < 0)
return r;
@@ -2361,7 +2361,7 @@ _public_ int sd_bus_message_appendv(
}
t = types;
- if (n_array != (unsigned) -1)
+ if (n_array != UINT_MAX)
n_array--;
else {
types++;
@@ -2445,7 +2445,7 @@ _public_ int sd_bus_message_appendv(
return r;
}
- if (n_array == (unsigned) -1) {
+ if (n_array == UINT_MAX) {
types += k;
n_struct -= k;
}
@@ -2478,7 +2478,7 @@ _public_ int sd_bus_message_appendv(
types = s;
n_struct = strlen(s);
- n_array = (unsigned) -1;
+ n_array = UINT_MAX;
break;
}
@@ -2502,7 +2502,7 @@ _public_ int sd_bus_message_appendv(
return r;
}
- if (n_array == (unsigned) -1) {
+ if (n_array == UINT_MAX) {
types += k - 1;
n_struct -= k - 1;
}
@@ -2513,7 +2513,7 @@ _public_ int sd_bus_message_appendv(
types = t + 1;
n_struct = k - 2;
- n_array = (unsigned) -1;
+ n_array = UINT_MAX;
break;
}
@@ -2675,7 +2675,7 @@ _public_ int sd_bus_message_append_array_memfd(
if (r < 0)
return r;
- if (offset == 0 && size == (uint64_t) -1)
+ if (offset == 0 && size == UINT64_MAX)
size = real_size;
else if (offset + size > real_size)
return -EMSGSIZE;
@@ -2692,7 +2692,7 @@ _public_ int sd_bus_message_append_array_memfd(
if (size % sz != 0)
return -EINVAL;
- if (size > (uint64_t) (uint32_t) -1)
+ if (size > (uint64_t) UINT32_MAX)
return -EINVAL;
r = sd_bus_message_open_container(m, SD_BUS_TYPE_ARRAY, CHAR_TO_STR(type));
@@ -2750,7 +2750,7 @@ _public_ int sd_bus_message_append_string_memfd(
if (r < 0)
return r;
- if (offset == 0 && size == (uint64_t) -1)
+ if (offset == 0 && size == UINT64_MAX)
size = real_size;
else if (offset + size > real_size)
return -EMSGSIZE;
@@ -2759,7 +2759,7 @@ _public_ int sd_bus_message_append_string_memfd(
if (size == 0)
return -EINVAL;
- if (size > (uint64_t) (uint32_t) -1)
+ if (size > (uint64_t) UINT32_MAX)
return -EINVAL;
c = message_get_last_container(m);
@@ -4430,7 +4430,7 @@ _public_ int sd_bus_message_readv(
* in a single stackframe. We hence implement our own
* home-grown stack in an array. */
- n_array = (unsigned) -1; /* length of current array entries */
+ n_array = UINT_MAX; /* length of current array entries */
n_struct = strlen(types); /* length of current struct contents signature */
for (;;) {
@@ -4438,7 +4438,7 @@ _public_ int sd_bus_message_readv(
n_loop++;
- if (n_array == 0 || (n_array == (unsigned) -1 && n_struct == 0)) {
+ if (n_array == 0 || (n_array == UINT_MAX && n_struct == 0)) {
r = type_stack_pop(stack, ELEMENTSOF(stack), &stack_ptr, &types, &n_struct, &n_array);
if (r < 0)
return r;
@@ -4453,7 +4453,7 @@ _public_ int sd_bus_message_readv(
}
t = types;
- if (n_array != (unsigned) -1)
+ if (n_array != UINT_MAX)
n_array--;
else {
types++;
@@ -4514,7 +4514,7 @@ _public_ int sd_bus_message_readv(
}
}
- if (n_array == (unsigned) -1) {
+ if (n_array == UINT_MAX) {
types += k;
n_struct -= k;
}
@@ -4553,7 +4553,7 @@ _public_ int sd_bus_message_readv(
types = s;
n_struct = strlen(s);
- n_array = (unsigned) -1;
+ n_array = UINT_MAX;
break;
}
@@ -4581,7 +4581,7 @@ _public_ int sd_bus_message_readv(
}
}
- if (n_array == (unsigned) -1) {
+ if (n_array == UINT_MAX) {
types += k - 1;
n_struct -= k - 1;
}
@@ -4592,7 +4592,7 @@ _public_ int sd_bus_message_readv(
types = t + 1;
n_struct = k - 2;
- n_array = (unsigned) -1;
+ n_array = UINT_MAX;
break;
}
@@ -5034,7 +5034,7 @@ static int message_skip_fields(
char t;
size_t l;
- if (array_size != (uint32_t) -1 &&
+ if (array_size != UINT32_MAX &&
array_size <= *ri - original_index)
return 0;
@@ -5122,7 +5122,7 @@ static int message_skip_fields(
if (r < 0)
return r;
- r = message_skip_fields(m, ri, (uint32_t) -1, (const char**) &s);
+ r = message_skip_fields(m, ri, UINT32_MAX, (const char**) &s);
if (r < 0)
return r;
@@ -5140,7 +5140,7 @@ static int message_skip_fields(
strncpy(sig, *signature + 1, l);
sig[l] = '\0';
- r = message_skip_fields(m, ri, (uint32_t) -1, (const char**) &s);
+ r = message_skip_fields(m, ri, UINT32_MAX, (const char**) &s);
if (r < 0)
return r;
}
@@ -5247,7 +5247,7 @@ int bus_message_parse_fields(sd_bus_message *m) {
_cleanup_free_ char *sig = NULL;
const char *signature;
uint64_t field_type;
- size_t item_size = (size_t) -1;
+ size_t item_size = SIZE_MAX;
if (BUS_MESSAGE_IS_GVARIANT(m)) {
uint64_t *u64;
@@ -5461,7 +5461,7 @@ int bus_message_parse_fields(sd_bus_message *m) {
default:
if (!BUS_MESSAGE_IS_GVARIANT(m))
- r = message_skip_fields(m, &ri, (uint32_t) -1, (const char **) &signature);
+ r = message_skip_fields(m, &ri, UINT32_MAX, (const char **) &signature);
}
if (r < 0)
diff --git a/src/libsystemd/sd-bus/bus-socket.c b/src/libsystemd/sd-bus/bus-socket.c
index 4881fd0d32..832526cc1b 100644
--- a/src/libsystemd/sd-bus/bus-socket.c
+++ b/src/libsystemd/sd-bus/bus-socket.c
@@ -620,7 +620,7 @@ static void bus_get_peercred(sd_bus *b) {
assert(b);
assert(!b->ucred_valid);
assert(!b->label);
- assert(b->n_groups == (size_t) -1);
+ assert(b->n_groups == SIZE_MAX);
/* Get the peer for socketpair() sockets */
b->ucred_valid = getpeercred(b->input_fd, &b->ucred) >= 0;
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
index d593002712..e719c74370 100644
--- a/src/libsystemd/sd-bus/sd-bus.c
+++ b/src/libsystemd/sd-bus/sd-bus.c
@@ -247,7 +247,7 @@ _public_ int sd_bus_new(sd_bus **ret) {
.creds_mask = SD_BUS_CREDS_WELL_KNOWN_NAMES|SD_BUS_CREDS_UNIQUE_NAME,
.accept_fd = true,
.original_pid = getpid_cached(),
- .n_groups = (size_t) -1,
+ .n_groups = SIZE_MAX,
.close_on_exit = true,
};
@@ -1964,8 +1964,8 @@ int bus_seal_synthetic_message(sd_bus *b, sd_bus_message *m) {
* hence let's fill something in for synthetic messages. Since
* synthetic messages might have a fake sender and we don't
* want to interfere with the real sender's serial numbers we
- * pick a fixed, artificial one. We use (uint32_t) -1 rather
- * than (uint64_t) -1 since dbus1 only had 32bit identifiers,
+ * pick a fixed, artificial one. We use UINT32_MAX rather
+ * than UINT64_MAX since dbus1 only had 32bit identifiers,
* even though kdbus can do 64bit. */
return sd_bus_message_seal(m, 0xFFFFFFFFULL, 0);
}
@@ -2205,7 +2205,9 @@ _public_ int sd_bus_send_to(sd_bus *bus, sd_bus_message *m, const char *destinat
static usec_t calc_elapse(sd_bus *bus, uint64_t usec) {
assert(bus);
- if (usec == (uint64_t) -1)
+ assert_cc(sizeof(usec_t) == sizeof(uint64_t));
+
+ if (usec == USEC_INFINITY)
return 0;
/* We start all timeouts the instant we enter BUS_HELLO/BUS_RUNNING state, so that the don't run in parallel
@@ -2215,7 +2217,7 @@ static usec_t calc_elapse(sd_bus *bus, uint64_t usec) {
if (IN_SET(bus->state, BUS_WATCH_BIND, BUS_OPENING, BUS_AUTHENTICATING))
return usec;
else
- return now(CLOCK_MONOTONIC) + usec;
+ return usec_add(now(CLOCK_MONOTONIC), usec);
}
static int timeout_compare(const void *a, const void *b) {
@@ -2330,7 +2332,7 @@ int bus_ensure_running(sd_bus *bus) {
if (r > 0)
continue;
- r = sd_bus_wait(bus, (uint64_t) -1);
+ r = sd_bus_wait(bus, UINT64_MAX);
if (r < 0)
return r;
}
@@ -2458,7 +2460,7 @@ _public_ int sd_bus_call(
left = timeout - n;
} else
- left = (uint64_t) -1;
+ left = UINT64_MAX;
r = bus_poll(bus, true, left);
if (r < 0)
@@ -2578,12 +2580,12 @@ _public_ int sd_bus_get_timeout(sd_bus *bus, uint64_t *timeout_usec) {
c = prioq_peek(bus->reply_callbacks_prioq);
if (!c) {
- *timeout_usec = (uint64_t) -1;
+ *timeout_usec = UINT64_MAX;
return 0;
}
if (c->timeout_usec == 0) {
- *timeout_usec = (uint64_t) -1;
+ *timeout_usec = UINT64_MAX;
return 0;
}
@@ -2596,7 +2598,7 @@ _public_ int sd_bus_get_timeout(sd_bus *bus, uint64_t *timeout_usec) {
case BUS_WATCH_BIND:
case BUS_OPENING:
- *timeout_usec = (uint64_t) -1;
+ *timeout_usec = UINT64_MAX;
return 0;
default:
@@ -3308,7 +3310,7 @@ static int bus_poll(sd_bus *bus, bool need_more, uint64_t timeout_usec) {
}
}
- if (timeout_usec != (uint64_t) -1 && (m == USEC_INFINITY || timeout_usec < m))
+ if (timeout_usec != UINT64_MAX && (m == USEC_INFINITY || timeout_usec < m))
m = timeout_usec;
r = ppoll_usec(p, n, m);
@@ -3374,7 +3376,7 @@ _public_ int sd_bus_flush(sd_bus *bus) {
if (bus->wqueue_size <= 0)
return 0;
- r = bus_poll(bus, false, (uint64_t) -1);
+ r = bus_poll(bus, false, UINT64_MAX);
if (r < 0)
return r;
}
diff --git a/src/libsystemd/sd-bus/test-bus-chat.c b/src/libsystemd/sd-bus/test-bus-chat.c
index a1d7ba173f..ba367677cf 100644
--- a/src/libsystemd/sd-bus/test-bus-chat.c
+++ b/src/libsystemd/sd-bus/test-bus-chat.c
@@ -127,7 +127,7 @@ static int server(sd_bus *bus) {
}
if (r == 0) {
- r = sd_bus_wait(bus, (uint64_t) -1);
+ r = sd_bus_wait(bus, UINT64_MAX);
if (r < 0) {
log_error_errno(r, "Failed to wait: %m");
goto fail;
@@ -472,7 +472,7 @@ static void* client2(void *p) {
goto finish;
}
if (r == 0) {
- r = sd_bus_wait(bus, (uint64_t) -1);
+ r = sd_bus_wait(bus, UINT64_MAX);
if (r < 0) {
log_error_errno(r, "Failed to wait: %m");
goto finish;
diff --git a/src/libsystemd/sd-bus/test-bus-objects.c b/src/libsystemd/sd-bus/test-bus-objects.c
index 5ef3f30c70..a71add4342 100644
--- a/src/libsystemd/sd-bus/test-bus-objects.c
+++ b/src/libsystemd/sd-bus/test-bus-objects.c
@@ -255,7 +255,7 @@ static void *server(void *p) {
}
if (r == 0) {
- r = sd_bus_wait(bus, (uint64_t) -1);
+ r = sd_bus_wait(bus, UINT64_MAX);
if (r < 0) {
log_error_errno(r, "Failed to wait: %m");
goto fail;
diff --git a/src/libsystemd/sd-bus/test-bus-server.c b/src/libsystemd/sd-bus/test-bus-server.c
index e7a14716bc..ab4045ee15 100644
--- a/src/libsystemd/sd-bus/test-bus-server.c
+++ b/src/libsystemd/sd-bus/test-bus-server.c
@@ -47,7 +47,7 @@ static void *server(void *p) {
}
if (r == 0) {
- r = sd_bus_wait(bus, (uint64_t) -1);
+ r = sd_bus_wait(bus, UINT64_MAX);
if (r < 0) {
log_error_errno(r, "Failed to wait: %m");
goto fail;