1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-27 20:44:56 +00:00

Fix more sonar issues.

This commit is contained in:
Brenden Matthews 2018-12-23 13:35:04 -05:00
parent db471102bb
commit 3df87776d5

View File

@ -378,10 +378,13 @@ void nvidia_display_setting::lua_setter(lua::state &l, bool init) {
Base::lua_setter(l, init); Base::lua_setter(l, init);
std::string str = do_convert(l, -1).first; std::string str = do_convert(l, -1).first;
if (!str.empty() && (nvdisplay = XOpenDisplay(str.c_str())) == nullptr) { if (!str.empty()) {
nvdisplay = XOpenDisplay(str.c_str());
if (nvdisplay == nullptr) {
CRIT_ERR(nullptr, NULL, "can't open nvidia display: %s", CRIT_ERR(nullptr, NULL, "can't open nvidia display: %s",
XDisplayName(str.c_str())); XDisplayName(str.c_str()));
} }
}
++s; ++s;
} // namespace } // namespace
@ -464,7 +467,6 @@ int set_nvidia_query(struct text_object *obj, const char *arg,
nvs->command = translate_nvidia_special_type[special_type]; nvs->command = translate_nvidia_special_type[special_type];
// Evaluate parameter // Evaluate parameter
// NOSONAR
switch (aid) { switch (aid) {
case ARG_TEMP: // GPU temperature case ARG_TEMP: // GPU temperature
case ARG_GPU_TEMP: case ARG_GPU_TEMP:
@ -771,14 +773,8 @@ static char *get_nvidia_string(TARGET_ID tid, ATTR_ID aid, int gid,
return str; return str;
} }
static int cache_nvidia_string_value(TARGET_ID tid, ATTR_ID aid, char *token, void cache_nvidia_string_value_update(nvidia_c_string *ac_string, char *token,
SEARCH_ID search, int *value, int update, SEARCH_ID search, int *value, int gid) {
int gid) {
static nvidia_c_string ac_string[MAXNUMGPU];
(void)tid;
(void)aid;
if (update) {
if (strcmp(token, (char *)"nvclockmin") == 0 && if (strcmp(token, (char *)"nvclockmin") == 0 &&
ac_string[gid].nvclockmin < 0) { ac_string[gid].nvclockmin < 0) {
ac_string[gid].nvclockmin = *value; ac_string[gid].nvclockmin = *value;
@ -806,8 +802,10 @@ static int cache_nvidia_string_value(TARGET_ID tid, ATTR_ID aid, char *token,
ac_string[gid].perfmax = *value; ac_string[gid].perfmax = *value;
} }
} }
}
} else { void cache_nvidia_string_value_noupdate(nvidia_c_string *ac_string, char *token,
SEARCH_ID search, int *value, int gid) {
if (strcmp(token, (char *)"nvclockmin") == 0) { if (strcmp(token, (char *)"nvclockmin") == 0) {
*value = ac_string[gid].nvclockmin; *value = ac_string[gid].nvclockmin;
} else if (strcmp(token, (char *)"nvclockmax") == 0) { } else if (strcmp(token, (char *)"nvclockmax") == 0) {
@ -828,6 +826,19 @@ static int cache_nvidia_string_value(TARGET_ID tid, ATTR_ID aid, char *token,
*value = ac_string[gid].perfmax; *value = ac_string[gid].perfmax;
} }
} }
}
static int cache_nvidia_string_value(TARGET_ID tid, ATTR_ID aid, char *token,
SEARCH_ID search, int *value, int update,
int gid) {
static nvidia_c_string ac_string[MAXNUMGPU];
(void)tid;
(void)aid;
if (update) {
cache_nvidia_string_value_update(ac_string, token, search, value, gid);
} else {
cache_nvidia_string_value_noupdate(ac_string, token, search, value, gid);
} }
return 0; return 0;
@ -879,11 +890,11 @@ static int get_nvidia_string_value(TARGET_ID tid, ATTR_ID aid, char *token,
kvp = strtok_r(nullptr, NV_KVPAIR_SEPARATORS, &saveptr1); kvp = strtok_r(nullptr, NV_KVPAIR_SEPARATORS, &saveptr1);
} }
// This call updated the cache for the cacheable values; // This call updated the cache for the cacheable values
cache_nvidia_string_value(tid, aid, token, search, &value, 1, gid); cache_nvidia_string_value(tid, aid, token, search, &value, 1, gid);
// Free string, return value // Free string, return value
free(str); free_and_zero(str);
return value; return value;
} }
@ -891,7 +902,10 @@ static int get_nvidia_string_value(TARGET_ID tid, ATTR_ID aid, char *token,
void print_nvidia_value(struct text_object *obj, char *p, void print_nvidia_value(struct text_object *obj, char *p,
unsigned int p_max_size) { unsigned int p_max_size) {
nvidia_s *nvs = static_cast<nvidia_s *>(obj->data.opaque); nvidia_s *nvs = static_cast<nvidia_s *>(obj->data.opaque);
int value, temp1, temp2; int value;
int temp1;
int temp2;
int result;
char *str; char *str;
int event_base; int event_base;
int error_base; int error_base;
@ -926,6 +940,7 @@ void print_nvidia_value(struct text_object *obj, char *p,
case QUERY_VALUE: case QUERY_VALUE:
switch (nvs->attribute) { switch (nvs->attribute) {
case ATTR_FAN_LEVEL: case ATTR_FAN_LEVEL:
/* falls through */
case ATTR_FAN_SPEED: case ATTR_FAN_SPEED:
if (num_COOLER < 1) { if (num_COOLER < 1) {
value = -1; value = -1;
@ -953,20 +968,22 @@ void print_nvidia_value(struct text_object *obj, char *p,
nvs->arg); nvs->arg);
switch (temp1) { switch (temp1) {
case NV_CTRL_GPU_POWER_MIZER_MODE_ADAPTIVE: case NV_CTRL_GPU_POWER_MIZER_MODE_ADAPTIVE:
temp2 = asprintf(&str, "Adaptive"); result = asprintf(&str, "Adaptive");
break; break;
case NV_CTRL_GPU_POWER_MIZER_MODE_PREFER_MAXIMUM_PERFORMANCE: case NV_CTRL_GPU_POWER_MIZER_MODE_PREFER_MAXIMUM_PERFORMANCE:
temp2 = asprintf(&str, "Max. Perf."); result = asprintf(&str, "Max. Perf.");
break; break;
case NV_CTRL_GPU_POWER_MIZER_MODE_AUTO: case NV_CTRL_GPU_POWER_MIZER_MODE_AUTO:
temp2 = asprintf(&str, "Auto"); result = asprintf(&str, "Auto");
break; break;
case NV_CTRL_GPU_POWER_MIZER_MODE_PREFER_CONSISTENT_PERFORMANCE: case NV_CTRL_GPU_POWER_MIZER_MODE_PREFER_CONSISTENT_PERFORMANCE:
temp2 = asprintf(&str, "Consistent"); result = asprintf(&str, "Consistent");
break; break;
default: default:
temp2 = asprintf(&str, "Unknown (%d)", value); result = asprintf(&str, "Unknown (%d)", value);
break;
} }
if (result < 0) { str = nullptr; }
break; break;
case ATTR_MEM_FREE: case ATTR_MEM_FREE:
temp1 = get_nvidia_value(nvs->target, ATTR_MEM_USED, nvs->gpu_id, temp1 = get_nvidia_value(nvs->target, ATTR_MEM_USED, nvs->gpu_id,
@ -986,6 +1003,8 @@ void print_nvidia_value(struct text_object *obj, char *p,
break; break;
} }
break; break;
default:
break;
} }
} }
@ -994,15 +1013,16 @@ void print_nvidia_value(struct text_object *obj, char *p,
snprintf(p, p_max_size, "%d", value); snprintf(p, p_max_size, "%d", value);
} else if (str != nullptr) { } else if (str != nullptr) {
snprintf(p, p_max_size, "%s", str); snprintf(p, p_max_size, "%s", str);
free(str); free_and_zero(str);
} else { } else {
snprintf(p, p_max_size, "%s", "N/A"); snprintf(p, p_max_size, "%s", "N/A");
} }
} }
double get_nvidia_barval(struct text_object *obj) { double get_nvidia_barval(struct text_object *obj) {
struct nvidia_s *nvs = static_cast<nvidia_s *>(obj->data.opaque); nvidia_s *nvs = static_cast<nvidia_s *>(obj->data.opaque);
int temp1, temp2; int temp1;
int temp2;
double value; double value;
// Assume failure // Assume failure