diff options
author | Lennart Poettering <lennart@poettering.net> | 2016-01-28 16:28:01 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2016-01-28 16:28:01 +0100 |
commit | d813d7a37211680b3110e36b3bcaff7510a14378 (patch) | |
tree | 7d82ef8cb670a70a1783b7b39c0ec95f0898a591 | |
parent | 1e22b5cda04b6d5e0dd83ab8e6ecb452cf34851f (diff) |
shared: meanor clean-ups for logs-show.c
Some minor simplifications. Shouldn't change codepaths.
-rw-r--r-- | src/shared/logs-show.c | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index a1f65d1a88..111f0225d9 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -82,12 +82,11 @@ static int print_catalog(FILE *f, sd_journal *j) { static int parse_field(const void *data, size_t length, const char *field, char **target, size_t *target_size) { size_t fl, nl; - void *buf; + char *buf; assert(data); assert(field); assert(target); - assert(target_size); fl = strlen(field); if (length < fl) @@ -97,16 +96,18 @@ static int parse_field(const void *data, size_t length, const char *field, char return 0; nl = length - fl; - buf = malloc(nl+1); + buf = new(char, nl+1); if (!buf) return log_oom(); memcpy(buf, (const char*) data + fl, nl); - ((char*)buf)[nl] = 0; + buf[nl] = 0; free(*target); *target = buf; - *target_size = nl; + + if (target_size) + *target_size = nl; return 1; } @@ -415,7 +416,7 @@ static int output_verbose( const void *data; size_t length; _cleanup_free_ char *cursor = NULL; - uint64_t realtime; + uint64_t realtime = 0; char ts[FORMAT_TIMESTAMP_MAX + 7]; int r; @@ -431,17 +432,15 @@ static int output_verbose( return log_full_errno(r == -EADDRNOTAVAIL ? LOG_DEBUG : LOG_ERR, r, "Failed to get source realtime timestamp: %m"); else { _cleanup_free_ char *value = NULL; - size_t size; - r = parse_field(data, length, "_SOURCE_REALTIME_TIMESTAMP=", &value, &size); + r = parse_field(data, length, "_SOURCE_REALTIME_TIMESTAMP=", &value, NULL); if (r < 0) return r; - else { - assert(r > 0); - r = safe_atou64(value, &realtime); - if (r < 0) - log_debug_errno(r, "Failed to parse realtime timestamp: %m"); - } + assert(r > 0); + + r = safe_atou64(value, &realtime); + if (r < 0) + log_debug_errno(r, "Failed to parse realtime timestamp: %m"); } if (r < 0) { |