mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-02-04 21:18:33 +00:00
Fix segfault in i8k (sf.net #3007167)
Apparently, sometimes the value of i8k.right_fan_status is sometimes null. This just makes sure the null value isn't passed to atoi(3). A better solution would be to figure out why is it null, but I cannot do that as I don't have the hardware.
This commit is contained in:
parent
6b45fe1ef0
commit
684933416c
23
src/i8k.cc
23
src/i8k.cc
@ -78,6 +78,8 @@ int update_i8k(void)
|
||||
|
||||
fclose(fp);
|
||||
|
||||
DBG("read `%s' from /proc/i8k\n", i8k_procbuf);
|
||||
|
||||
i8k.version = strtok(&i8k_procbuf[0], I8K_DELIM);
|
||||
i8k.bios = strtok(NULL, I8K_DELIM);
|
||||
i8k.serial = strtok(NULL, I8K_DELIM);
|
||||
@ -91,21 +93,21 @@ int update_i8k(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char *fan_status_to_string(int status)
|
||||
static void print_i8k_fan_status(char *p, int p_max_size, const char *status)
|
||||
{
|
||||
switch(status) {
|
||||
case 0: return "off";
|
||||
case 1: return "low";
|
||||
case 2: return "high";
|
||||
}
|
||||
return "error";
|
||||
static char *status_arr[] = { "off", "low", "high", "error" };
|
||||
|
||||
int i = status ? atoi(status) : 3;
|
||||
if(i < 0 || i > 3)
|
||||
i = 3;
|
||||
|
||||
snprintf(p, p_max_size, "%s", status_arr[i]);
|
||||
}
|
||||
|
||||
void print_i8k_left_fan_status(struct text_object *obj, char *p, int p_max_size)
|
||||
{
|
||||
(void)obj;
|
||||
snprintf(p, p_max_size, "%s",
|
||||
fan_status_to_string(atoi(i8k.left_fan_status)));
|
||||
print_i8k_fan_status(p, p_max_size, i8k.left_fan_status);
|
||||
}
|
||||
|
||||
void print_i8k_cpu_temp(struct text_object *obj, char *p, int p_max_size)
|
||||
@ -121,8 +123,7 @@ void print_i8k_cpu_temp(struct text_object *obj, char *p, int p_max_size)
|
||||
void print_i8k_right_fan_status(struct text_object *obj, char *p, int p_max_size)
|
||||
{
|
||||
(void)obj;
|
||||
snprintf(p, p_max_size, "%s",
|
||||
fan_status_to_string(atoi(i8k.right_fan_status)));
|
||||
print_i8k_fan_status(p, p_max_size, i8k.right_fan_status);
|
||||
}
|
||||
|
||||
void print_i8k_ac_status(struct text_object *obj, char *p, int p_max_size)
|
||||
|
Loading…
x
Reference in New Issue
Block a user