summaryrefslogtreecommitdiff
path: root/cpustats
diff options
context:
space:
mode:
authorManoj Gupta <manojgupta@google.com>2016-12-13 17:19:13 -0800
committerGeorge Burgess IV <gbiv@google.com>2016-12-13 17:19:13 -0800
commitf5b2ee02c60f996e0d008c27f2ef4076a2889347 (patch)
treec794c999f3d9c8d2b2e49e6f9b6366b5a92880cc /cpustats
parent88ff807ea265e293ca72204e0328f840966bbb93 (diff)
downloadextras-f5b2ee02c60f996e0d008c27f2ef4076a2889347.tar.gz
Fix clang static analyzer warnings.
system/extras/cpustats/cpustats.c:127:61: warning: Assigned value is garbage or undefined [clang-analyzer-core.uninitialized.Assign] system/extras/cpustats/cpustats.c:116:29: warning: Call to 'malloc' has an allocation size of 0 bytes [clang-analyzer-unix.API] Test: Warning no longer appears Change-Id: I770bf73421608c890ecb1c1c538970e358a69199
Diffstat (limited to 'cpustats')
-rw-r--r--cpustats/cpustats.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/cpustats/cpustats.c b/cpustats/cpustats.c
index 0042caf5..375143b6 100644
--- a/cpustats/cpustats.c
+++ b/cpustats/cpustats.c
@@ -105,6 +105,7 @@ int main(int argc, char *argv[]) {
}
cpu_count = get_cpu_count();
+ if (cpu_count < 1) die("Unexpected cpu count\n");
old_cpus = malloc(sizeof(struct cpu_info) * cpu_count);
if (!old_cpus) die("Could not allocate struct cpu_info\n");
@@ -112,7 +113,9 @@ int main(int argc, char *argv[]) {
if (!new_cpus) die("Could not allocate struct cpu_info\n");
for (i = 0; i < cpu_count; i++) {
- old_cpus[i].freq_count = new_cpus[i].freq_count = get_freq_scales_count(i);
+ freq_count = get_freq_scales_count(i);
+ if (freq_count < 1) die("Unexpected frequency scale count\n");
+ old_cpus[i].freq_count = new_cpus[i].freq_count = freq_count;
new_cpus[i].freqs = malloc(sizeof(struct freq_info) * new_cpus[i].freq_count);
if (!new_cpus[i].freqs) die("Could not allocate struct freq_info\n");
old_cpus[i].freqs = malloc(sizeof(struct freq_info) * old_cpus[i].freq_count);