Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.
/ jdk13u-dev Public archive

Commit

Permalink
8268361: Fix the infinite loop in next_line
Browse files Browse the repository at this point in the history
Backport-of: 72672277e4dddf8e72f1c705cd5f57de40745635
  • Loading branch information
wkia authored and Yuri Nesterenko committed Sep 1, 2022
1 parent df4ddba commit 97c75f0
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,13 @@ static struct perfbuf {

#define DEC_64 "%"SCNd64

static void next_line(FILE *f) {
while (fgetc(f) != '\n');
static int next_line(FILE *f) {
int c;
do {
c = fgetc(f);
} while (c != '\n' && c != EOF);

return c;
}

/**
Expand Down Expand Up @@ -90,7 +95,10 @@ static int get_totalticks(int which, ticks *pticks) {
&iowTicks, &irqTicks, &sirqTicks);

// Move to next line
next_line(fh);
if (next_line(fh) == EOF) {
fclose(fh);
return -2;
}

//find the line for requested cpu faster to just iterate linefeeds?
if (which != -1) {
Expand All @@ -103,7 +111,10 @@ static int get_totalticks(int which, ticks *pticks) {
fclose(fh);
return -2;
}
next_line(fh);
if (next_line(fh) == EOF) {
fclose(fh);
return -2;
}
}
n = fscanf(fh, "cpu%*d " DEC_64 " " DEC_64 " " DEC_64 " " DEC_64 " "
DEC_64 " " DEC_64 " " DEC_64 "\n",
Expand Down

1 comment on commit 97c75f0

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.