fix new_graph parameters
authorPhil Sutter <phil@nwl.cc>
Sun, 22 Nov 2009 20:12:54 +0000 (21:12 +0100)
committerPhil Sutter <phil@nwl.cc>
Sun, 22 Nov 2009 20:12:54 +0000 (21:12 +0100)
One should never print into buffers without knowing their size. Although
new_graph consumes only a single char, this may already be too much.

src/common.c
src/common.h
src/conky.c
src/diskio.c
src/exec.c
src/llua.c
src/net_stat.c
src/specials.c
src/specials.h

index c4099d0..3c65f52 100644 (file)
@@ -464,8 +464,8 @@ void scan_loadgraph_arg(struct text_object *obj, const char *arg)
                free(buf);
 }
 
-void print_loadgraph(struct text_object *obj, char *p)
+void print_loadgraph(struct text_object *obj, char *p, int p_max_size)
 {
-       new_graph(obj, p, info.loadavg[0]);
+       new_graph(obj, p, p_max_size, info.loadavg[0]);
 }
 #endif /* X11 */
index 4dadab2..2c1ddd1 100644 (file)
@@ -72,7 +72,7 @@ void scan_loadavg_arg(struct text_object *, const char *);
 void print_loadavg(struct text_object *, char *, int);
 #ifdef X11
 void scan_loadgraph_arg(struct text_object *, const char *);
-void print_loadgraph(struct text_object *, char *);
+void print_loadgraph(struct text_object *, char *, int);
 #endif /* X11 */
 
 #endif /* _COMMON_H */
index e7d28e1..5f04df1 100644 (file)
@@ -902,10 +902,10 @@ void generate_text_internal(char *p, int p_max_size,
                        }
 #ifdef X11
                        OBJ(cpugraph) {
-                               new_graph(obj, p, round_to_int(cur->cpu_usage[obj->data.i] * 100));
+                               new_graph(obj, p, p_max_size, round_to_int(cur->cpu_usage[obj->data.i] * 100));
                        }
                        OBJ(loadgraph) {
-                               print_loadgraph(obj, p);
+                               print_loadgraph(obj, p, p_max_size);
                        }
 #endif /* X11 */
                        OBJ(color) {
@@ -1373,7 +1373,7 @@ void generate_text_internal(char *p, int p_max_size,
                        }
 #ifdef X11
                        OBJ(memgraph) {
-                               new_graph(obj, p, cur->memmax ? (cur->mem * 100.0) / (cur->memmax) : 0.0);
+                               new_graph(obj, p, p_max_size, cur->memmax ? (cur->mem * 100.0) / (cur->memmax) : 0.0);
                        }
 #endif /* X11 */
                        /* mixer stuff */
@@ -2325,7 +2325,7 @@ void generate_text_internal(char *p, int p_max_size,
                        OBJ(apcupsd_loadgraph) {
                                double progress;
                                progress =      atof(cur->apcupsd.items[APCUPSD_LOAD]);
-                               new_graph(obj, p, (int)progress);
+                               new_graph(obj, p, p_max_size, (int)progress);
                        }
 #endif /* X11 */
                        OBJ(apcupsd_loadgauge) {
index 75fd296..de49f1d 100644 (file)
@@ -183,7 +183,7 @@ static void print_diskiograph_dir(struct text_object *obj, int dir, char *p, int
        else
                val = diskio->current_write;
 
-       new_graph(obj, p, val);
+       new_graph(obj, p, p_max_size, val);
 }
 
 void print_diskiograph(struct text_object *obj, char *p, int p_max_size)
index 79cda00..4057d09 100644 (file)
@@ -387,7 +387,7 @@ void print_execgraph(struct text_object *obj, char *p, int p_max_size)
        barnum = get_barnum(p);
 
        if (barnum > 0) {
-               new_graph(obj, p, round_to_int(barnum));
+               new_graph(obj, p, p_max_size, round_to_int(barnum));
        }
 }
 
@@ -409,7 +409,7 @@ void print_execigraph(struct text_object *obj, char *p, int p_max_size)
                }
                ed->last_update = current_update_time;
        }
-       new_graph(obj, p, (int) (ed->barnum));
+       new_graph(obj, p, p_max_size, (int) (ed->barnum));
 }
 #endif /* X11 */
 
index 750c8f3..bb9b2d3 100644 (file)
@@ -563,7 +563,7 @@ void print_lua_graph(struct text_object *obj, char *p, int p_max_size)
                return;
 
        if (llua_getnumber(obj->data.s, &per)) {
-               new_graph(obj, p, per);
+               new_graph(obj, p, p_max_size, per);
        }
 }
 #endif /* X11 */
index 05d55d1..79cb6c6 100644 (file)
@@ -213,7 +213,7 @@ void print_downspeedgraph(struct text_object *obj, char *p, int p_max_size)
        if (!ns || !p_max_size)
                return;
 
-       new_graph(obj, p, ns->recv_speed / 1024.0);
+       new_graph(obj, p, p_max_size, ns->recv_speed / 1024.0);
 }
 
 void print_upspeedgraph(struct text_object *obj, char *p, int p_max_size)
@@ -223,7 +223,7 @@ void print_upspeedgraph(struct text_object *obj, char *p, int p_max_size)
        if (!ns || !p_max_size)
                return;
 
-       new_graph(obj, p, ns->trans_speed / 1024.0);
+       new_graph(obj, p, p_max_size, ns->trans_speed / 1024.0);
 }
 #endif /* X11 */
 
index 859da86..9a30b66 100644 (file)
@@ -339,7 +339,7 @@ static void graph_append(struct special_t *graph, double f, char showaslog)
        }
 }
 
-void new_graph(struct text_object *obj, char *buf, double val)
+void new_graph(struct text_object *obj, char *buf, int buf_max_size, double val)
 {
        struct special_t *s = 0;
        struct graph *g = obj->special_data;
@@ -347,7 +347,7 @@ void new_graph(struct text_object *obj, char *buf, double val)
        if ((output_methods & TO_X) == 0)
                return;
 
-       if (!g)
+       if (!g || !buf_max_size)
                return;
 
        s = new_special(buf, GRAPH);
index 101306f..e250e3f 100644 (file)
@@ -104,7 +104,7 @@ void scan_stippled_hr(struct text_object *, const char*);
 
 /* printing specials */
 void new_font(char *, char *);
-void new_graph(struct text_object *, char *, double);
+void new_graph(struct text_object *, char *, int, double);
 void new_hr(char *, int);
 void new_stippled_hr(struct text_object *, char *);
 #endif