mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-15 09:44:04 +00:00
Don't crash when using out-of-range cpu numbers (sf.net #3368243)
bug reported by Ormaaj
This commit is contained in:
parent
422cc24ba2
commit
b3d96b3b34
15
src/conky.c
15
src/conky.c
@ -902,12 +902,17 @@ void generate_text_internal(char *p, int p_max_size,
|
||||
OBJ(cpu) {
|
||||
if (cur->cpu_usage) {
|
||||
if (obj->data.i > info.cpu_count) {
|
||||
NORM_ERR("obj->data.i %i info.cpu_count %i",
|
||||
obj->data.i, info.cpu_count);
|
||||
CRIT_ERR(NULL, NULL, "attempting to use more CPUs than you have!");
|
||||
}
|
||||
percent_print(p, p_max_size,
|
||||
static bool warned = false;
|
||||
if(!warned) {
|
||||
NORM_ERR("obj->data.i %i info.cpu_count %i",
|
||||
obj->data.i, info.cpu_count);
|
||||
NORM_ERR("attempting to use more CPUs than you have!");
|
||||
warned = true;
|
||||
}
|
||||
} else {
|
||||
percent_print(p, p_max_size,
|
||||
round_to_int(cur->cpu_usage[obj->data.i] * 100.0));
|
||||
}
|
||||
}
|
||||
}
|
||||
OBJ(cpugauge)
|
||||
|
@ -927,8 +927,9 @@ static int open_sysfs_sensor(const char *dir, const char *dev, const char *type,
|
||||
snprintf(path, 255, "%s%s/%s%d_input", dir, dev, type, n);
|
||||
fd = open(path, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
CRIT_ERR(NULL, NULL, "can't open '%s': %s\nplease check your device or remove this "
|
||||
NORM_ERR("can't open '%s': %s\nplease check your device or remove this "
|
||||
"var from "PACKAGE_NAME, path, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1080,7 +1081,7 @@ void print_sysfs_sensor(struct text_object *obj, char *p, int p_max_size)
|
||||
double r;
|
||||
struct sysfs *sf = obj->data.opaque;
|
||||
|
||||
if (!sf)
|
||||
if (!sf || sf->fd < 0)
|
||||
return;
|
||||
|
||||
r = get_sysfs_info(&sf->fd, sf->arg,
|
||||
|
Loading…
Reference in New Issue
Block a user