From da347a996939a8fe7277d180d0098094332e63d7 Mon Sep 17 00:00:00 2001 From: PA4WDH Date: Sun, 25 Aug 2024 16:57:08 +0200 Subject: Add -Wall -Werror and fix warnings --- Makefile | 3 +++ cpulist.c | 4 ++-- cputemp.c | 12 ++++++------ sysfs.c | 9 +++++++++ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 737dfa7..ccbcac1 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,6 @@ +CC=gcc +CFLAGS=-Wall -Werror + cputemp2maxfreq: version.o debug.o sysfs.o cpufreq.o failsafe.o argparse.o logger.o cputemp.o cpulist.o version.h: generate_version_h.sh .git/index diff --git a/cpulist.c b/cpulist.c index 307638d..dfb4733 100644 --- a/cpulist.c +++ b/cpulist.c @@ -44,7 +44,7 @@ int cpulist_find_cpus() { DIR *cpudir; struct dirent *cpu_dirent; - char sysfs_file[128]; + char sysfs_file[309]; int package; DEBUG1_CPULIST("Started\n") @@ -72,7 +72,7 @@ int cpulist_find_cpus() if (cpulist_is_cpu(cpu_dirent->d_name)) { DEBUG2_CPULIST("Found CPU %s\n",cpu_dirent->d_name); - snprintf(sysfs_file,128,"/sys/devices/system/cpu/%s/topology/physical_package_id",cpu_dirent->d_name); + snprintf(sysfs_file,309,"/sys/devices/system/cpu/%s/topology/physical_package_id",cpu_dirent->d_name); package=sysfs_read_long_int(sysfs_file); DEBUG2_CPULIST("CPU Belongs to package id %d\n",package); if ((package==config.cpu) || (config.cpu<0)) diff --git a/cputemp.c b/cputemp.c index e30cc31..ca616b1 100644 --- a/cputemp.c +++ b/cputemp.c @@ -79,7 +79,7 @@ void cputemp_read_hwmon(char *hwmon,char *sensor_name,struct s_sensor *sensor) { DIR *hwmon_dir; struct dirent *hwmon_dirent; - char name_file[255]; + char name_file[258]; char input_file[255]; int offset; @@ -100,10 +100,10 @@ void cputemp_read_hwmon(char *hwmon,char *sensor_name,struct s_sensor *sensor) if (cputemp_is_label(hwmon_dirent->d_name)) { DEBUG2_CPUTEMP("Found label %s\n",hwmon_dirent->d_name); - sprintf(name_file,"%s/%s",hwmon,hwmon_dirent->d_name); - sprintf(input_file,"%s/%s",hwmon,hwmon_dirent->d_name); + snprintf(name_file,258,"%s/%s",hwmon,hwmon_dirent->d_name); + snprintf(input_file,258,"%s/%s",hwmon,hwmon_dirent->d_name); offset=strlen(input_file)-5; - strncpy(input_file+offset,"input",5); + strncpy(input_file+offset,"input",6); cputemp_match_and_validate(name_file,input_file,sensor_name,sensor); } hwmon_dirent=readdir(hwmon_dir); @@ -126,7 +126,7 @@ void cputemp_find_sensor(char *sensor_name,struct s_sensor *sensor) { DIR *hwmon_dir; struct dirent *hwmon_dirent; - char subdir[255]; + char subdir[273]; DEBUG1_CPUTEMP("Searching for sensor %s\n",sensor_name); @@ -149,7 +149,7 @@ void cputemp_find_sensor(char *sensor_name,struct s_sensor *sensor) // Note that /sys/class/hwmon actually contains symlinks but we treat them like directories if (strncmp(hwmon_dirent->d_name,"hwmon",5)==0) { - sprintf(subdir,"/sys/class/hwmon/%s",hwmon_dirent->d_name); + snprintf(subdir,273,"/sys/class/hwmon/%s",hwmon_dirent->d_name); DEBUG2_CPUTEMP("Found hwmon entry: %s\n",subdir); cputemp_read_hwmon(subdir,sensor_name,sensor); } diff --git a/sysfs.c b/sysfs.c index dc2b822..d6e4d60 100644 --- a/sysfs.c +++ b/sysfs.c @@ -3,7 +3,11 @@ #include #include #include +#include #include "debug.h" +#include "cputemp2maxfreq.h" + +extern struct s_config config; int sysfs_read_str(char *sysfs_file,char *buf,size_t bufsize) { @@ -62,6 +66,11 @@ int sysfs_write_str(char *sysfs_file,char *value,long int checkdelay) // Write the data len=write(sysfs_handle,value,strlen(value)); + if (len<0) + { + config.logger("Error %d occoured while writing to sysfs",errno); + } + close(sysfs_handle); DEBUG2_SYSFS("Written %zd bytes\n",len); -- cgit v1.2.3