From 8ee9c6d22ed10fdaecb09d070e61c00e1446119e Mon Sep 17 00:00:00 2001 From: "Aleksinski, MichalX" Date: Tue, 24 Jul 2018 08:39:20 +0100 Subject: [PATCH] Corrected issues reported by klockwork Change-Id: I3737a39c40d89a8782ef9c3d8195351f0fdeb278 --- src/intel_rdt.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/intel_rdt.c b/src/intel_rdt.c index e509b875..5fc7504c 100644 --- a/src/intel_rdt.c +++ b/src/intel_rdt.c @@ -833,7 +833,8 @@ static int read_proc_name(const char *procfs_path, char *path = ssnprintf_alloc("%s/%s/%s", procfs_path, pid_entry->d_name, comm_file_name); - + if (path == NULL) + return -1; FILE *f = fopen(path, "r"); if (f == NULL) { ERROR(RDT_PLUGIN ": Failed to open comm file, error: %d\n", errno); @@ -841,6 +842,7 @@ static int read_proc_name(const char *procfs_path, return -1; } size_t read_length = fread(name, sizeof(char), out_size, f); + name[out_size - 1] = '\0'; fclose(f); sfree(path); /* strip new line ending */ @@ -1308,9 +1310,9 @@ static int rdt_refresh_ngroup(rdt_name_group_t *ngroup, "%u, removed: %u.", ngroup->desc, (unsigned)new_pids_count, (unsigned)lost_pids_count); - if (new_pids_count != 0 || lost_pids_count != 0) { + if (new_pids_count > 0 || lost_pids_count > 0) { - if (new_pids) { + if (new_pids && new_pids_count > 0) { pid_t new_pids_array[new_pids_count]; pids_list_to_array(new_pids_array, new_pids, STATIC_ARRAY_SIZE(new_pids_array)); @@ -1347,7 +1349,7 @@ static int rdt_refresh_ngroup(rdt_name_group_t *ngroup, } } - if (lost_pids) { + if (lost_pids && lost_pids_count > 0) { pid_t lost_pids_array[lost_pids_count]; pids_list_to_array(lost_pids_array, lost_pids, STATIC_ARRAY_SIZE(lost_pids_array)); -- 2.11.0