mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-16 01:57:09 +00:00
Fix an out-of-range error in new_graph (#356)
The code was multiplying the index with the size of the element, and then adding it to the typed pointer (resulting in a double multiplication and an OOB access). Replace the buggy code with a slightly safer c++ alternative.
This commit is contained in:
parent
641f4ecfdb
commit
2600d01373
@ -519,14 +519,12 @@ void new_graph(struct text_object *obj, char *buf, int buf_max_size, double val)
|
||||
DBGP("reallocing graph from %d to %d", s->graph_allocated, s->graph_width);
|
||||
if (!s->graph) {
|
||||
/* initialize */
|
||||
memset(graph, 0, s->graph_width * sizeof(double));
|
||||
std::fill_n(graph, s->graph_width, 0.0);
|
||||
s->scale = 100;
|
||||
} else {
|
||||
if (s->graph_width > s->graph_allocated) {
|
||||
/* initialize the new region */
|
||||
memset(graph + (s->graph_allocated * sizeof(double)), 0,
|
||||
(s->graph_width - s->graph_allocated) *
|
||||
sizeof(double));
|
||||
std::fill(graph + s->graph_allocated, graph + s->graph_width, 0.0);
|
||||
}
|
||||
}
|
||||
s->graph = graph;
|
||||
|
Loading…
Reference in New Issue
Block a user