Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9f3c840

Browse files
committed
8268361: Fix the infinite loop in next_line
Backport-of: 72672277e4dddf8e72f1c705cd5f57de40745635
1 parent4003db8 commit9f3c840

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

‎src/jdk.management/linux/native/libmanagement_ext/UnixOperatingSystem.c‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,13 @@ static struct perfbuf {
6363
#defineDEC_64 "%"SCNd64
6464
#defineNS_PER_SEC 1000000000
6565

66-
staticvoidnext_line(FILE*f) {
67-
while (fgetc(f)!='\n');
66+
staticintnext_line(FILE*f) {
67+
intc;
68+
do {
69+
c=fgetc(f);
70+
}while (c!='\n'&&c!=EOF);
71+
72+
returnc;
6873
}
6974

7075
/**
@@ -93,7 +98,10 @@ static int get_totalticks(int which, ticks *pticks) {
9398
&iowTicks,&irqTicks,&sirqTicks);
9499

95100
// Move to next line
96-
next_line(fh);
101+
if (next_line(fh)==EOF) {
102+
fclose(fh);
103+
return-2;
104+
}
97105

98106
//find the line for requested cpu faster to just iterate linefeeds?
99107
if (which!=-1) {
@@ -106,7 +114,10 @@ static int get_totalticks(int which, ticks *pticks) {
106114
fclose(fh);
107115
return-2;
108116
}
109-
next_line(fh);
117+
if (next_line(fh)==EOF) {
118+
fclose(fh);
119+
return-2;
120+
}
110121
}
111122
n=fscanf(fh,"cpu%*d "DEC_64" "DEC_64" "DEC_64" "DEC_64" "
112123
DEC_64" "DEC_64" "DEC_64"\n",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp