Corrected issues reported by klockwork
authorAleksinski, MichalX <michalx.aleksinski@intel.com>
Tue, 24 Jul 2018 07:39:20 +0000 (08:39 +0100)
committerAleksinski, MichalX <michalx.aleksinski@intel.com>
Wed, 6 Mar 2019 06:43:33 +0000 (06:43 +0000)
Change-Id: I3737a39c40d89a8782ef9c3d8195351f0fdeb278

src/intel_rdt.c

index e509b87..5fc7504 100644 (file)
@@ -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));