Several fixlets for Coverity (#36791)

This commit is contained in:
Lennart Poettering
2025-03-19 22:27:00 +01:00
committed by GitHub
11 changed files with 51 additions and 50 deletions
+5 -6
View File
@@ -153,23 +153,22 @@ static int dump_processes(
if (!hashmap_isempty(cg->pids)) {
const char *name;
size_t n = 0, i;
pid_t *pids;
void *pidp;
int width;
size_t n = 0;
/* Order processes by their PID */
pids = newa(pid_t, hashmap_size(cg->pids));
pid_t *pids = newa(pid_t, hashmap_size(cg->pids));
HASHMAP_FOREACH_KEY(name, pidp, cg->pids)
pids[n++] = PTR_TO_PID(pidp);
assert(n == hashmap_size(cg->pids));
assert(n > 0);
typesafe_qsort(pids, n, pid_compare_func);
width = DECIMAL_STR_WIDTH(pids[n-1]);
int width = DECIMAL_STR_WIDTH(pids[n-1]);
for (i = 0; i < n; i++) {
for (size_t i = 0; i < n; i++) {
_cleanup_free_ char *e = NULL;
const char *special;
bool more;
+8 -7
View File
@@ -458,14 +458,11 @@ static void parse_display_realtime(
const char *source_monotonic,
usec_t *ret) {
usec_t t, s, u;
usec_t t;
assert(j);
assert(ret);
// FIXME: _SOURCE_MONOTONIC_TIMESTAMP is in CLOCK_BOOTTIME, hence we cannot use it for adjusting realtime.
source_monotonic = NULL;
/* First, try _SOURCE_REALTIME_TIMESTAMP. */
if (source_realtime && safe_atou64(source_realtime, &t) >= 0 && VALID_REALTIME(t)) {
*ret = t;
@@ -479,11 +476,15 @@ static void parse_display_realtime(
}
/* If _SOURCE_MONOTONIC_TIMESTAMP is provided, adjust the header timestamp. */
// FIXME: _SOURCE_MONOTONIC_TIMESTAMP is in CLOCK_BOOTTIME, hence we cannot use it for adjusting realtime.
/*
usec_t s, u;
if (source_monotonic && safe_atou64(source_monotonic, &s) >= 0 && VALID_MONOTONIC(s) &&
sd_journal_get_monotonic_usec(j, &u, &(sd_id128_t) {}) >= 0) {
*ret = map_clock_usec_raw(t, u, s);
return;
}
*/
/* Otherwise, use the header timestamp as is. */
*ret = t;
@@ -504,14 +505,14 @@ static void parse_display_timestamp(
assert(ret_display_ts);
assert(ret_boot_id);
// FIXME: _SOURCE_MONOTONIC_TIMESTAMP is in CLOCK_BOOTTIME, hence we cannot use it for adjusting realtime.
source_monotonic = NULL;
if (source_realtime && safe_atou64(source_realtime, &t) >= 0 && VALID_REALTIME(t))
source_ts.realtime = t;
// FIXME: _SOURCE_MONOTONIC_TIMESTAMP is in CLOCK_BOOTTIME, hence we cannot use it for adjusting realtime.
/*
if (source_monotonic && safe_atou64(source_monotonic, &t) >= 0 && VALID_MONOTONIC(t))
source_ts.monotonic = t;
*/
(void) sd_journal_get_realtime_usec(j, &header_ts.realtime);
(void) sd_journal_get_monotonic_usec(j, &header_ts.monotonic, &boot_id);
+3 -3
View File
@@ -222,11 +222,11 @@ static RequestOperation look_for_escape(PTYForward *f, const char *buffer, size_
case 0x1D: { /* Check for ^] */
usec_t nw = now(CLOCK_MONOTONIC);
if (f->escape_counter == 0 || nw > f->escape_timestamp + ESCAPE_USEC) {
if (f->escape_counter == 0 || nw > usec_add(f->escape_timestamp, ESCAPE_USEC)) {
f->escape_timestamp = nw;
f->escape_counter = 1;
} else {
(f->escape_counter)++;
f->escape_counter++;
if (f->escape_counter >= 3)
return REQUEST_EXIT;
@@ -237,7 +237,7 @@ static RequestOperation look_for_escape(PTYForward *f, const char *buffer, size_
case 'a'...'z':
if (f->escape_counter == 2 &&
now(CLOCK_MONOTONIC) <= f->escape_timestamp + ESCAPE_USEC) {
now(CLOCK_MONOTONIC) <= usec_add(f->escape_timestamp, ESCAPE_USEC)) {
f->escape_timestamp = 0;
f->escape_counter = 0;
return REQUEST_HOTKEY_BASE + *p;