@cryptotaxi247 / netdata-1 / commits / e4fbb3184

Limit sprintf usage in coretemp module in FreeBSD plugin

Vladimir Kobal committed Aug 17, 2017 at 21:45 UTC e4fbb3184ad234eb4339806aa181fd46254ca1d4
1 file changed +4 -3
src/freebsd_sysctl.c
+4 -3
@@ -385,14 +385,15 @@ int do_dev_cpu_temperature(int update_every, usec_t dt) {
385 char char_mib[MAX_INT_DIGITS + 21];
386 char char_rd[MAX_INT_DIGITS + 9];
387
388 - if(unlikely(number_of_cpus != old_number_of_cpus)) {
388 + if (unlikely(number_of_cpus != old_number_of_cpus)) {
389 pcpu_temperature = reallocz(pcpu_temperature, sizeof(int) * number_of_cpus);
390 mib = reallocz(mib, sizeof(int) * number_of_cpus * 4);
391 if (unlikely(number_of_cpus > old_number_of_cpus))
392 memset(&mib[old_number_of_cpus * 4], 0, sizeof(RRDDIM) * (number_of_cpus - old_number_of_cpus));
393 }
394 for (i = 0; i < number_of_cpus; i++) {
395 - sprintf(char_mib, "dev.cpu.%d.temperature", i);
395 + if (unlikely(!(mib[i * 4])))
396 + sprintf(char_mib, "dev.cpu.%d.temperature", i);
397 if (unlikely(getsysctl_simple(char_mib, &mib[i * 4], 4, &pcpu_temperature[i], sizeof(int)))) {
398 error("DISABLED: cpu.temperature chart");
399 error("DISABLED: dev.cpu.temperature module");
@@ -405,7 +406,7 @@ int do_dev_cpu_temperature(int update_every, usec_t dt) {
406 static RRDSET *st;
407 static RRDDIM **rd_pcpu_temperature;
408
408 - if(unlikely(number_of_cpus != old_number_of_cpus)) {
409 + if (unlikely(number_of_cpus != old_number_of_cpus)) {
410 rd_pcpu_temperature = reallocz(rd_pcpu_temperature, sizeof(RRDDIM) * number_of_cpus);
411 if (unlikely(number_of_cpus > old_number_of_cpus))
412 memset(&rd_pcpu_temperature[old_number_of_cpus], 0, sizeof(RRDDIM) * (number_of_cpus - old_number_of_cpus));