diff options
author | PA4WDH | 2024-08-25 17:03:13 +0200 |
---|---|---|
committer | PA4WDH | 2024-08-25 17:03:13 +0200 |
commit | 6aab4389f27e35ae5bdacb7cf01d0a69d067e40e (patch) | |
tree | d751119f13454657170054a13b754966a884588f /cpulist.c | |
parent | Add -Wall -Werror and fix warnings (diff) | |
download | cputemp2maxfreq-6aab4389f27e35ae5bdacb7cf01d0a69d067e40e.tar.gz cputemp2maxfreq-6aab4389f27e35ae5bdacb7cf01d0a69d067e40e.tar.bz2 cputemp2maxfreq-6aab4389f27e35ae5bdacb7cf01d0a69d067e40e.zip |
Small fixes in cpulist.c
Diffstat (limited to 'cpulist.c')
-rw-r--r-- | cpulist.c | 20 |
1 files changed, 12 insertions, 8 deletions
@@ -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; } |