Skip to content

Commit

Permalink
Merge branch 'remove-vla' of BenBE/htop
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lange authored and Daniel Lange committed Aug 2, 2023
2 parents 2d4e5cb + 1309c4b commit 278ebbb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
7 changes: 3 additions & 4 deletions OpenFilesScreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,8 @@ static void OpenFilesScreen_scan(InfoScreen* this) {
OpenFiles_FileData* fdata = pdata->files;
while (fdata) {
OpenFiles_Data* data = &fdata->data;
size_t lenN = strlen(getDataForType(data, 'n'));
size_t sizeEntry = 5 + 7 + 4 + 10 + 10 + 10 + 10 + lenN + 8 /*spaces*/ + 1 /*null*/;
char entry[sizeEntry];
xSnprintf(entry, sizeof(entry), "%5.5s %-7.7s %-4.4s %-10.10s %10.10s %10.10s %10.10s %s",
char* entry = NULL;
xAsprintf(&entry, "%5.5s %-7.7s %-4.4s %-10.10s %10.10s %10.10s %10.10s %s",
getDataForType(data, 'f'),
getDataForType(data, 't'),
getDataForType(data, 'a'),
Expand All @@ -265,6 +263,7 @@ static void OpenFilesScreen_scan(InfoScreen* this) {
getDataForType(data, 'i'),
getDataForType(data, 'n'));
InfoScreen_addLine(this, entry);
free(entry);
OpenFiles_Data_clear(data);
OpenFiles_FileData* old = fdata;
fdata = fdata->next;
Expand Down
5 changes: 2 additions & 3 deletions darwin/PlatformHelpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,8 @@ double Platform_calculateNanosecondsPerMachTick(void) {
* the "Apple M1" chip specifically when running under Rosetta 2.
*/

size_t cpuBrandStringSize = 1024;
char cpuBrandString[cpuBrandStringSize];
Platform_getCPUBrandString(cpuBrandString, cpuBrandStringSize);
char cpuBrandString[1024] = "";
Platform_getCPUBrandString(cpuBrandString, sizeof(cpuBrandString));

bool isRunningUnderRosetta2 = Platform_isRunningTranslated();

Expand Down
8 changes: 6 additions & 2 deletions linux/LibSensors.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
#include <errno.h>
#include <limits.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <sensors/sensors.h>

#include "Macros.h"
Expand Down Expand Up @@ -143,7 +144,8 @@ static int tempDriverPriority(const sensors_chip_name* chip) {

void LibSensors_getCPUTemperatures(CPUData* cpus, unsigned int existingCPUs, unsigned int activeCPUs) {
assert(existingCPUs > 0 && existingCPUs < 16384);
double data[existingCPUs + 1];

double* data = xMallocArray(existingCPUs + 1, sizeof(double));
for (size_t i = 0; i < existingCPUs + 1; i++)
data[i] = NAN;

Expand Down Expand Up @@ -264,6 +266,8 @@ void LibSensors_getCPUTemperatures(CPUData* cpus, unsigned int existingCPUs, uns
out:
for (unsigned int i = 0; i <= existingCPUs; i++)
cpus[i].temperature = data[i];

free(data);
}

#endif /* HAVE_SENSORS_SENSORS_H */
4 changes: 3 additions & 1 deletion openbsd/OpenBSDMachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ static void OpenBSDMachine_scanMemoryInfo(OpenBSDMachine* this) {
*/
int nswap = swapctl(SWAP_NSWAP, 0, 0);
if (nswap > 0) {
struct swapent swdev[nswap];
struct swapent* swdev = xMallocArray(nswap, sizeof(struct swapent));
int rnswap = swapctl(SWAP_STATS, swdev, nswap);

/* Total things up */
Expand All @@ -177,6 +177,8 @@ static void OpenBSDMachine_scanMemoryInfo(OpenBSDMachine* this) {

super->totalSwap = total;
super->usedSwap = used;

free(swdev);
} else {
super->totalSwap = super->usedSwap = 0;
}
Expand Down

0 comments on commit 278ebbb

Please sign in to comment.