aboutsummaryrefslogtreecommitdiffstats
path: root/cpulist.c
diff options
context:
space:
mode:
authorPA4WDH2024-08-25 17:03:13 +0200
committerPA4WDH2024-08-25 17:03:13 +0200
commit6aab4389f27e35ae5bdacb7cf01d0a69d067e40e (patch)
treed751119f13454657170054a13b754966a884588f /cpulist.c
parentAdd -Wall -Werror and fix warnings (diff)
downloadcputemp2maxfreq-6aab4389f27e35ae5bdacb7cf01d0a69d067e40e.tar.gz
cputemp2maxfreq-6aab4389f27e35ae5bdacb7cf01d0a69d067e40e.tar.bz2
cputemp2maxfreq-6aab4389f27e35ae5bdacb7cf01d0a69d067e40e.zip
Small fixes in cpulist.c
Diffstat (limited to 'cpulist.c')
-rw-r--r--cpulist.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/cpulist.c b/cpulist.c
index dfb4733..eb219b5 100644
--- a/cpulist.c
+++ b/cpulist.c
@@ -16,11 +16,15 @@ extern struct s_cpudata cpudata;
// Add a CPU to the list
void cpulist_add(char *cpu)
{
- cpudata.cpulist_len++;
- cpudata.cpulist=reallocarray(cpudata.cpulist,cpudata.cpulist_len,sizeof(char *));
- cpudata.cpulist[cpudata.cpulist_len-1]=malloc(strlen(cpu)+1);
- strcpy(cpudata.cpulist[cpudata.cpulist_len-1],cpu);
- cpudata.cpulist[cpudata.cpulist_len-1][strlen(cpu)]=0;
+ int newlen;
+
+ newlen=cpudata.cpulist_len+1;
+ cpudata.cpulist=reallocarray(cpudata.cpulist,newlen,sizeof(char *));
+
+ cpudata.cpulist[cpudata.cpulist_len]=malloc(strlen(cpu)+1);
+ strcpy(cpudata.cpulist[cpudata.cpulist_len],cpu);
+ cpudata.cpulist[cpudata.cpulist_len][strlen(cpu)]=0;
+ cpudata.cpulist_len=newlen;
}
// Validate if we found a file named cpu[0-9][0-9][0-9]
@@ -101,10 +105,10 @@ void cpulist_free()
{
int count;
if (cpudata.cpulist==NULL) return;
+ int len=cpudata.cpulist_len;
+ cpudata.cpulist_len=0;
- for(count=0;count<cpudata.cpulist_len;count++) free(cpudata.cpulist[count]);
-
+ for(count=0;count<len;count++) free(cpudata.cpulist[count]);
free(cpudata.cpulist);
cpudata.cpulist=NULL;
- cpudata.cpulist_len=0;
}