Skip to content

Commit

Permalink
Fix in rescpu
Browse files Browse the repository at this point in the history
If the string contains an empty value, for eg. "power management:\n"
then we need to handle that case.

Signed-off-by: Anjali Kulkarni <[email protected]>
  • Loading branch information
anjalidk authored and hallyn committed Oct 4, 2023
1 parent 5f5eda8 commit e49b3f2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions rescpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
static int populate_cpuinfo(void *out, char *buffer, int total_len, int probe)
{
char *end, *start, *start2, *end2;
char end3[1];
int bytes_done = 0;
struct cpuinfo *cpu = (struct cpuinfo *)out;


start = buffer;
while(1) {
if (bytes_done >= total_len)
Expand All @@ -52,7 +52,10 @@ static int populate_cpuinfo(void *out, char *buffer, int total_len, int probe)
if (*(end+1) == '\n') {
start2 = end+1;
bytes_done++;
goto nextline;
end[0] = '\0';
end2 = end3;
end2[0] = '\0';
goto next;
}
end2 = end+2;
bytes_done += 2;
Expand All @@ -72,6 +75,7 @@ static int populate_cpuinfo(void *out, char *buffer, int total_len, int probe)
if (start == end || start2 == end2)
goto nextline;

next:
if (!strcmp(start, "processor")) {
/*
* If probe is set, then this is being called during
Expand Down

0 comments on commit e49b3f2

Please sign in to comment.