Merge pull request #10249 from keszybz/lgtm-fixes

Fixes for issues found by LGTM
This commit is contained in:
Lennart Poettering 2018-10-02 17:42:55 +02:00 committed by GitHub
commit eb74d3b97a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 22 additions and 17 deletions

View File

@ -592,8 +592,7 @@ static int base64_append_width(
_cleanup_free_ char *x = NULL;
char *t, *s;
ssize_t slen, len, avail;
int line, lines;
ssize_t len, slen, avail, line, lines;
len = base64mem(p, l, &x);
if (len <= 0)
@ -602,6 +601,9 @@ static int base64_append_width(
lines = DIV_ROUND_UP(len, width);
slen = strlen_ptr(sep);
if (lines > (SSIZE_MAX - plen - 1 - slen) / (indent + width + 1))
return -ENOMEM;
t = realloc(*prefix, plen + 1 + slen + (indent + width + 1) * lines);
if (!t)
return -ENOMEM;

View File

@ -280,7 +280,7 @@ EFI_STATUS graphics_splash(UINT8 *content, UINTN len, const EFI_GRAPHICS_OUTPUT_
GraphicsOutput->Mode->Info->VerticalResolution, 0);
/* EFI buffer */
blt_size = dib->x * dib->y * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
blt_size = sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * dib->x * dib->y;
blt = AllocatePool(blt_size);
if (!blt)
return EFI_OUT_OF_RESOURCES;

View File

@ -3459,9 +3459,7 @@ int manager_reload(Manager *m) {
m->uid_refs = hashmap_free(m->uid_refs);
m->gid_refs = hashmap_free(m->gid_refs);
q = lookup_paths_init(&m->lookup_paths, m->unit_file_scope, 0, NULL);
if (q < 0 && r >= 0)
r = q;
r = lookup_paths_init(&m->lookup_paths, m->unit_file_scope, 0, NULL);
q = manager_run_environment_generators(m);
if (q < 0 && r >= 0)

View File

@ -34,7 +34,8 @@ static ssize_t write_entry(char *buf, size_t size, Uploader *u) {
r = snprintf(buf + pos, size - pos,
"__CURSOR=%s\n", u->current_cursor);
if (pos + r > size)
assert(r >= 0);
if ((size_t) r > size - pos)
/* not enough space */
return pos;
@ -58,7 +59,8 @@ static ssize_t write_entry(char *buf, size_t size, Uploader *u) {
r = snprintf(buf + pos, size - pos,
"__REALTIME_TIMESTAMP="USEC_FMT"\n", realtime);
if (r + pos > size)
assert(r >= 0);
if ((size_t) r > size - pos)
/* not enough space */
return pos;
@ -83,7 +85,8 @@ static ssize_t write_entry(char *buf, size_t size, Uploader *u) {
r = snprintf(buf + pos, size - pos,
"__MONOTONIC_TIMESTAMP="USEC_FMT"\n", monotonic);
if (r + pos > size)
assert(r >= 0);
if ((size_t) r > size - pos)
/* not enough space */
return pos;
@ -108,7 +111,8 @@ static ssize_t write_entry(char *buf, size_t size, Uploader *u) {
r = snprintf(buf + pos, size - pos,
"_BOOT_ID=%s\n", sd_id128_to_string(boot_id, sid));
if (r + pos > size)
assert(r >= 0);
if ((size_t) r > size - pos)
/* not enough space */
return pos;

View File

@ -60,10 +60,11 @@ static void draw_progress(uint64_t p, usec_t *last_usec) {
}
static uint64_t scale_progress(uint64_t scale, uint64_t p, uint64_t m) {
/* Calculates scale * p / m, but handles m == 0 safely, and saturates.
* Currently all callers use m >= 1, but we keep the check to be defensive.
*/
/* Calculates scale * p / m, but handles m == 0 safely, and saturates */
if (p >= m || m == 0)
if (p >= m || m == 0) /* lgtm [cpp/constant-comparison] */
return scale;
return scale * p / m;

View File

@ -1896,10 +1896,10 @@ static int install_context_apply(
if (q < 0)
return q;
r = install_info_traverse(scope, c, paths, i, flags, NULL);
if (r < 0) {
q = install_info_traverse(scope, c, paths, i, flags, NULL);
if (q < 0) {
unit_file_changes_add(changes, n_changes, r, i->name, NULL);
return r;
return q;
}
/* We can attempt to process a masked unit when a different unit

View File

@ -862,7 +862,7 @@ static void test_with_dropin(const char *root) {
unit_file_changes_free(changes, n_changes);
changes = NULL; n_changes = 0;
assert_se(unit_file_enable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("with-dropin-4a.service"), &changes, &n_changes) == 1);
assert_se(unit_file_enable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("with-dropin-4a.service"), &changes, &n_changes) == 2);
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "with-dropin-3.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
assert_se(n_changes == 2);
assert_se(changes[0].type == UNIT_FILE_SYMLINK);