summaryrefslogtreecommitdiffstats
path: root/Meter.c
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2014-01-16 01:40:47 -0200
committerHisham Muhammad <hisham@gobolinux.org>2014-01-16 01:40:47 -0200
commitc1e0f6e17c16236d68ed26a5e413e9234293f4d9 (patch)
tree0b233e4971c581a589fbf42f87efa326899ceb8e /Meter.c
parent4256c23d84689a12d182937eae9bb13673867370 (diff)
BUGFIX: Fix crash when adding meters and toggling detailed CPU time.
See https://bugzilla.redhat.com/show_bug.cgi?id=987805 for details. (thanks to Dawid Gajownik for the detailed analysis!)
Diffstat (limited to 'Meter.c')
-rw-r--r--Meter.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/Meter.c b/Meter.c
index 7948028e..34238c86 100644
--- a/Meter.c
+++ b/Meter.c
@@ -52,12 +52,13 @@ typedef struct MeterClass_ {
const Meter_Draw draw;
const Meter_SetValues setValues;
const int defaultMode;
- int items;
const double total;
const int* attributes;
const char* name;
const char* uiName;
const char* caption;
+ const char maxItems;
+ char curItems;
} MeterClass;
#define As_Meter(this_) ((MeterClass*)((this_)->super.klass))
@@ -70,8 +71,8 @@ typedef struct MeterClass_ {
#define Meter_doneFn(this_) As_Meter(this_)->done
#define Meter_setValues(this_, c_, i_) As_Meter(this_)->setValues((Meter*)(this_), c_, i_)
#define Meter_defaultMode(this_) As_Meter(this_)->defaultMode
-#define Meter_getItems(this_) As_Meter(this_)->items
-#define Meter_setItems(this_, n_) As_Meter(this_)->items = (n_)
+#define Meter_getItems(this_) As_Meter(this_)->curItems
+#define Meter_setItems(this_, n_) As_Meter(this_)->curItems = (n_)
#define Meter_attributes(this_) As_Meter(this_)->attributes
#define Meter_name(this_) As_Meter(this_)->name
#define Meter_uiName(this_) As_Meter(this_)->uiName
@@ -146,12 +147,17 @@ MeterClass* Meter_types[] = {
};
Meter* Meter_new(ProcessList* pl, int param, MeterClass* type) {
- Meter* this = calloc(sizeof(Meter), 1);
+ Meter* this = calloc(1, sizeof(Meter));
Object_setClass(this, type);
this->h = 1;
this->param = param;
this->pl = pl;
- this->values = calloc(sizeof(double), type->items);
+ char maxItems = type->maxItems;
+ if (maxItems == 0) {
+ maxItems = 1;
+ }
+ type->curItems = maxItems;
+ this->values = calloc(maxItems, sizeof(double));
this->total = type->total;
this->caption = strdup(type->caption);
if (Meter_initFn(this))

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