Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion RichString.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ static inline int RichString_writeFromWide(RichString* this, int attrs, const ch
}
this->chptr[newLen] = 0;

return len;
return (int)len;
}

int RichString_appendnWideColumns(RichString* this, int attrs, const char* data_c, size_t len, int* columns) {
Expand Down
26 changes: 19 additions & 7 deletions linux/LibSensors.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ int LibSensors_countCCDs(void) {
return ccds;
}

static int LibSensors_stringToID(const char* str) {
char* endptr;
unsigned long parsedID = strtoul(str, &endptr, 10);
if (parsedID >= INT_MAX || *endptr != '\0')
return -1;
return (int)parsedID;
}

void LibSensors_getCPUTemperatures(CPUData* cpus, unsigned int existingCPUs, unsigned int activeCPUs) {
assert(existingCPUs > 0 && existingCPUs < 16384);

Expand Down Expand Up @@ -344,17 +352,21 @@ void LibSensors_getCPUTemperatures(CPUData* cpus, unsigned int existingCPUs, uns
char *label = sym_sensors_get_label(chip, feature);
if (label) {
bool skip = true;
int ID;
/* Intel coretemp names, labels mention package and physical id */
if (String_startsWith(label, "Package id ")) {
physicalID = strtoul(label + strlen("Package id "), NULL, 10);
if ((ID = LibSensors_stringToID(label + strlen("Package id "))) != -1)
physicalID = ID;
} else if (String_startsWith(label, "Physical id ")) {
physicalID = strtoul(label + strlen("Physical id "), NULL, 10);
if ((ID = LibSensors_stringToID(label + strlen("Physical id "))) != -1)
physicalID = ID;
} else if (String_startsWith(label, "Core ")) {
int coreID = strtoul(label + strlen("Core "), NULL, 10);
for (size_t i = 1; i < existingCPUs + 1; i++) {
if (cpus[i].physicalID == physicalID && cpus[i].coreID == coreID) {
data[i] = temp;
coreTempCount++;
if ((ID = LibSensors_stringToID(label + strlen("Core "))) != -1) {
for (size_t i = 1; i < existingCPUs + 1; i++) {
if (cpus[i].physicalID == physicalID && cpus[i].coreID == ID) {
data[i] = temp;
coreTempCount++;
}
}
}
}
Expand Down
23 changes: 13 additions & 10 deletions linux/LinuxProcessTable.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ static FILE* fopenat(openat_arg_t openatArg, const char* pathname, const char* m
return fp;
}

static pid_t strtopid(const char* str) {
char* endptr;
unsigned long parsedPid = strtoul(str, &endptr, 10);
if (parsedPid == 0 || parsedPid >= INT_MAX || *endptr != '\0')
return 0; // indicate failure by an invalid pid
return (pid_t)parsedPid;
}

static inline uint64_t fast_strtoull_dec(char** str, size_t maxlen) {
uint64_t result = 0;

Expand Down Expand Up @@ -982,8 +990,8 @@ static void LinuxProcessTable_readOpenVZData(LinuxProcess* process, openat_arg_t
free_and_xStrdup(&process->ctid, name_value_sep);
break;
case 2:
foundVPid = true;
process->vpid = strtoul(name_value_sep, NULL, 0);
if ((process->vpid = strtopid(name_value_sep)) != 0)
foundVPid = true;
break;
default:
//Sanity Check: Should never reach here, or the implementation is missing something!
Expand Down Expand Up @@ -1582,14 +1590,9 @@ static bool LinuxProcessTable_recurseProcTree(LinuxProcessTable* this, openat_ar
}

// filename is a number: process directory
int pid;
{
char* endptr;
unsigned long parsedPid = strtoul(name, &endptr, 10);
if (parsedPid == 0 || parsedPid >= INT_MAX || *endptr != '\0')
continue;
pid = (int)parsedPid;
}
pid_t pid = strtopid(name);
if (pid == 0)
continue;

// Skip task directory of main thread
if (mainTask && pid == Process_getPid(&mainTask->super))
Expand Down
Loading