diff options
author | Nivedita Swaminathan <nivedita.swaminathan@intel.com> | 2015-12-09 15:06:17 -0800 |
---|---|---|
committer | Nivedita Swaminathan <nivedita.swaminathan@intel.com> | 2015-12-09 15:06:17 -0800 |
commit | 93f5d3038f7c33ddd7cc22a0165bc1207b40ca6a (patch) | |
tree | 752f2fec3d7594e6840c415270b81f00b77f98b6 | |
parent | 53370d908764ab7924473cf07b8f9c56e28a1377 (diff) | |
download | powertop-2.0-93f5d3038f7c33ddd7cc22a0165bc1207b40ca6a.tar.gz |
Revert "Fix crash due to unbounded string copies"
This reverts commit 53370d908764ab7924473cf07b8f9c56e28a1377.
41 files changed, 286 insertions, 298 deletions
diff --git a/src/calibrate/calibrate.cpp b/src/calibrate/calibrate.cpp index 60ab892..eacaeec 100644 --- a/src/calibrate/calibrate.cpp +++ b/src/calibrate/calibrate.cpp @@ -91,20 +91,20 @@ static void find_all_usb_callback(const char *d_name) char filename[PATH_MAX]; ifstream file; - snprintf(filename, sizeof(filename), "/sys/bus/usb/devices/%s/power/active_duration", d_name); + snprintf(filename, PATH_MAX, "/sys/bus/usb/devices/%s/power/active_duration", d_name); if (access(filename, R_OK) != 0) return; - snprintf(filename, sizeof(filename), "/sys/bus/usb/devices/%s/power/idVendor", d_name); + snprintf(filename, PATH_MAX, "/sys/bus/usb/devices/%s/power/idVendor", d_name); file.open(filename, ios::in); if (file) { - file.getline(filename, sizeof(filename)); + file.getline(filename, 4096); file.close(); if (strcmp(filename, "1d6b") == 0) return; } - snprintf(filename, sizeof(filename), "/sys/bus/usb/devices/%s/power/control", d_name); + snprintf(filename, PATH_MAX, "/sys/bus/usb/devices/%s/power/control", d_name); save_sysfs(filename); usb_devices.push_back(filename); } @@ -125,7 +125,7 @@ static void suspend_all_usb_devices(void) static void find_all_rfkill_callback(const char *d_name) { char filename[PATH_MAX]; - snprintf(filename, sizeof(filename), "/sys/class/rfkill/%s/soft", d_name); + snprintf(filename, PATH_MAX, "/sys/class/rfkill/%s/soft", d_name); if (access(filename, R_OK) != 0) return; save_sysfs(filename); @@ -155,13 +155,13 @@ static void unrfkill_all_radios(void) static void find_backlight_callback(const char *d_name) { char filename[PATH_MAX]; - snprintf(filename, sizeof(filename), "/sys/class/backlight/%s/brightness", d_name); + snprintf(filename, PATH_MAX, "/sys/class/backlight/%s/brightness", d_name); if (access(filename, R_OK) != 0) return; save_sysfs(filename); backlight_devices.push_back(filename); - snprintf(filename, sizeof(filename), "/sys/class/backlight/%s/max_brightness", d_name); + snprintf(filename, PATH_MAX, "/sys/class/backlight/%s/max_brightness", d_name); blmax = read_sysfs(filename); } @@ -181,7 +181,7 @@ static void lower_backlight(void) static void find_scsi_link_callback(const char *d_name) { char filename[PATH_MAX]; - snprintf(filename, sizeof(filename), "/sys/class/scsi_host/%s/link_power_management_policy", d_name); + snprintf(filename, PATH_MAX, "/sys/class/scsi_host/%s/link_power_management_policy", d_name); if (access(filename, R_OK)!=0) return; diff --git a/src/cpu/abstract_cpu.cpp b/src/cpu/abstract_cpu.cpp index f419dbf..17acb71 100644 --- a/src/cpu/abstract_cpu.cpp +++ b/src/cpu/abstract_cpu.cpp @@ -71,9 +71,9 @@ void abstract_cpu::account_freq(uint64_t freq, uint64_t duration) state->freq = freq; hz_to_human(freq, state->human_name); if (freq == 0) - pt_strcpy(state->human_name, _("Idle")); + strcpy(state->human_name, _("Idle")); if (is_turbo(freq, max_frequency, max_minus_one_frequency)) - pt_strcpy(state->human_name, _("Turbo Mode")); + sprintf(state->human_name, _("Turbo Mode")); state->after_count = 1; } @@ -112,7 +112,7 @@ void abstract_cpu::measurement_start(void) old_idle = true; - snprintf(filename, sizeof(filename), "/sys/devices/system/cpu/cpu%i/cpufreq/scaling_available_frequencies", number); + snprintf(filename, PATH_MAX, "/sys/devices/system/cpu/cpu%i/cpufreq/scaling_available_frequencies", number); file.open(filename, ios::in); if (file) { file >> max_frequency; @@ -205,8 +205,8 @@ void abstract_cpu::insert_cstate(const char *linux_name, const char *human_name, cstates.push_back(state); - pt_strcpy(state->linux_name, linux_name); - pt_strcpy(state->human_name, human_name); + strcpy(state->linux_name, linux_name); + strcpy(state->human_name, human_name); state->line_level = -1; @@ -337,7 +337,7 @@ void abstract_cpu::insert_pstate(uint64_t freq, const char *human_name, uint64_t pstates.push_back(state); state->freq = freq; - pt_strcpy(state->human_name, human_name); + strcpy(state->human_name, human_name); state->time_before = duration; @@ -446,12 +446,12 @@ void abstract_cpu::wiggle(void) /* wiggle a CPU so that we have a record of it at the start and end of the perf trace */ - snprintf(filename, sizeof(filename), "/sys/devices/system/cpu/cpu%i/cpufreq/scaling_max_freq", first_cpu); + snprintf(filename, PATH_MAX, "/sys/devices/system/cpu/cpu%i/cpufreq/scaling_max_freq", first_cpu); ifile.open(filename, ios::in); ifile >> maxf; ifile.close(); - snprintf(filename, sizeof(filename), "/sys/devices/system/cpu/cpu%i/cpufreq/scaling_min_freq", first_cpu); + snprintf(filename, PATH_MAX, "/sys/devices/system/cpu/cpu%i/cpufreq/scaling_min_freq", first_cpu); ifile.open(filename, ios::in); ifile >> minf; ifile.close(); @@ -462,7 +462,7 @@ void abstract_cpu::wiggle(void) ofile.open(filename, ios::out); ofile << minf; ofile.close(); - snprintf(filename, sizeof(filename), "/sys/devices/system/cpu/cpu%i/cpufreq/scaling_max_freq", first_cpu); + snprintf(filename, PATH_MAX, "/sys/devices/system/cpu/cpu%i/cpufreq/scaling_max_freq", first_cpu); ofile.open(filename, ios::out); ofile << minf; ofile.close(); diff --git a/src/cpu/cpu.cpp b/src/cpu/cpu.cpp index 9ca320f..ee87c04 100644 --- a/src/cpu/cpu.cpp +++ b/src/cpu/cpu.cpp @@ -78,18 +78,18 @@ static class abstract_cpu * new_package(int package, int cpu, char * vendor, int ret->set_type("Package"); ret->childcount = 0; - snprintf(packagename, sizeof(packagename), _("cpu package %i"), cpu); + sprintf(packagename, _("cpu package %i"), cpu); cpudev = new class cpudevice(_("cpu package"), packagename, ret); all_devices.push_back(cpudev); - snprintf(packagename, sizeof(packagename), _("package-%i"), cpu); + sprintf(packagename, _("package-%i"), cpu); cpu_rapl_dev = new class cpu_rapl_device(cpudev, _("cpu rapl package"), packagename, ret); if (cpu_rapl_dev->device_present()) all_devices.push_back(cpu_rapl_dev); else delete cpu_rapl_dev; - snprintf(packagename, sizeof(packagename), _("package-%i"), cpu); + sprintf(packagename, _("package-%i"), cpu); dram_rapl_dev = new class dram_rapl_device(cpudev, _("dram rapl package"), packagename, ret); if (dram_rapl_dev->device_present()) all_devices.push_back(dram_rapl_dev); @@ -157,14 +157,14 @@ static void handle_one_cpu(unsigned int number, char *vendor, int family, int mo unsigned int core_number = 0; class abstract_cpu *package, *core, *cpu; - snprintf(filename, sizeof(filename), "/sys/devices/system/cpu/cpu%i/topology/core_id", number); + snprintf(filename, PATH_MAX, "/sys/devices/system/cpu/cpu%i/topology/core_id", number); file.open(filename, ios::in); if (file) { file >> core_number; file.close(); } - snprintf(filename, sizeof(filename), "/sys/devices/system/cpu/cpu%i/topology/physical_package_id", number); + snprintf(filename, PATH_MAX, "/sys/devices/system/cpu/cpu%i/topology/physical_package_id", number); file.open(filename, ios::in); if (file) { file >> package_number; @@ -556,14 +556,14 @@ void report_display_cpu_cstates(void) if (strcmp(core_type, "Core") == 0 ) { core_data[idx2]=""; idx2+=1; - snprintf(tmp_num, sizeof(tmp_num), __("Core %d"), _core->get_number()); + sprintf(tmp_num, __("Core %d"),_core->get_number()); core_data[idx2]=string(tmp_num); idx2+=1; core_num+=1; } else { core_data[idx2]=""; idx2+=1; - snprintf(tmp_num, sizeof(tmp_num), __("GPU %d"), _core->get_number()); + sprintf(tmp_num,__("GPU %d"),_core->get_number()); core_data[idx2]=string(tmp_num); idx2+=1; } @@ -765,7 +765,7 @@ void report_display_cpu_pstates(void) if (line == LEVEL_HEADER) { core_data[idx2]=""; idx2+=1; - snprintf(tmp_num, sizeof(tmp_num), __("Core %d"), _core->get_number()); + sprintf(tmp_num,__("Core %d"),_core->get_number()); core_data[idx2]=string(tmp_num); idx2+=1; } else { @@ -786,7 +786,7 @@ void report_display_cpu_pstates(void) continue; if (line == LEVEL_HEADER) { - snprintf(tmp_num, sizeof(tmp_num), __("CPU %d"), _cpu->get_number()); + sprintf(tmp_num,__("CPU %d"),_cpu->get_number()); cpu_data[idx3] = string(tmp_num); idx3+=1; continue; diff --git a/src/cpu/cpu_linux.cpp b/src/cpu/cpu_linux.cpp index 2e8dba3..e19fba1 100644 --- a/src/cpu/cpu_linux.cpp +++ b/src/cpu/cpu_linux.cpp @@ -46,7 +46,7 @@ void cpu_linux::parse_cstates_start(void) char filename[256]; int len; - len = snprintf(filename, sizeof(filename), "/sys/devices/system/cpu/cpu%i/cpuidle", number); + len = snprintf(filename, 256, "/sys/devices/system/cpu/cpu%i/cpuidle", number); dir = opendir(filename); if (!dir) @@ -64,21 +64,21 @@ void cpu_linux::parse_cstates_start(void) if (strlen(entry->d_name) < 3) continue; - pt_strcpy(linux_name, entry->d_name); - pt_strcpy(human_name, linux_name); + strcpy(linux_name, entry->d_name); + strcpy(human_name, linux_name); - snprintf(filename + len, sizeof(filename) - len, "/%s/name", entry->d_name); + snprintf(filename + len, 256 - len, "/%s/name", entry->d_name); file.open(filename, ios::in); if (file) { - file.getline(human_name, sizeof(human_name)); + file.getline(human_name, 64); file.close(); } if (strcmp(human_name, "C0")==0) - pt_strcpy(human_name, _("C0 polling")); + strcpy(human_name, _("C0 polling")); - snprintf(filename + len, sizeof(filename) - len, "/%s/usage", entry->d_name); + snprintf(filename + len, 256 - len, "/%s/usage", entry->d_name); file.open(filename, ios::in); if (file) { file >> usage; @@ -86,7 +86,7 @@ void cpu_linux::parse_cstates_start(void) } else continue; - snprintf(filename + len, sizeof(filename) - len, "/%s/time", entry->d_name); + snprintf(filename + len, 256 - len, "/%s/time", entry->d_name); file.open(filename, ios::in); if (file) { @@ -113,7 +113,7 @@ void cpu_linux::parse_pstates_start(void) if (children[i]) children[i]->wiggle(); - snprintf(filename, sizeof(filename), "/sys/devices/system/cpu/cpu%i/cpufreq/stats/time_in_state", first_cpu); + snprintf(filename, 256, "/sys/devices/system/cpu/cpu%i/cpufreq/stats/time_in_state", first_cpu); file.open(filename, ios::in); @@ -122,7 +122,7 @@ void cpu_linux::parse_pstates_start(void) while (file) { uint64_t f; - file.getline(line, sizeof(line)); + file.getline(line, 1024); f = strtoull(line, NULL, 10); account_freq(f, 0); } @@ -146,7 +146,7 @@ void cpu_linux::parse_cstates_end(void) ifstream file; int len; - len = snprintf(filename, sizeof(filename), "/sys/devices/system/cpu/cpu%i/cpuidle", number); + len = snprintf(filename, 256, "/sys/devices/system/cpu/cpu%i/cpuidle", number); dir = opendir(filename); if (!dir) @@ -164,11 +164,11 @@ void cpu_linux::parse_cstates_end(void) if (strlen(entry->d_name) < 3) continue; - pt_strcpy(linux_name, entry->d_name); - pt_strcpy(human_name, linux_name); + strcpy(linux_name, entry->d_name); + strcpy(human_name, linux_name); - snprintf(filename + len, sizeof(filename) - len, "/%s/usage", entry->d_name); + snprintf(filename + len, 256 - len, "/%s/usage", entry->d_name); file.open(filename, ios::in); if (file) { file >> usage; @@ -176,7 +176,7 @@ void cpu_linux::parse_cstates_end(void) } else continue; - snprintf(filename + len, sizeof(filename) - len, "/%s/time", entry->d_name); + snprintf(filename + len, 256 - len, "/%s/time", entry->d_name); file.open(filename, ios::in); if (file) { @@ -196,7 +196,7 @@ void cpu_linux::parse_pstates_end(void) char filename[256]; ifstream file; - snprintf(filename, sizeof(filename), "/sys/devices/system/cpu/cpu%i/cpufreq/stats/time_in_state", number); + snprintf(filename, 256, "/sys/devices/system/cpu/cpu%i/cpufreq/stats/time_in_state", number); file.open(filename, ios::in); @@ -207,9 +207,9 @@ void cpu_linux::parse_pstates_end(void) uint64_t f,count; char *c; - memset(line, 0, sizeof(line)); + memset(line, 0, 1024); - file.getline(line, sizeof(line)); + file.getline(line, 1024); f = strtoull(line, &c, 10); if (!c) diff --git a/src/cpu/cpudevice.cpp b/src/cpu/cpudevice.cpp index 4c7ca7b..371d8a8 100644 --- a/src/cpu/cpudevice.cpp +++ b/src/cpu/cpudevice.cpp @@ -26,14 +26,13 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include "../lib.h" #include "../parameters/parameters.h" cpudevice::cpudevice(const char *classname, const char *dev_name, class abstract_cpu *_cpu) { - pt_strcpy(_class, classname); - pt_strcpy(_cpuname, dev_name); + strcpy(_class, classname); + strcpy(_cpuname, dev_name); cpu = _cpu; wake_index = get_param_index("cpu-wakeups");; consumption_index = get_param_index("cpu-consumption");; diff --git a/src/cpu/intel_cpus.cpp b/src/cpu/intel_cpus.cpp index 7cb9d45..999ba07 100644 --- a/src/cpu/intel_cpus.cpp +++ b/src/cpu/intel_cpus.cpp @@ -175,7 +175,7 @@ void nhm_core::measurement_start(void) } - snprintf(filename, sizeof(filename), "/sys/devices/system/cpu/cpu%i/cpufreq/stats/time_in_state", first_cpu); + snprintf(filename, PATH_MAX, "/sys/devices/system/cpu/cpu%i/cpufreq/stats/time_in_state", first_cpu); file.open(filename, ios::in); @@ -517,7 +517,7 @@ void nhm_cpu::measurement_start(void) insert_cstate("active", _("C0 active"), 0, aperf_before, 1); - snprintf(filename, sizeof(filename), "/sys/devices/system/cpu/cpu%i/cpufreq/stats/time_in_state", first_cpu); + snprintf(filename, PATH_MAX, "/sys/devices/system/cpu/cpu%i/cpufreq/stats/time_in_state", first_cpu); file.open(filename, ios::in); @@ -526,7 +526,7 @@ void nhm_cpu::measurement_start(void) while (file) { uint64_t f; - file.getline(line, sizeof(line)); + file.getline(line, 1024); f = strtoull(line, NULL, 10); account_freq(f, 0); } diff --git a/src/devices/ahci.cpp b/src/devices/ahci.cpp index b8adf72..6ea1322 100644 --- a/src/devices/ahci.cpp +++ b/src/devices/ahci.cpp @@ -51,7 +51,7 @@ static string disk_name(char *path, char *target, char *shortname) char pathname[PATH_MAX]; string diskname = ""; - snprintf(pathname, sizeof(pathname), "%s/%s", path, target); + snprintf(pathname, PATH_MAX, "%s/%s", path, target); dir = opendir(pathname); if (!dir) return diskname; @@ -65,10 +65,10 @@ static string disk_name(char *path, char *target, char *shortname) if (!strchr(dirent->d_name, ':')) continue; - snprintf(line, sizeof(line), "%s/%s/model", pathname, dirent->d_name); + snprintf(line, PATH_MAX, "%s/%s/model", pathname, dirent->d_name); file = fopen(line, "r"); if (file) { - if (fgets(line, sizeof(line), file) == NULL) { + if (fgets(line, 4096, file) == NULL) { fclose(file); break; } @@ -92,7 +92,7 @@ static string model_name(char *path, char *shortname) struct dirent *dirent; char pathname[PATH_MAX]; - snprintf(pathname, sizeof(pathname), "%s/device", path); + snprintf(pathname, PATH_MAX, "%s/device", path); dir = opendir(pathname); if (!dir) @@ -131,29 +131,29 @@ ahci::ahci(char *_name, char *path): device() register_sysfs_path(sysfs_path); - snprintf(devname, sizeof(devname), "ahci:%s", _name); + snprintf(devname, 128, "ahci:%s", _name); strncpy(name, devname, sizeof(name)); active_index = get_param_index("ahci-link-power-active"); partial_index = get_param_index("ahci-link-power-partial"); - snprintf(buffer, sizeof(buffer), "%s-active", name); + snprintf(buffer, 4096, "%s-active", name); active_rindex = get_result_index(buffer); - snprintf(buffer, sizeof(buffer), "%s-partial", name); + snprintf(buffer, 4096, "%s-partial", name); partial_rindex = get_result_index(buffer); - snprintf(buffer, sizeof(buffer), "%s-slumber", name); + snprintf(buffer, 4096, "%s-slumber", name); slumber_rindex = get_result_index(buffer); - snprintf(buffer, sizeof(buffer), "%s-devslp", name); + snprintf(buffer, 4096, "%s-devslp", name); devslp_rindex = get_result_index(buffer); diskname = model_name(path, _name); if (strlen(diskname.c_str()) == 0) - snprintf(humanname, sizeof(humanname), _("SATA link: %s"), _name); + snprintf(humanname, 4096, _("SATA link: %s"), _name); else - snprintf(humanname, sizeof(humanname), _("SATA disk: %s"), diskname.c_str()); + snprintf(humanname, 4096, _("SATA disk: %s"), diskname.c_str()); } void ahci::start_measurement(void) @@ -161,27 +161,27 @@ void ahci::start_measurement(void) char filename[PATH_MAX]; ifstream file; - snprintf(filename, sizeof(filename), "%s/ahci_alpm_active", sysfs_path); + snprintf(filename, PATH_MAX, "%s/ahci_alpm_active", sysfs_path); try { file.open(filename, ios::in); if (file) { file >> start_active; } file.close(); - snprintf(filename, sizeof(filename), "%s/ahci_alpm_partial", sysfs_path); + snprintf(filename, PATH_MAX, "%s/ahci_alpm_partial", sysfs_path); file.open(filename, ios::in); if (file) { file >> start_partial; } file.close(); - snprintf(filename, sizeof(filename), "%s/ahci_alpm_slumber", sysfs_path); + snprintf(filename, PATH_MAX, "%s/ahci_alpm_slumber", sysfs_path); file.open(filename, ios::in); if (file) { file >> start_slumber; } file.close(); - snprintf(filename, sizeof(filename), "%s/ahci_alpm_devslp", sysfs_path); + snprintf(filename, PATH_MAX, "%s/ahci_alpm_devslp", sysfs_path); file.open(filename, ios::in); if (file) { file >> start_devslp; @@ -203,25 +203,25 @@ void ahci::end_measurement(void) double total; try { - snprintf(filename, sizeof(filename), "%s/ahci_alpm_active", sysfs_path); + snprintf(filename, 4096, "%s/ahci_alpm_active", sysfs_path); file.open(filename, ios::in); if (file) { file >> end_active; } file.close(); - snprintf(filename, sizeof(filename), "%s/ahci_alpm_partial", sysfs_path); + snprintf(filename, 4096, "%s/ahci_alpm_partial", sysfs_path); file.open(filename, ios::in); if (file) { file >> end_partial; } file.close(); - snprintf(filename, sizeof(filename), "%s/ahci_alpm_slumber", sysfs_path); + snprintf(filename, 4096, "%s/ahci_alpm_slumber", sysfs_path); file.open(filename, ios::in); if (file) { file >> end_slumber; } file.close(); - snprintf(filename, sizeof(filename), "%s/ahci_alpm_devslp", sysfs_path); + snprintf(filename, 4096, "%s/ahci_alpm_devslp", sysfs_path); file.open(filename, ios::in); if (file) { file >> end_devslp; @@ -245,28 +245,28 @@ void ahci::end_measurement(void) p = (end_active - start_active) / total * 100.0; if (p < 0) p = 0; - snprintf(powername, sizeof(powername), "%s-active", name); + snprintf(powername, 4096, "%s-active", name); report_utilization(powername, p); /* percent in partial */ p = (end_partial - start_partial) / total * 100.0; if (p < 0) p = 0; - snprintf(powername, sizeof(powername), "%s-partial", name); + snprintf(powername, 4096, "%s-partial", name); report_utilization(powername, p); /* percent in slumber */ p = (end_slumber - start_slumber) / total * 100.0; if (p < 0) p = 0; - snprintf(powername, sizeof(powername), "%s-slumber", name); + snprintf(powername, 4096, "%s-slumber", name); report_utilization(powername, p); /* percent in devslp */ p = (end_devslp - start_devslp) / total * 100.0; if (p < 0) p = 0; - snprintf(powername, sizeof(powername), "%s-devslp", name); + snprintf(powername, 4096, "%s-devslp", name); report_utilization(powername, p); } @@ -306,7 +306,7 @@ void create_all_ahcis(void) break; if (entry->d_name[0] == '.') continue; - snprintf(filename, sizeof(filename), "/sys/class/scsi_host/%s/ahci_alpm_accounting", entry->d_name); + snprintf(filename, PATH_MAX, "/sys/class/scsi_host/%s/ahci_alpm_accounting", entry->d_name); check_file.open(filename, ios::in); check_file.get(); @@ -319,7 +319,7 @@ void create_all_ahcis(void) continue; file << 1 ; file.close(); - snprintf(filename, sizeof(filename), "/sys/class/scsi_host/%s", entry->d_name); + snprintf(filename, PATH_MAX, "/sys/class/scsi_host/%s", entry->d_name); bl = new class ahci(entry->d_name, filename); all_devices.push_back(bl); @@ -415,18 +415,18 @@ void ahci::report_device_stats(string *ahci_data, int idx) printf("\nData from ahci %s\n",ahci_data[offset].c_str()); offset +=1; - snprintf(util, sizeof(util), "%5.1f", active_util); + sprintf(util, "%5.1f", active_util); ahci_data[offset]= util; offset +=1; - snprintf(util, sizeof(util), "%5.1f", partial_util); + sprintf(util, "%5.1f", partial_util); ahci_data[offset]= util; offset +=1; - snprintf(util, sizeof(util), "%5.1f", slumber_util); + sprintf(util, "%5.1f", slumber_util); ahci_data[offset]= util; offset +=1; - snprintf(util, sizeof(util), "%5.1f", devslp_util); + sprintf(util, "%5.1f", devslp_util); ahci_data[offset]= util; } diff --git a/src/devices/alsa.cpp b/src/devices/alsa.cpp index 425b58a..961a9e5 100644 --- a/src/devices/alsa.cpp +++ b/src/devices/alsa.cpp @@ -53,32 +53,32 @@ alsa::alsa(const char *_name, const char *path): device() start_inactive = 0; strncpy(sysfs_path, path, sizeof(sysfs_path)); - snprintf(devname, sizeof(devname), "alsa:%s", _name); - snprintf(humanname, sizeof(humanname), "alsa:%s", _name); + snprintf(devname, 4096, "alsa:%s", _name); + snprintf(humanname, 4096, "alsa:%s", _name); strncpy(name, devname, sizeof(name)); rindex = get_result_index(name); guilty[0] = 0; model[0] = 0; vendor[0] = 0; - snprintf(devname, sizeof(devname), "%s/modelname", path); + snprintf(devname, 4096, "%s/modelname", path); file.open(devname); if (file) { - file.getline(model, sizeof(model)); + file.getline(model, 4096); file.close(); } - snprintf(devname, sizeof(devname), "%s/vendor_name", path); + snprintf(devname, 4096, "%s/vendor_name", path); file.open(devname); if (file) { - file.getline(vendor, sizeof(vendor)); + file.getline(vendor, 4096); file.close(); } if (strlen(model) && strlen(vendor)) - snprintf(humanname, sizeof(humanname), _("Audio codec %s: %s (%s)"), name, model, vendor); + snprintf(humanname, 4096, _("Audio codec %s: %s (%s)"), name, model, vendor); else if (strlen(model)) - snprintf(humanname, sizeof(humanname), _("Audio codec %s: %s"), _name, model); + snprintf(humanname, 4096, _("Audio codec %s: %s"), _name, model); else if (strlen(vendor)) - snprintf(humanname, sizeof(humanname), _("Audio codec %s: %s"), _name, vendor); + snprintf(humanname, 4096, _("Audio codec %s: %s"), _name, vendor); } void alsa::start_measurement(void) @@ -86,14 +86,14 @@ void alsa::start_measurement(void) char filename[PATH_MAX]; ifstream file; - snprintf(filename, sizeof(filename), "%s/power_off_acct", sysfs_path); + snprintf(filename, PATH_MAX, "%s/power_off_acct", sysfs_path); try { file.open(filename, ios::in); if (file) { file >> start_inactive; } file.close(); - snprintf(filename, sizeof(filename), "%s/power_on_acct", sysfs_path); + snprintf(filename, PATH_MAX, "%s/power_on_acct", sysfs_path); file.open(filename, ios::in); if (file) { @@ -112,14 +112,14 @@ void alsa::end_measurement(void) ifstream file; double p; - snprintf(filename, sizeof(filename), "%s/power_off_acct", sysfs_path); + snprintf(filename, PATH_MAX, "%s/power_off_acct", sysfs_path); try { file.open(filename, ios::in); if (file) { file >> end_inactive; } file.close(); - snprintf(filename, sizeof(filename), "%s/power_on_acct", sysfs_path); + snprintf(filename, PATH_MAX, "%s/power_on_acct", sysfs_path); file.open(filename, ios::in); if (file) { @@ -158,11 +158,11 @@ static void create_all_alsa_callback(const char *d_name) if (strncmp(d_name, "hwC", 3) != 0) return; - snprintf(filename, sizeof(filename), "/sys/class/sound/card0/%s/power_on_acct", d_name); + snprintf(filename, PATH_MAX, "/sys/class/sound/card0/%s/power_on_acct", d_name); if (access(filename, R_OK) != 0) return; - snprintf(filename, sizeof(filename), "/sys/class/sound/card0/%s", d_name); + snprintf(filename, PATH_MAX, "/sys/class/sound/card0/%s", d_name); bl = new class alsa(d_name, filename); all_devices.push_back(bl); register_parameter("alsa-codec-power", 0.5); @@ -200,8 +200,8 @@ void alsa::register_power_with_devlist(struct result_bundle *results, struct par const char * alsa::human_name(void) { - pt_strcpy(temp_buf, humanname); + sprintf(temp_buf, "%s", humanname); if (strlen(guilty) > 0) - snprintf(temp_buf, sizeof(temp_buf), "%s (%s)", humanname, guilty); + sprintf(temp_buf, "%s (%s)", humanname, guilty); return temp_buf; } diff --git a/src/devices/backlight.cpp b/src/devices/backlight.cpp index 609f851..d12cf98 100644 --- a/src/devices/backlight.cpp +++ b/src/devices/backlight.cpp @@ -58,14 +58,14 @@ void backlight::start_measurement(void) char filename[PATH_MAX]; ifstream file; - snprintf(filename, sizeof(filename), "%s/max_brightness", sysfs_path); + snprintf(filename, PATH_MAX, "%s/max_brightness", sysfs_path); file.open(filename, ios::in); if (file) { file >> max_level; } file.close(); - snprintf(filename, sizeof(filename), "%s/actual_brightness", sysfs_path); + snprintf(filename, PATH_MAX, "%s/actual_brightness", sysfs_path); file.open(filename, ios::in); if (file) { file >> start_level; @@ -91,19 +91,19 @@ static int dpms_screen_on(void) if (strncmp(entry->d_name, "card", 4) != 0) continue; - snprintf(filename, sizeof(filename), "/sys/class/drm/card0/%s/enabled", entry->d_name); + snprintf(filename, PATH_MAX, "/sys/class/drm/card0/%s/enabled", entry->d_name); file.open(filename, ios::in); if (!file) continue; - file.getline(line, sizeof(line)); + file.getline(line, 4096); file.close(); if (strcmp(line, "enabled") != 0) continue; - snprintf(filename, sizeof(filename), "/sys/class/drm/card0/%s/dpms", entry->d_name); + snprintf(filename, PATH_MAX, "/sys/class/drm/card0/%s/dpms", entry->d_name); file.open(filename, ios::in); if (!file) continue; - file.getline(line, sizeof(line)); + file.getline(line, 4096); file.close(); if (strcmp(line, "On") == 0) { closedir(dir); @@ -122,7 +122,7 @@ void backlight::end_measurement(void) double p; int _backlight = 0; - snprintf(filename, sizeof(filename), "%s/actual_brightness", sysfs_path); + snprintf(filename, PATH_MAX, "%s/actual_brightness", sysfs_path); file.open(filename, ios::in); if (file) { file >> end_level; @@ -137,7 +137,7 @@ void backlight::end_measurement(void) } report_utilization(name, p); - snprintf(powername, sizeof(powername), "%s-power", name); + snprintf(powername, 4096, "%s-power", name); report_utilization(powername, _backlight); } @@ -159,7 +159,7 @@ static void create_all_backlights_callback(const char *d_name) { class backlight *bl; char filename[PATH_MAX]; - snprintf(filename, sizeof(filename), "/sys/class/backlight/%s", d_name); + snprintf(filename, PATH_MAX, "/sys/class/backlight/%s", d_name); bl = new class backlight(d_name, filename); all_devices.push_back(bl); } diff --git a/src/devices/devfreq.cpp b/src/devices/devfreq.cpp index 89a36d8..afa9bb6 100644 --- a/src/devices/devfreq.cpp +++ b/src/devices/devfreq.cpp @@ -123,7 +123,7 @@ void devfreq::parse_devfreq_trans_stat(char *dname) ifstream file; char filename[256]; - snprintf(filename, sizeof(filename), "/sys/class/devfreq/%s/trans_stat", dir_name); + snprintf(filename, 256, "/sys/class/devfreq/%s/trans_stat", dir_name); file.open(filename); if (!file) diff --git a/src/devices/device.cpp b/src/devices/device.cpp index 1757a55..91ebc12 100644 --- a/src/devices/device.cpp +++ b/src/devices/device.cpp @@ -68,11 +68,11 @@ void device::register_sysfs_path(const char *path) { char current_path[PATH_MAX + 1]; int iter = 0; - pt_strcpy(current_path, path); + strcpy(current_path, path); while (iter++ < 10) { char test_path[PATH_MAX + 1]; - snprintf(test_path, sizeof(test_path), "%s/device", current_path); + sprintf(test_path, "%s/device", current_path); if (access(test_path, R_OK) == 0) strcpy(current_path, test_path); else diff --git a/src/devices/i915-gpu.cpp b/src/devices/i915-gpu.cpp index d0f1d69..c63e11f 100644 --- a/src/devices/i915-gpu.cpp +++ b/src/devices/i915-gpu.cpp @@ -30,7 +30,7 @@ #include <dirent.h> #include <unistd.h> #include <limits.h> -#include "../lib.h" + using namespace std; @@ -78,11 +78,11 @@ void create_i915_gpu(void) class i915gpu *gpu; gpu_rapl_device *rapl_dev; - pt_strcpy(filename, "/sys/kernel/debug/tracing/events/i915/i915_gem_ring_dispatch/format"); + strcpy(filename, "/sys/kernel/debug/tracing/events/i915/i915_gem_ring_dispatch/format"); if (access(filename, R_OK) !=0) { /* try an older tracepoint */ - pt_strcpy(filename, "/sys/kernel/debug/tracing/events/i915/i915_gem_request_submit/format"); + strcpy(filename, "/sys/kernel/debug/tracing/events/i915/i915_gem_request_submit/format"); if (access(filename, R_OK) != 0) return; } diff --git a/src/devices/network.cpp b/src/devices/network.cpp index f8f4212..002600b 100644 --- a/src/devices/network.cpp +++ b/src/devices/network.cpp @@ -40,7 +40,6 @@ using namespace std; #include "device.h" #include "network.h" -#include "../lib.h" #include "../parameters/parameters.h" #include "../process/process.h" extern "C" { @@ -143,38 +142,38 @@ network::network(const char *_name, const char *path): device() strncpy(sysfs_path, path, sizeof(sysfs_path)); register_sysfs_path(sysfs_path); - pt_strcpy(devname, _name); + sprintf(devname, "%s", _name); sprintf(humanname, "nic:%s", _name); strncpy(name, devname, sizeof(name)); - snprintf(devname, sizeof(devname), "%s-up", _name); + sprintf(devname, "%s-up", _name); index_up = get_param_index(devname); rindex_up = get_result_index(devname); - snprintf(devname, sizeof(devname), "%s-powerunsave", _name); + sprintf(devname, "%s-powerunsave", _name); index_powerunsave = get_param_index(devname); rindex_powerunsave = get_result_index(devname); - snprintf(devname, sizeof(devname), "%s-link-100", _name); + sprintf(devname, "%s-link-100", _name); index_link_100 = get_param_index(devname); rindex_link_100 = get_result_index(devname); - snprintf(devname, sizeof(devname), "%s-link-1000", _name); + sprintf(devname, "%s-link-1000", _name); index_link_1000 = get_param_index(devname); rindex_link_1000 = get_result_index(devname); - snprintf(devname, sizeof(devname), "%s-link-high", _name); + sprintf(devname, "%s-link-high", _name); index_link_high = get_param_index(devname); rindex_link_high = get_result_index(devname); - snprintf(devname, sizeof(devname), "%s-packets", _name); + sprintf(devname, "%s-packets", _name); index_pkts = get_param_index(devname); rindex_pkts = get_result_index(devname); memset(line, 0, 4096); filename.append("/device/driver"); if (readlink(filename.c_str(), line, 4096) > 0) { - snprintf(humanname, sizeof(humanname), _("Network interface: %s (%s)"), _name, basename(line)); + sprintf(humanname, _("Network interface: %s (%s)"), _name, basename(line)); }; } @@ -190,7 +189,7 @@ static int net_iface_up(const char *iface) if (sock<0) return 0; - pt_strcpy(ifr.ifr_name, iface); + strcpy(ifr.ifr_name, iface); /* Check if the interface is up */ ret = ioctl(sock, SIOCGIFFLAGS, &ifr); @@ -222,7 +221,7 @@ static int iface_link(const char *name) if (sock<0) return 0; - pt_strcpy(ifr.ifr_name, name); + strcpy(ifr.ifr_name, name); memset(&cmd, 0, sizeof(cmd)); @@ -250,7 +249,7 @@ static int iface_speed(const char *name) if (sock<0) return 0; - pt_strcpy(ifr.ifr_name, name); + strcpy(ifr.ifr_name, name); memset(&cmd, 0, sizeof(cmd)); @@ -354,22 +353,22 @@ static void netdev_callback(const char *d_name) f_name.append(d_name); - snprintf(devname, sizeof(devname), "%s-up", d_name); + sprintf(devname, "%s-up", d_name); register_parameter(devname); - snprintf(devname, sizeof(devname), "%s-powerunsave", d_name); + sprintf(devname, "%s-powerunsave", d_name); register_parameter(devname); - snprintf(devname, sizeof(devname), "%s-link-100", d_name); + sprintf(devname, "%s-link-100", d_name); register_parameter(devname); - snprintf(devname, sizeof(devname), "%s-link-1000", d_name); + sprintf(devname, "%s-link-1000", d_name); register_parameter(devname); - snprintf(devname, sizeof(devname), "%s-link-high", d_name); + sprintf(devname, "%s-link-high", d_name); register_parameter(devname); - snprintf(devname, sizeof(devname), "%s-packets", d_name); + sprintf(devname, "%s-packets", d_name); register_parameter(devname); network *bl = new(std::nothrow) class network(d_name, f_name.c_str()); diff --git a/src/devices/rfkill.cpp b/src/devices/rfkill.cpp index 2115b5b..7dea12e 100644 --- a/src/devices/rfkill.cpp +++ b/src/devices/rfkill.cpp @@ -52,21 +52,21 @@ rfkill::rfkill(char *_name, char *path): device() end_hard = 0; strncpy(sysfs_path, path, sizeof(sysfs_path)); register_sysfs_path(sysfs_path); - snprintf(devname, sizeof(devname), "radio:%s", _name); - snprintf(humanname, sizeof(humanname), "radio:%s", _name); + snprintf(devname, 128, "radio:%s", _name); + snprintf(humanname, 4096, "radio:%s", _name); strncpy(name, devname, sizeof(name)); register_parameter(devname); index = get_param_index(devname); rindex = get_result_index(name); memset(line, 0, 4096); - snprintf(filename, sizeof(filename), "%s/device/driver", path); - if (readlink(filename, line, sizeof(line)) > 0) { - snprintf(humanname, sizeof(humanname), _("Radio device: %s"), basename(line)); + snprintf(filename, PATH_MAX, "%s/device/driver", path); + if (readlink(filename, line, 4096) > 0) { + snprintf(humanname, 4096, _("Radio device: %s"), basename(line)); } - snprintf(filename, sizeof(filename), "%s/device/device/driver", path); - if (readlink(filename, line, sizeof(line)) > 0) { - snprintf(humanname, sizeof(humanname), _("Radio device: %s"), basename(line)); + snprintf(filename, PATH_MAX, "%s/device/device/driver", path); + if (readlink(filename, line, 4096) > 0) { + snprintf(humanname, 4096, _("Radio device: %s"), basename(line)); } } @@ -80,14 +80,14 @@ void rfkill::start_measurement(void) end_hard = 1; end_soft = 1; - snprintf(filename, sizeof(filename), "%s/hard", sysfs_path); + snprintf(filename, PATH_MAX, "%s/hard", sysfs_path); file.open(filename, ios::in); if (file) { file >> start_hard; } file.close(); - snprintf(filename, sizeof(filename), "%s/soft", sysfs_path); + snprintf(filename, PATH_MAX, "%s/soft", sysfs_path); file.open(filename, ios::in); if (file) { file >> start_soft; @@ -100,13 +100,13 @@ void rfkill::end_measurement(void) char filename[PATH_MAX]; ifstream file; - snprintf(filename, sizeof(filename), "%s/hard", sysfs_path); + snprintf(filename, PATH_MAX, "%s/hard", sysfs_path); file.open(filename, ios::in); if (file) { file >> end_hard; } file.close(); - snprintf(filename, sizeof(filename), "%s/soft", sysfs_path); + snprintf(filename, PATH_MAX, "%s/soft", sysfs_path); file.open(filename, ios::in); if (file) { file >> end_soft; @@ -143,15 +143,15 @@ static void create_all_rfkills_callback(const char *d_name) class rfkill *bl; ifstream file; - snprintf(filename, sizeof(filename), "/sys/class/rfkill/%s/name", d_name); - strncpy(name, d_name, sizeof(name) - 1); + snprintf(filename, PATH_MAX, "/sys/class/rfkill/%s/name", d_name); + strncpy(name, d_name, 4095); file.open(filename, ios::in); if (file) { file.getline(name, 100); file.close(); } - snprintf(filename, sizeof(filename), "/sys/class/rfkill/%s", d_name); + snprintf(filename, PATH_MAX, "/sys/class/rfkill/%s", d_name); bl = new class rfkill(name, filename); all_devices.push_back(bl); } diff --git a/src/devices/runtime_pm.cpp b/src/devices/runtime_pm.cpp index ccfd945..0f9c5a4 100644 --- a/src/devices/runtime_pm.cpp +++ b/src/devices/runtime_pm.cpp @@ -40,10 +40,10 @@ runtime_pmdevice::runtime_pmdevice(const char *_name, const char *path) : device() { - pt_strcpy(sysfs_path, path); + strcpy(sysfs_path, path); register_sysfs_path(sysfs_path); - pt_strcpy(name, _name); - snprintf(humanname, sizeof(humanname), "runtime-%s", _name); + strcpy(name, _name); + sprintf(humanname, "runtime-%s", _name); index = get_param_index(humanname); r_index = get_result_index(humanname); @@ -66,14 +66,14 @@ void runtime_pmdevice::start_measurement(void) after_suspended_time = 0; after_active_time = 0; - snprintf(filename, sizeof(filename), "%s/power/runtime_suspended_time", sysfs_path); + snprintf(filename, PATH_MAX, "%s/power/runtime_suspended_time", sysfs_path); file.open(filename, ios::in); if (!file) return; file >> before_suspended_time; file.close(); - snprintf(filename, sizeof(filename), "%s/power/runtime_active_time", sysfs_path); + snprintf(filename, PATH_MAX, "%s/power/runtime_active_time", sysfs_path); file.open(filename, ios::in); if (!file) return; @@ -86,14 +86,14 @@ void runtime_pmdevice::end_measurement(void) char filename[PATH_MAX]; ifstream file; - snprintf(filename, sizeof(filename), "%s/power/runtime_suspended_time", sysfs_path); + snprintf(filename, PATH_MAX, "%s/power/runtime_suspended_time", sysfs_path); file.open(filename, ios::in); if (!file) return; file >> after_suspended_time; file.close(); - snprintf(filename, sizeof(filename), "%s/power/runtime_active_time", sysfs_path); + snprintf(filename, PATH_MAX, "%s/power/runtime_active_time", sysfs_path); file.open(filename, ios::in); if (!file) return; @@ -141,7 +141,7 @@ double runtime_pmdevice::power_usage(struct result_bundle *result, struct parame void runtime_pmdevice::set_human_name(char *_name) { - pt_strcpy(humanname, _name); + strcpy(humanname, _name); } @@ -151,7 +151,7 @@ int device_has_runtime_pm(const char *sysfs_path) ifstream file; unsigned long value; - snprintf(filename, sizeof(filename), "%s/power/runtime_suspended_time", sysfs_path); + snprintf(filename, PATH_MAX, "%s/power/runtime_suspended_time", sysfs_path); file.open(filename, ios::in); if (!file) return 0; @@ -160,7 +160,7 @@ int device_has_runtime_pm(const char *sysfs_path) if (value) return 1; - snprintf(filename, sizeof(filename), "%s/power/runtime_active_time", sysfs_path); + snprintf(filename, PATH_MAX, "%s/power/runtime_active_time", sysfs_path); file.open(filename, ios::in); if (!file) return 0; @@ -180,7 +180,7 @@ static void do_bus(const char *bus) DIR *dir; char filename[PATH_MAX]; - snprintf(filename, sizeof(filename), "/sys/bus/%s/devices/", bus); + snprintf(filename, PATH_MAX, "/sys/bus/%s/devices/", bus); dir = opendir(filename); if (!dir) return; @@ -201,25 +201,25 @@ static void do_bus(const char *bus) char dev_name[4096]; bool is_adapter = false; - snprintf(filename, sizeof(filename), "/sys/bus/%s/devices/%s/new_device", bus, entry->d_name); + snprintf(filename, PATH_MAX, "/sys/bus/%s/devices/%s/new_device", bus, entry->d_name); if (access(filename, W_OK) == 0) is_adapter = true; - snprintf(filename, sizeof(filename), "/sys/bus/%s/devices/%s/name", bus, entry->d_name); + snprintf(filename, PATH_MAX, "/sys/bus/%s/devices/%s/name", bus, entry->d_name); file.open(filename, ios::in); if (file) { getline(file, devname); file.close(); } - snprintf(dev_name, sizeof(dev_name), _("I2C %s (%s): %s"), (is_adapter ? _("Adapter") : _("Device")), entry->d_name, devname.c_str()); + snprintf(dev_name, 4096, _("I2C %s (%s): %s"), (is_adapter ? _("Adapter") : _("Device")), entry->d_name, devname.c_str()); dev->set_human_name(dev_name); } if (strcmp(bus, "pci") == 0) { uint16_t vendor = 0, device = 0; - snprintf(filename, sizeof(filename), "/sys/bus/%s/devices/%s/vendor", bus, entry->d_name); + snprintf(filename, PATH_MAX, "/sys/bus/%s/devices/%s/vendor", bus, entry->d_name); file.open(filename, ios::in); if (file) { @@ -228,7 +228,7 @@ static void do_bus(const char *bus) } - snprintf(filename, sizeof(filename), "/sys/bus/%s/devices/%s/device", bus, entry->d_name); + snprintf(filename, PATH_MAX, "/sys/bus/%s/devices/%s/device", bus, entry->d_name); file.open(filename, ios::in); if (file) { file >> hex >> device; @@ -237,7 +237,7 @@ static void do_bus(const char *bus) if (vendor && device) { char devname[4096]; - snprintf(devname, sizeof(devname), _("PCI Device: %s"), + snprintf(devname, 4096, _("PCI Device: %s"), pci_id_to_name(vendor, device, filename, 4095)); dev->set_human_name(devname); } diff --git a/src/devices/thinkpad-fan.cpp b/src/devices/thinkpad-fan.cpp index 8e2ce53..d9bb026 100644 --- a/src/devices/thinkpad-fan.cpp +++ b/src/devices/thinkpad-fan.cpp @@ -78,7 +78,7 @@ void create_thinkpad_fan(void) char filename[PATH_MAX]; class thinkpad_fan *fan; - pt_strcpy(filename, "/sys/devices/platform/thinkpad_hwmon/fan1_input"); + strcpy(filename, "/sys/devices/platform/thinkpad_hwmon/fan1_input"); if (access(filename, R_OK) !=0) return; diff --git a/src/devices/thinkpad-light.cpp b/src/devices/thinkpad-light.cpp index d047ab3..945161a 100644 --- a/src/devices/thinkpad-light.cpp +++ b/src/devices/thinkpad-light.cpp @@ -76,7 +76,7 @@ void create_thinkpad_light(void) char filename[PATH_MAX]; class thinkpad_light *light; - pt_strcpy(filename, "/sys/devices/platform/thinkpad_acpi/leds/tpacpi::thinklight/brightness"); + strcpy(filename, "/sys/devices/platform/thinkpad_acpi/leds/tpacpi::thinklight/brightness"); if (access(filename, R_OK) !=0) return; diff --git a/src/devices/usb.cpp b/src/devices/usb.cpp index aa9c227..eb8c718 100644 --- a/src/devices/usb.cpp +++ b/src/devices/usb.cpp @@ -43,11 +43,11 @@ usbdevice::usbdevice(const char *_name, const char *path, const char *devid): de char vendor[4096]; char product[4096]; - pt_strcpy(sysfs_path, path); + strcpy(sysfs_path, path); register_sysfs_path(sysfs_path); - pt_strcpy(name, _name); - pt_strcpy(devname, devid); - snprintf(humanname, sizeof(humanname), _("USB device: %s"), pretty_print(devid, vendor, 4096)); + strcpy(name, _name); + strcpy(devname, devid); + sprintf(humanname, _("USB device: %s"), pretty_print(devid, vendor, 4096)); active_before = 0; active_after = 0; connected_before = 0; @@ -60,7 +60,7 @@ usbdevice::usbdevice(const char *_name, const char *path, const char *devid): de /* root ports and hubs should count as 0 power ... their activity is derived */ - snprintf(filename, sizeof(filename), "%s/bDeviceClass", path); + snprintf(filename, PATH_MAX, "%s/bDeviceClass", path); file.open(filename, ios::in); if (file) { int dclass = 0; @@ -73,7 +73,7 @@ usbdevice::usbdevice(const char *_name, const char *path, const char *devid): de vendor[0] = 0; product[0] = 0; - snprintf(filename, sizeof(filename), "%s/manufacturer", path); + snprintf(filename, PATH_MAX, "%s/manufacturer", path); file.open(filename, ios::in); if (file) { file.getline(vendor, 2047); @@ -81,18 +81,18 @@ usbdevice::usbdevice(const char *_name, const char *path, const char *devid): de vendor[0] = 0; file.close(); }; - snprintf(filename, sizeof(filename), "%s/product", path); + snprintf(filename, PATH_MAX, "%s/product", path); file.open(filename, ios::in); if (file) { file.getline(product, 2040); file.close(); }; if (strlen(vendor) && strlen(product)) - snprintf(humanname, sizeof(humanname), _("USB device: %s (%s)"), product, vendor); + snprintf(humanname, 4096, _("USB device: %s (%s)"), product, vendor); else if (strlen(product)) - snprintf(humanname, sizeof(humanname), _("USB device: %s"), product); + snprintf(humanname, 4096, _("USB device: %s"), product); else if (strlen(vendor)) - snprintf(humanname, sizeof(humanname), _("USB device: %s"), vendor); + snprintf(humanname, 4096, _("USB device: %s"), vendor); } @@ -107,14 +107,14 @@ void usbdevice::start_measurement(void) connected_before = 0; connected_after = 0; - snprintf(fullpath, sizeof(fullpath), "%s/power/active_duration", sysfs_path); + snprintf(fullpath, PATH_MAX, "%s/power/active_duration", sysfs_path); file.open(fullpath, ios::in); if (file) { file >> active_before; } file.close(); - snprintf(fullpath, sizeof(fullpath), "%s/power/connected_duration", sysfs_path); + snprintf(fullpath, PATH_MAX, "%s/power/connected_duration", sysfs_path); file.open(fullpath, ios::in); if (file) { file >> connected_before; @@ -127,14 +127,14 @@ void usbdevice::end_measurement(void) ifstream file; char fullpath[PATH_MAX]; - snprintf(fullpath, sizeof(fullpath), "%s/power/active_duration", sysfs_path); + snprintf(fullpath, PATH_MAX, "%s/power/active_duration", sysfs_path); file.open(fullpath, ios::in); if (file) { file >> active_after; } file.close(); - snprintf(fullpath, sizeof(fullpath), "%s/power/connected_duration", sysfs_path); + snprintf(fullpath, PATH_MAX, "%s/power/connected_duration", sysfs_path); file.open(fullpath, ios::in); if (file) { file >> connected_after; @@ -194,24 +194,24 @@ static void create_all_usb_devices_callback(const char *d_name) char vendorid[64], devid[64]; char devid_name[4096]; - snprintf(filename, sizeof(filename), "/sys/bus/usb/devices/%s", d_name); - snprintf(device_name, sizeof(device_name), "%s/power/active_duration", filename); + snprintf(filename, PATH_MAX, "/sys/bus/usb/devices/%s", d_name); + snprintf(device_name, PATH_MAX, "%s/power/active_duration", filename); if (access(device_name, R_OK) != 0) return; - snprintf(device_name, sizeof(device_name), "%s/idVendor", filename); + snprintf(device_name, PATH_MAX, "%s/idVendor", filename); file.open(device_name, ios::in); if (file) file.getline(vendorid, 64); file.close(); - snprintf(device_name, sizeof(device_name), "%s/idProduct", filename); + snprintf(device_name, PATH_MAX, "%s/idProduct", filename); file.open(device_name, ios::in); if (file) file.getline(devid, 64); file.close(); - snprintf(devid_name, sizeof(devid_name), "usb-device-%s-%s", vendorid, devid); - snprintf(device_name, sizeof(device_name), "usb-device-%s-%s-%s", d_name, vendorid, devid); + snprintf(devid_name, 4096, "usb-device-%s-%s", vendorid, devid); + snprintf(device_name, PATH_MAX, "usb-device-%s-%s-%s", d_name, vendorid, devid); if (result_device_exists(device_name)) return; diff --git a/src/devlist.cpp b/src/devlist.cpp index e6a4f4c..bf48f23 100644 --- a/src/devlist.cpp +++ b/src/devlist.cpp @@ -125,7 +125,7 @@ void collect_open_devices(void) if (strcmp(entry->d_name, "self") == 0) continue; - snprintf(filename, sizeof(filename), "/proc/%s/fd/", entry->d_name); + snprintf(filename, PATH_MAX, "/proc/%s/fd/", entry->d_name); dir2 = opendir(filename); if (!dir2) @@ -138,9 +138,9 @@ void collect_open_devices(void) break; if (!isdigit(entry2->d_name[0])) continue; - snprintf(filename, sizeof(filename), "/proc/%s/fd/%s", entry->d_name, entry2->d_name); - memset(link, 0, sizeof(link)); - ret = readlink(filename, link, sizeof(link) - 1); + snprintf(filename, PATH_MAX, "/proc/%s/fd/%s", entry->d_name, entry2->d_name); + memset(link, 0, PATH_MAX); + ret = readlink(filename, link, PATH_MAX - 1); if (ret < 0) continue; @@ -263,7 +263,7 @@ void register_devpower(const char *devstring, double power, class device *_dev) if (!dev) { dev = (struct devpower *)malloc(sizeof (struct devpower)); - pt_strcpy(dev->device, devstring); + strcpy(dev->device, devstring); dev->power = 0.0; devpower.push_back(dev); } @@ -333,13 +333,13 @@ void report_show_open_devices(void) for (i = 0; i < target->size(); i++) { proc[0] = 0; if (strcmp(prev, (*target)[i]->comm) != 0) - snprintf(proc, sizeof(proc), "%s", (*target)[i]->comm); + sprintf(proc, "%s", (*target)[i]->comm); process_data[idx]=string(proc); idx+=1; process_data[idx]=string((*target)[i]->device); idx+=1; - snprintf(prev, sizeof(prev), "%s", (*target)[i]->comm); + sprintf(prev, "%s", (*target)[i]->comm); } /* Report Output */ diff --git a/src/lib.cpp b/src/lib.cpp index 56e1681..29f109f 100644 --- a/src/lib.cpp +++ b/src/lib.cpp @@ -240,7 +240,7 @@ string read_sysfs_string(const char *format, const char *param) char filename[PATH_MAX]; - snprintf(filename, sizeof(filename), format, param); + snprintf(filename, PATH_MAX, format, param); file.open(filename, ios::in); if (!file) @@ -475,10 +475,10 @@ int read_msr(int cpu, uint64_t offset, uint64_t *value) int fd; char msr_path[256]; - snprintf(msr_path, sizeof(msr_path), "/dev/cpu/%d/msr", cpu); + snprintf(msr_path, 256, "/dev/cpu/%d/msr", cpu); if (access(msr_path, R_OK) != 0){ - snprintf(msr_path, sizeof(msr_path), "/dev/msr%d", cpu); + snprintf(msr_path, 256, "/dev/msr%d", cpu); if (access(msr_path, R_OK) != 0){ fprintf(stderr, @@ -507,10 +507,10 @@ int write_msr(int cpu, uint64_t offset, uint64_t value) int fd; char msr_path[256]; - snprintf(msr_path, sizeof(msr_path), "/dev/cpu/%d/msr", cpu); + snprintf(msr_path, 256, "/dev/cpu/%d/msr", cpu); if (access(msr_path, R_OK) != 0){ - snprintf(msr_path, sizeof(msr_path), "/dev/msr%d", cpu); + snprintf(msr_path, 256, "/dev/msr%d", cpu); if (access(msr_path, R_OK) != 0){ fprintf(stderr, @@ -28,7 +28,6 @@ #include <libintl.h> #include <stdint.h> #include <stdlib.h> -#include <cstring> /* Include only for Automake builds */ #ifdef HAVE_CONFIG_H @@ -76,12 +75,6 @@ extern char *fmt_prefix(double n, char *buf); extern char *pretty_print(const char *str, char *buf, int len); extern int equals(double a, double b); -template<size_t N> void pt_strcpy(char (&d)[N], const char *s) -{ - strncpy(d, s, N); - d[N-1] = '\0'; -} - typedef void (*callback)(const char*); extern void process_directory(const char *d_name, callback fn); extern int utf_ok; diff --git a/src/main.cpp b/src/main.cpp index b60d7b5..2a2a6e9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -419,7 +419,7 @@ int main(int argc, char **argv) break; case 'C': /* csv report */ reporttype = REPORT_CSV; - snprintf(filename, sizeof(filename), "%s", optarg ? optarg : "powertop.csv"); + snprintf(filename, PATH_MAX, "%s", optarg ? optarg : "powertop.csv"); if (!strlen(filename)) { fprintf(stderr, _("Invalid CSV filename\n")); @@ -435,7 +435,7 @@ int main(int argc, char **argv) break; case 'r': /* html report */ reporttype = REPORT_HTML; - snprintf(filename, sizeof(filename), "%s", optarg ? optarg : "powertop.html"); + snprintf(filename, PATH_MAX, "%s", optarg ? optarg : "powertop.html"); if (!strlen(filename)) { fprintf(stderr, _("Invalid HTML filename\n")); @@ -453,7 +453,7 @@ int main(int argc, char **argv) time_out = (optarg ? atoi(optarg) : 20); break; case 'w': /* measure workload */ - snprintf(workload, sizeof(workload), "%s", optarg ? optarg : ""); + snprintf(workload, PATH_MAX, "%s", optarg ? optarg : ""); break; case 'V': print_version(); diff --git a/src/measurement/acpi.cpp b/src/measurement/acpi.cpp index 2c9815d..a55109b 100644 --- a/src/measurement/acpi.cpp +++ b/src/measurement/acpi.cpp @@ -30,7 +30,6 @@ #include <stdio.h> #include <stdlib.h> #include <limits.h> -#include "../lib.h" using namespace std; @@ -73,7 +72,7 @@ void acpi_power_meter::measure(void) voltage = 0; capacity = 0; - snprintf(filename, sizeof(filename), "/proc/acpi/battery/%s/state", battery_name); + snprintf(filename, PATH_MAX, "/proc/acpi/battery/%s/state", battery_name); file.open(filename, ios::in); if (!file) @@ -81,7 +80,7 @@ void acpi_power_meter::measure(void) while (file) { char *c; - file.getline(line, sizeof(line)); + file.getline(line, 4096); if (strstr(line, "present:") && (strstr(line, "yes") == NULL)) { return; @@ -97,7 +96,7 @@ void acpi_power_meter::measure(void) c = strchr(c, ' '); if (c) { c++; - pt_strcpy(rate_units, c); + strcpy(rate_units, c); } else { _rate = 0; strcpy(rate_units, "Unknown"); @@ -112,7 +111,7 @@ void acpi_power_meter::measure(void) c = strchr(c, ' '); if (c) { c++; - pt_strcpy(capacity_units, c); + strcpy(capacity_units, c); } else { _capacity = 0; strcpy(capacity_units, "Unknown"); @@ -126,7 +125,7 @@ void acpi_power_meter::measure(void) c = strchr(c, ' '); if (c) { c++; - pt_strcpy(voltage_units, c); + strcpy(voltage_units, c); } else { _voltage = 0; strcpy(voltage_units, "Unknown"); diff --git a/src/measurement/sysfs.cpp b/src/measurement/sysfs.cpp index 8126104..794f88f 100644 --- a/src/measurement/sysfs.cpp +++ b/src/measurement/sysfs.cpp @@ -41,7 +41,7 @@ bool sysfs_power_meter::get_sysfs_attr(const char *attribute, int *value) char filename[PATH_MAX]; bool ok; - snprintf(filename, sizeof(filename), "/sys/class/power_supply/%s/%s", name, attribute); + snprintf(filename, PATH_MAX, "/sys/class/power_supply/%s/%s", name, attribute); *value = read_sysfs(filename, &ok); return ok; diff --git a/src/parameters/parameters.cpp b/src/parameters/parameters.cpp index 3bd5c05..511cdcf 100644 --- a/src/parameters/parameters.cpp +++ b/src/parameters/parameters.cpp @@ -454,9 +454,9 @@ char* get_param_directory(const char *filename) static char tempfilename[PATH_MAX]; if (access("/var/cache/powertop", W_OK ) == 0) - snprintf(tempfilename, sizeof(tempfilename), "/var/cache/powertop/%s", filename); + snprintf(tempfilename, PATH_MAX, "/var/cache/powertop/%s", filename); if (access("/data/local/powertop", W_OK ) == 0) - snprintf(tempfilename, sizeof(tempfilename), "/data/local/powertop/%s", filename); + snprintf(tempfilename, PATH_MAX, "/data/local/powertop/%s", filename); return tempfilename; }; diff --git a/src/process/do_process.cpp b/src/process/do_process.cpp index 391cb7f..91dc900 100644 --- a/src/process/do_process.cpp +++ b/src/process/do_process.cpp @@ -857,7 +857,7 @@ void process_update_display(void) format_watts(all_power[i]->Witts(), power, 10); if (!show_power) strcpy(power, " "); - snprintf(name, sizeof(name), "%s", all_power[i]->type()); + sprintf(name, "%s", all_power[i]->type()); align_string(name, 14, 20); @@ -867,18 +867,18 @@ void process_update_display(void) usage[0] = 0; if (all_power[i]->usage_units()) { if (all_power[i]->usage() < 1000) - snprintf(usage, sizeof(usage), "%5.1f%s", all_power[i]->usage(), all_power[i]->usage_units()); + sprintf(usage, "%5.1f%s", all_power[i]->usage(), all_power[i]->usage_units()); else - snprintf(usage, sizeof(usage), "%5i%s", (int)all_power[i]->usage(), all_power[i]->usage_units()); + sprintf(usage, "%5i%s", (int)all_power[i]->usage(), all_power[i]->usage_units()); } align_string(usage, 14, 20); - snprintf(events, sizeof(events), "%5.1f", all_power[i]->events()); + sprintf(events, "%5.1f", all_power[i]->events()); if (!all_power[i]->show_events()) events[0] = 0; else if (all_power[i]->events() <= 0.3) - snprintf(events, sizeof(events), "%5.2f", all_power[i]->events()); + sprintf(events, "%5.2f", all_power[i]->events()); align_string(events, 12, 20); wprintw(win, "%s %s %s %s %s\n", power, usage, events, name, pretty_print(all_power[i]->description(), descr, 128)); @@ -944,7 +944,7 @@ void report_process_update_display(void) if (!show_power) strcpy(power, " "); - snprintf(name, sizeof(name), "%s", all_power[i]->type()); + sprintf(name, "%s", all_power[i]->type()); if (strcmp(name, "Device") == 0) continue; @@ -956,17 +956,17 @@ void report_process_update_display(void) usage[0] = 0; if (all_power[i]->usage_units()) { if (all_power[i]->usage() < 1000) - snprintf(usage, sizeof(usage), "%5.1f%s", all_power[i]->usage(), all_power[i]->usage_units()); + sprintf(usage, "%5.1f%s", all_power[i]->usage(), all_power[i]->usage_units()); else - snprintf(usage, sizeof(usage), "%5i%s", (int)all_power[i]->usage(), all_power[i]->usage_units()); + sprintf(usage, "%5i%s", (int)all_power[i]->usage(), all_power[i]->usage_units()); } - snprintf(wakes, sizeof(wakes), "%5.1f", all_power[i]->wake_ups / measurement_time); + sprintf(wakes, "%5.1f", all_power[i]->wake_ups / measurement_time); if (all_power[i]->wake_ups / measurement_time <= 0.3) - snprintf(wakes, sizeof(wakes), "%5.2f", all_power[i]->wake_ups / measurement_time); - snprintf(gpus, sizeof(gpus), "%5.1f", all_power[i]->gpu_ops / measurement_time); - snprintf(disks, sizeof(disks), "%5.1f (%5.1f)", all_power[i]->hard_disk_hits / measurement_time, + sprintf(wakes, "%5.2f", all_power[i]->wake_ups / measurement_time); + sprintf(gpus, "%5.1f", all_power[i]->gpu_ops / measurement_time); + sprintf(disks, "%5.1f (%5.1f)", all_power[i]->hard_disk_hits / measurement_time, all_power[i]->disk_hits / measurement_time); - snprintf(xwakes, sizeof(xwakes), "%5.1f", all_power[i]->xwakes / measurement_time); + sprintf(xwakes, "%5.1f", all_power[i]->xwakes / measurement_time); if (!all_power[i]->show_events()) { wakes[0] = 0; gpus[0] = 0; @@ -1087,7 +1087,7 @@ void report_summary(void) if (!show_power) strcpy(power, " "); - snprintf(name, sizeof(name), "%s", all_power[i]->type()); + sprintf(name, "%s", all_power[i]->type()); if (i > total) break; @@ -1099,17 +1099,17 @@ void report_summary(void) usage[0] = 0; if (all_power[i]->usage_units()) { if (all_power[i]->usage() < 1000) - snprintf(usage, sizeof(usage), "%5.1f%s", all_power[i]->usage_summary(), + sprintf(usage, "%5.1f%s", all_power[i]->usage_summary(), all_power[i]->usage_units_summary()); else - snprintf(usage, sizeof(usage), "%5i%s", (int)all_power[i]->usage_summary(), + sprintf(usage, "%5i%s", (int)all_power[i]->usage_summary(), all_power[i]->usage_units_summary()); } - snprintf(events, sizeof(events), "%5.1f", all_power[i]->events()); + sprintf(events, "%5.1f", all_power[i]->events()); if (!all_power[i]->show_events()) events[0] = 0; else if (all_power[i]->events() <= 0.3) - snprintf(events, sizeof(events), "%5.2f", all_power[i]->events()); + sprintf(events, "%5.2f", all_power[i]->events()); summary_data[idx]=string(usage); idx+=1; diff --git a/src/process/interrupt.cpp b/src/process/interrupt.cpp index 53b0367..8ca756f 100644 --- a/src/process/interrupt.cpp +++ b/src/process/interrupt.cpp @@ -51,7 +51,7 @@ interrupt::interrupt(const char *_handler, int _number) : power_consumer() number = _number; strncpy(handler, _handler, 31); raw_count = 0; - snprintf(desc, sizeof(desc), "[%i] %s", number, pretty_print(handler, buf, 128)); + sprintf(desc, "[%i] %s", number, pretty_print(handler, buf, 128)); } @@ -98,7 +98,7 @@ class interrupt * find_create_interrupt(const char *_handler, int nr, int cpu) unsigned int i; class interrupt *new_irq; - pt_strcpy(handler, _handler); + strcpy(handler, _handler); if (strcmp(handler, "timer")==0) sprintf(handler, "timer/%i", cpu); diff --git a/src/process/process.cpp b/src/process/process.cpp index 25de86f..34dc68d 100644 --- a/src/process/process.cpp +++ b/src/process/process.cpp @@ -33,7 +33,6 @@ #include <iostream> #include <fstream> -#include "../lib.h" vector <class process *> all_processes; @@ -90,7 +89,7 @@ process::process(const char *_comm, int _pid, int _tid) : power_consumer() char line[4097]; ifstream file; - pt_strcpy(comm, _comm); + strcpy(comm, _comm); pid = _pid; is_idle = 0; running = 0; @@ -121,7 +120,7 @@ process::process(const char *_comm, int _pid, int _tid) : power_consumer() if (strncmp(_comm, "kondemand/", 10) == 0) is_idle = 1; - pt_strcpy(desc, comm); + strcpy(desc, comm); sprintf(line, "/proc/%i/cmdline", _pid); file.open(line, ios::binary); @@ -131,7 +130,7 @@ process::process(const char *_comm, int _pid, int _tid) : power_consumer() file.close(); if (strlen(line) < 1) { is_kernel = 1; - snprintf(desc, sizeof(desc), "[%s]", comm); + sprintf(desc, "[%s]", comm); } else { int sz = sizeof(desc) - 1; cmdline_to_string(line); diff --git a/src/process/processdevice.cpp b/src/process/processdevice.cpp index 00f48c8..5bb269e 100644 --- a/src/process/processdevice.cpp +++ b/src/process/processdevice.cpp @@ -39,7 +39,7 @@ device_consumer::device_consumer(class device *dev) : power_consumer() const char * device_consumer::description(void) { - snprintf(str, sizeof(str), "%s", device->human_name()); + sprintf(str, "%s", device->human_name()); return str; } diff --git a/src/process/timer.cpp b/src/process/timer.cpp index d2b5abe..1ca8c25 100644 --- a/src/process/timer.cpp +++ b/src/process/timer.cpp @@ -125,7 +125,7 @@ const char * timer::description(void) if (child_runtime > accumulated_runtime) child_runtime = 0; - snprintf(desc, sizeof(desc), "%s", handler); + sprintf(desc, "%s", handler); return desc; } diff --git a/src/process/work.cpp b/src/process/work.cpp index 797f766..e62e5d3 100644 --- a/src/process/work.cpp +++ b/src/process/work.cpp @@ -40,7 +40,7 @@ work::work(unsigned long address) : power_consumer() { strncpy(handler, kernel_function(address), 31); raw_count = 0; - snprintf(desc, sizeof(desc), "%s", handler); + sprintf(desc, "%s", handler); } diff --git a/src/report/report.cpp b/src/report/report.cpp index ddb2e30..6bf905b 100644 --- a/src/report/report.cpp +++ b/src/report/report.cpp @@ -174,7 +174,7 @@ void init_report_output(char *filename_str, int iterations) char datestr[200]; if (iterations == 1) - snprintf(reportout.filename, sizeof(reportout.filename), "%s", filename_str); + snprintf(reportout.filename, PATH_MAX, "%s", filename_str); else { filename = string(filename_str); @@ -185,7 +185,7 @@ void init_report_output(char *filename_str, int iterations) memset(&stamp, 0, sizeof(time_t)); stamp = time(NULL); strftime(datestr, sizeof(datestr), "%Y%m%d-%H%M%S", localtime(&stamp)); - snprintf(reportout.filename, sizeof(reportout.filename), "%s-%s%s", + snprintf(reportout.filename, PATH_MAX, "%s-%s%s", filename.substr(0, period).c_str(), datestr, filename.substr(period).c_str()); } diff --git a/src/tuning/bluetooth.cpp b/src/tuning/bluetooth.cpp index dab46d7..9be327e 100644 --- a/src/tuning/bluetooth.cpp +++ b/src/tuning/bluetooth.cpp @@ -46,8 +46,8 @@ bt_tunable::bt_tunable(void) : tunable("", 1.0, _("Good"), _("Bad"), _("Unknown")) { sprintf(desc, _("Bluetooth device interface status")); - pt_strcpy(toggle_bad, "/usr/sbin/hciconfig hci0 up &> /dev/null &"); - pt_strcpy(toggle_good, "/usr/sbin/hciconfig hci0 down &> /dev/null"); + strcpy(toggle_bad, "/usr/sbin/hciconfig hci0 up &> /dev/null &"); + strcpy(toggle_good, "/usr/sbin/hciconfig hci0 down &> /dev/null"); } diff --git a/src/tuning/ethernet.cpp b/src/tuning/ethernet.cpp index 6b1f393..da04711 100644 --- a/src/tuning/ethernet.cpp +++ b/src/tuning/ethernet.cpp @@ -52,7 +52,7 @@ ethernet_tunable::ethernet_tunable(const char *iface) : tunable("", 0.3, _("Good memset(interf, 0, sizeof(interf)); strncpy(interf, iface, sizeof(interf)); sprintf(desc, _("Wake-on-lan status for device %s"), iface); - snprintf(toggle_good, sizeof(toggle_good), "ethtool -s %s wol d;", iface); + snprintf(toggle_good, 4096, "ethtool -s %s wol d;", iface); } @@ -71,7 +71,7 @@ int ethernet_tunable::good_bad(void) if (sock<0) return result; - pt_strcpy(ifr.ifr_name, interf); + strcpy(ifr.ifr_name, interf); /* Check if the interf is up */ ret = ioctl(sock, SIOCGIFFLAGS, &ifr); @@ -107,7 +107,7 @@ void ethernet_tunable::toggle(void) if (sock<0) return; - pt_strcpy(ifr.ifr_name, interf); + strcpy(ifr.ifr_name, interf); /* Check if the interface is up */ ret = ioctl(sock, SIOCGIFFLAGS, &ifr); diff --git a/src/tuning/runtime.cpp b/src/tuning/runtime.cpp index 9b6abed..e226695 100644 --- a/src/tuning/runtime.cpp +++ b/src/tuning/runtime.cpp @@ -53,7 +53,7 @@ runtime_tunable::runtime_tunable(const char *path, const char *bus, const char * char filename[PATH_MAX]; uint16_t vendor = 0, device = 0; - snprintf(filename, sizeof(filename), "/sys/bus/%s/devices/%s/vendor", bus, dev); + snprintf(filename, PATH_MAX, "/sys/bus/%s/devices/%s/vendor", bus, dev); file.open(filename, ios::in); if (file) { @@ -62,7 +62,7 @@ runtime_tunable::runtime_tunable(const char *path, const char *bus, const char * } - snprintf(filename, sizeof(filename), "/sys/bus/%s/devices/%s/device", bus, dev); + snprintf(filename, PATH_MAX, "/sys/bus/%s/devices/%s/device", bus, dev); file.open(filename, ios::in); if (file) { file >> hex >> device; @@ -78,8 +78,8 @@ runtime_tunable::runtime_tunable(const char *path, const char *bus, const char * } - snprintf(toggle_good, sizeof(toggle_good), "echo 'auto' > '%s';", runtime_path); - snprintf(toggle_bad, sizeof(toggle_bad), "echo 'on' > '%s';", runtime_path); + snprintf(toggle_good, 4096, "echo 'auto' > '%s';", runtime_path); + snprintf(toggle_bad, 4096, "echo 'on' > '%s';", runtime_path); } int runtime_tunable::good_bad(void) @@ -126,7 +126,7 @@ void add_runtime_tunables(const char *bus) DIR *dir; char filename[PATH_MAX]; - snprintf(filename, sizeof(filename), "/sys/bus/%s/devices/", bus); + snprintf(filename, PATH_MAX, "/sys/bus/%s/devices/", bus); dir = opendir(filename); if (!dir) return; @@ -140,13 +140,13 @@ void add_runtime_tunables(const char *bus) if (entry->d_name[0] == '.') continue; - snprintf(filename, sizeof(filename), "/sys/bus/%s/devices/%s/power/control", bus, entry->d_name); + snprintf(filename, PATH_MAX, "/sys/bus/%s/devices/%s/power/control", bus, entry->d_name); if (access(filename, R_OK) != 0) continue; - snprintf(filename, sizeof(filename), "/sys/bus/%s/devices/%s", bus, entry->d_name); + snprintf(filename, PATH_MAX, "/sys/bus/%s/devices/%s", bus, entry->d_name); runtime = new class runtime_tunable(filename, bus, entry->d_name); diff --git a/src/tuning/tunable.cpp b/src/tuning/tunable.cpp index 827b913..83595ea 100644 --- a/src/tuning/tunable.cpp +++ b/src/tuning/tunable.cpp @@ -26,7 +26,6 @@ #include "tuning.h" #include "tunable.h" #include <string.h> -#include "../lib.h" vector<class tunable *> all_tunables; vector<class tunable *> all_untunables; @@ -35,10 +34,10 @@ vector<class tunable *> all_untunables; tunable::tunable(const char *str, double _score, const char *good, const char *bad, const char *neutral) { score = _score; - pt_strcpy(desc, str); - pt_strcpy(good_string, good); - pt_strcpy(bad_string, bad); - pt_strcpy(neutral_string, neutral); + strcpy(desc, str); + strcpy(good_string, good); + strcpy(bad_string, bad); + strcpy(neutral_string, neutral); } @@ -46,7 +45,7 @@ tunable::tunable(void) { score = 0; desc[0] = 0; - pt_strcpy(good_string, _("Good")); - pt_strcpy(bad_string, _("Bad")); - pt_strcpy(neutral_string, _("Unknown")); + strcpy(good_string, _("Good")); + strcpy(bad_string, _("Bad")); + strcpy(neutral_string, _("Unknown")); } diff --git a/src/tuning/tuning.cpp b/src/tuning/tuning.cpp index 005bb4b..a701cdb 100644 --- a/src/tuning/tuning.cpp +++ b/src/tuning/tuning.cpp @@ -113,8 +113,8 @@ static void __tuning_update_display(int cursor_pos) for (i = 0; i < all_tunables.size(); i++) { char res[128]; char desc[4096]; - pt_strcpy(res, all_tunables[i]->result_string()); - pt_strcpy(desc, all_tunables[i]->description()); + strcpy(res, all_tunables[i]->result_string()); + strcpy(desc, all_tunables[i]->description()); while (strlen(res) < 12) strcat(res, " "); diff --git a/src/tuning/tuningi2c.cpp b/src/tuning/tuningi2c.cpp index b75e811..d207ca0 100644 --- a/src/tuning/tuningi2c.cpp +++ b/src/tuning/tuningi2c.cpp @@ -38,7 +38,7 @@ i2c_tunable::i2c_tunable(const char *path, const char *name, bool is_adapter) : char filename[PATH_MAX]; string devname; - snprintf(filename, sizeof(filename), "%s/name", path); + snprintf(filename, PATH_MAX, "%s/name", path); file.open(filename, ios::in); if (file) { getline(file, devname); @@ -46,20 +46,20 @@ i2c_tunable::i2c_tunable(const char *path, const char *name, bool is_adapter) : } if (is_adapter) { - snprintf(i2c_path, sizeof(i2c_path), "%s/device/power/control", path); - snprintf(filename, sizeof(filename), "%s/device", path); + snprintf(i2c_path, PATH_MAX, "%s/device/power/control", path); + snprintf(filename, PATH_MAX, "%s/device", path); } else { - snprintf(i2c_path, sizeof(i2c_path), "%s/power/control", path); - snprintf(filename, sizeof(filename), "%s/device", path); + snprintf(i2c_path, PATH_MAX, "%s/power/control", path); + snprintf(filename, PATH_MAX, "%s/device", path); } if (device_has_runtime_pm(filename)) - snprintf(desc, sizeof(desc), _("Runtime PM for I2C %s %s (%s)"), (is_adapter ? _("Adapter") : _("Device")), name, (devname.empty() ? "" : devname.c_str())); + snprintf(desc, 4096, _("Runtime PM for I2C %s %s (%s)"), (is_adapter ? _("Adapter") : _("Device")), name, (devname.empty() ? "" : devname.c_str())); else - snprintf(desc, sizeof(desc), _("I2C %s %s has no runtime power management"), (is_adapter ? _("Adapter") : _("Device")), name); + snprintf(desc, 4096, _("I2C %s %s has no runtime power management"), (is_adapter ? _("Adapter") : _("Device")), name); - snprintf(toggle_good, sizeof(toggle_good), "echo 'auto' > '%s';", i2c_path); - snprintf(toggle_bad, sizeof(toggle_bad), "echo 'on' > '%s';", i2c_path); + snprintf(toggle_good, 4096, "echo 'auto' > '%s';", i2c_path); + snprintf(toggle_bad, 4096, "echo 'on' > '%s';", i2c_path); } int i2c_tunable::good_bad(void) diff --git a/src/tuning/tuningsysfs.cpp b/src/tuning/tuningsysfs.cpp index 954f52e..811977d 100644 --- a/src/tuning/tuningsysfs.cpp +++ b/src/tuning/tuningsysfs.cpp @@ -44,11 +44,11 @@ sysfs_tunable::sysfs_tunable(const char *str, const char *_sysfs_path, const char *_target_content) : tunable(str, 1.0, _("Good"), _("Bad"), _("Unknown")) { - pt_strcpy(sysfs_path, _sysfs_path); - pt_strcpy(target_value, _target_content); + strcpy(sysfs_path, _sysfs_path); + strcpy(target_value, _target_content); bad_value[0] = 0; - snprintf(toggle_good, sizeof(toggle_good), "echo '%s' > '%s';", target_value, sysfs_path); - snprintf(toggle_bad, sizeof(toggle_bad), "echo '%s' > '%s';", bad_value, sysfs_path); + snprintf(toggle_good, 4096, "echo '%s' > '%s';", target_value, sysfs_path); + snprintf(toggle_bad, 4096, "echo '%s' > '%s';", bad_value, sysfs_path); } int sysfs_tunable::good_bad(void) @@ -69,7 +69,7 @@ int sysfs_tunable::good_bad(void) if (strcmp(current_value, target_value) == 0) return TUNE_GOOD; - pt_strcpy(bad_value, current_value); + strcpy(bad_value, current_value); return TUNE_BAD; } @@ -119,8 +119,8 @@ static void add_sata_tunables_callback(const char *d_name) char filename[PATH_MAX]; char msg[4096]; - snprintf(filename, sizeof(filename), "/sys/class/scsi_host/%s/link_power_management_policy", d_name); - snprintf(msg, sizeof(msg), _("Enable SATA link power management for %s"), d_name); + snprintf(filename, PATH_MAX, "/sys/class/scsi_host/%s/link_power_management_policy", d_name); + snprintf(msg, 4096, _("Enable SATA link power management for %s"), d_name); add_sysfs_tunable(msg, filename,"min_power"); } diff --git a/src/tuning/tuningusb.cpp b/src/tuning/tuningusb.cpp index 3b7b2b1..12f9ce2 100644 --- a/src/tuning/tuningusb.cpp +++ b/src/tuning/tuningusb.cpp @@ -43,7 +43,7 @@ usb_tunable::usb_tunable(const char *path, const char *name) : tunable("", 0.9, char vendor[2048]; char product[2048]; string str1, str2; - snprintf(usb_path, sizeof(usb_path), "%s/power/control", path); + snprintf(usb_path, PATH_MAX, "%s/power/control", path); vendor[0] = 0; product[0] = 0; @@ -51,9 +51,9 @@ usb_tunable::usb_tunable(const char *path, const char *name) : tunable("", 0.9, str1 = read_sysfs_string("%s/idVendor", path); str2 = read_sysfs_string("%s/idProduct", path); - snprintf(desc, sizeof(desc), _("Autosuspend for unknown USB device %s (%s:%s)"), name, str1.c_str(), str2.c_str()); + snprintf(desc, 4096, _("Autosuspend for unknown USB device %s (%s:%s)"), name, str1.c_str(), str2.c_str()); - snprintf(filename, sizeof(filename), "%s/manufacturer", path); + snprintf(filename, PATH_MAX, "%s/manufacturer", path); file.open(filename, ios::in); if (file) { file.getline(vendor, 2047); @@ -61,21 +61,21 @@ usb_tunable::usb_tunable(const char *path, const char *name) : tunable("", 0.9, vendor[0] = 0; file.close(); }; - snprintf(filename, sizeof(filename), "%s/product", path); + snprintf(filename, PATH_MAX, "%s/product", path); file.open(filename, ios::in); if (file) { file.getline(product, 2040); file.close(); }; if (strlen(vendor) && strlen(product)) - snprintf(desc, sizeof(desc), _("Autosuspend for USB device %s [%s]"), product, vendor); + snprintf(desc, 4096, _("Autosuspend for USB device %s [%s]"), product, vendor); else if (strlen(product)) - snprintf(desc, sizeof(desc), _("Autosuspend for USB device %s [%s]"), product, name); + snprintf(desc, 4096, _("Autosuspend for USB device %s [%s]"), product, name); else if (strlen(vendor)) - snprintf(desc, sizeof(desc), _("Autosuspend for USB device %s [%s]"), vendor, name); + snprintf(desc, 4096, _("Autosuspend for USB device %s [%s]"), vendor, name); - snprintf(toggle_good, sizeof(toggle_good), "echo 'auto' > '%s';", usb_path); - snprintf(toggle_bad, sizeof(toggle_bad), "echo 'on' > '%s';", usb_path); + snprintf(toggle_good, 4096, "echo 'auto' > '%s';", usb_path); + snprintf(toggle_bad, 4096, "echo 'on' > '%s';", usb_path); } int usb_tunable::good_bad(void) @@ -121,23 +121,23 @@ static void add_usb_callback(const char *d_name) char filename[PATH_MAX]; DIR *dir; - snprintf(filename, sizeof(filename), "/sys/bus/usb/devices/%s/power/control", d_name); + snprintf(filename, PATH_MAX, "/sys/bus/usb/devices/%s/power/control", d_name); if (access(filename, R_OK) != 0) return; - snprintf(filename, sizeof(filename), "/sys/bus/usb/devices/%s/power/active_duration", d_name); + snprintf(filename, PATH_MAX, "/sys/bus/usb/devices/%s/power/active_duration", d_name); if (access(filename, R_OK)!=0) return; /* every interface of this device should support autosuspend */ - snprintf(filename, sizeof(filename), "/sys/bus/usb/devices/%s", d_name); + snprintf(filename, PATH_MAX, "/sys/bus/usb/devices/%s", d_name); if ((dir = opendir(filename))) { struct dirent *entry; while ((entry = readdir(dir))) { /* dirname: <busnum>-<devnum>...:<config num>-<interface num> */ if (!isdigit(entry->d_name[0])) continue; - snprintf(filename, sizeof(filename), "/sys/bus/usb/devices/%s/%s/supports_autosuspend", d_name, entry->d_name); + snprintf(filename, PATH_MAX, "/sys/bus/usb/devices/%s/%s/supports_autosuspend", d_name, entry->d_name); if (access(filename, R_OK) == 0 && read_sysfs(filename) == 0) break; } @@ -146,7 +146,7 @@ static void add_usb_callback(const char *d_name) return; } - snprintf(filename, sizeof(filename), "/sys/bus/usb/devices/%s", d_name); + snprintf(filename, PATH_MAX, "/sys/bus/usb/devices/%s", d_name); usb = new class usb_tunable(filename, d_name); all_tunables.push_back(usb); } diff --git a/src/tuning/wifi.cpp b/src/tuning/wifi.cpp index f7a91ec..2763b43 100644 --- a/src/tuning/wifi.cpp +++ b/src/tuning/wifi.cpp @@ -44,11 +44,11 @@ extern "C" { wifi_tunable::wifi_tunable(const char *_iface) : tunable("", 1.5, _("Good"), _("Bad"), _("Unknown")) { - pt_strcpy(iface, _iface); + strcpy(iface, _iface); sprintf(desc, _("Wireless Power Saving for interface %s"), iface); - snprintf(toggle_good, sizeof(toggle_good), "iw dev %s set power_save on", iface); - snprintf(toggle_bad, sizeof(toggle_bad), "iw dev %s set power_save off", iface); + snprintf(toggle_good, 4096, "iw dev %s set power_save on", iface); + snprintf(toggle_bad, 4096, "iw dev %s set power_save off", iface); } int wifi_tunable::good_bad(void) |