From ec7ab36814ebc592f6b7fe94e10afecaa6a34074 Mon Sep 17 00:00:00 2001 From: marco candrian Date: Tue, 22 Jan 2008 14:56:03 +0100 Subject: [PATCH] max values must be > 0 on the graph-widget Signed-off-by: Julien Danjou --- widgets/graph.c | 14 +++++++++++--- widgets/progressbar.c | 1 - 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/widgets/graph.c b/widgets/graph.c index f2a4e62e..0ed68186 100644 --- a/widgets/graph.c +++ b/widgets/graph.c @@ -54,6 +54,9 @@ graph_draw(Widget *widget, DrawCtx *ctx, int offset, Data *d = widget->data; Area rectangle; + if(d->width < 1 || !(d->max > 0)) + return 0; + if(!widget->user_supplied_x) widget->area.x = widget_calculate_offset(widget->statusbar->width, d->width, @@ -100,7 +103,7 @@ graph_tell(Widget *widget, char *command) int i; float value; - if(!command || d->width < 1) + if(!command || d->width < 1 || !(d->max > 0)) return; if(++d->lines_index >= d->lines_size) /* cycle inside the array */ @@ -172,14 +175,19 @@ graph_new(Statusbar *statusbar, cfg_t *config) warn("graph widget needs: (width - padding_left) >= 3\n"); return w; } + /* prevent: division by zero */ + d->current_max = d->max = cfg_getfloat(config, "max"); + if(!(d->max > 0)) + { + warn("graph widget needs a 'max' value greater than zero\n"); + return w; + } d->lines = p_new(int, d->lines_size); if (cfg_getbool(config, "scale")) d->line_values = p_new(float, d->lines_size); - /* prevent: division by zero; with a MIN option one day, check for div/0's */ - d->current_max = d->max = MAX(cfg_getfloat(config, "max"), 0.0001); if((color = cfg_getstr(config, "fg"))) d->fg = initxcolor(globalconf.display, phys_screen, color); else diff --git a/widgets/progressbar.c b/widgets/progressbar.c index ee19a4e8..9c0731f1 100644 --- a/widgets/progressbar.c +++ b/widgets/progressbar.c @@ -180,7 +180,6 @@ progressbar_new(Statusbar *statusbar, cfg_t *config) } - d->height = cfg_getfloat(config, "height"); d->gap = cfg_getint(config, "gap"); d->padding_left = cfg_getint(config, "padding_left");