summaryrefslogtreecommitdiffstats
path: root/AvailableMetersPanel.c
diff options
context:
space:
mode:
authorExplorer09 <explorer09@gmail.com>2016-03-19 15:01:13 +0800
committerExplorer09 <explorer09@gmail.com>2016-03-19 15:01:13 +0800
commit328de356236d62f3cf8efd728cd9f0f71d496fd8 (patch)
tree93ee998ac5daf42e2d614c59a8cd71a48898aee9 /AvailableMetersPanel.c
parentc8a735e471ccd83bfb29414bdfadf09af24b2517 (diff)
Assert (Platform_meterTypes[0]==&CPUMeter_class)
Just assume Platform_meterTypes[0] is always &CPUMeter_class for every platform. This removes a conditional in AvailableMetersPanel_new(). Also adds some comments about the logic here. Without assuming Platform_meterTypes[0], the (int i=1) clause in this for loop will not make sense. (I.e. Why not (int i=0)? ) Also replaced a sprintf() call with safer snprintf() in code further below.
Diffstat (limited to 'AvailableMetersPanel.c')
-rw-r--r--AvailableMetersPanel.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/AvailableMetersPanel.c b/AvailableMetersPanel.c
index f5d1f2d7..e68475f4 100644
--- a/AvailableMetersPanel.c
+++ b/AvailableMetersPanel.c
@@ -112,20 +112,22 @@ AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* heade
this->scr = scr;
Panel_setHeader(super, "Available meters");
+ // Platform_meterTypes[0] should be always (&CPUMeter_class), which we will
+ // handle separately in the code below.
for (int i = 1; Platform_meterTypes[i]; i++) {
MeterClass* type = Platform_meterTypes[i];
- if (type != &CPUMeter_class) {
- const char* label = type->description ? type->description : type->uiName;
- Panel_add(super, (Object*) ListItem_new(label, i << 16));
- }
+ assert(type != &CPUMeter_class);
+ const char* label = type->description ? type->description : type->uiName;
+ Panel_add(super, (Object*) ListItem_new(label, i << 16));
}
+ // Handle (&CPUMeter_class)
MeterClass* type = &CPUMeter_class;
int cpus = pl->cpuCount;
if (cpus > 1) {
Panel_add(super, (Object*) ListItem_new("CPU average", 0));
for (int i = 1; i <= cpus; i++) {
char buffer[50];
- sprintf(buffer, "%s %d", type->uiName, i);
+ snprintf(buffer, 50, "%s %d", type->uiName, i);
Panel_add(super, (Object*) ListItem_new(buffer, i));
}
} else {

© 2014-2024 Faster IT GmbH | imprint | privacy policy