Skip to content

Commit

Permalink
make the return value of getline() handled correct
Browse files Browse the repository at this point in the history
getline() will return -1 when fail, so make the return value handle
correct.

Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
  • Loading branch information
yeyunfeng-dev committed Sep 19, 2019
1 parent 724243f commit 735c024
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion activate.c
Expand Up @@ -44,7 +44,7 @@ static int check_affinity(struct irq_info *info, cpumask_t applied_mask)
file = fopen(buf, "r");
if (!file)
return 1;
if (getline(&line, &size, file)==0) {
if (getline(&line, &size, file)<=0) {
free(line);
fclose(file);
return 1;
Expand Down
8 changes: 4 additions & 4 deletions cputree.c
Expand Up @@ -278,7 +278,7 @@ static void do_one_cpu(char *path)
if (file) {
char *line = NULL;
size_t size = 0;
if (getline(&line, &size, file)==0)
if (getline(&line, &size, file)<=0)
return;
fclose(file);
if (line && line[0]=='0') {
Expand Down Expand Up @@ -323,7 +323,7 @@ static void do_one_cpu(char *path)
if (file) {
char *line = NULL;
size_t size = 0;
if (getline(&line, &size, file))
if (getline(&line, &size, file) > 0)
cpumask_parse_user(line, strlen(line), package_mask);
fclose(file);
free(line);
Expand All @@ -335,7 +335,7 @@ static void do_one_cpu(char *path)
if (file) {
char *line = NULL;
size_t size = 0;
if (getline(&line, &size, file))
if (getline(&line, &size, file) > 0)
packageid = strtoul(line, NULL, 10);
fclose(file);
free(line);
Expand Down Expand Up @@ -368,7 +368,7 @@ static void do_one_cpu(char *path)
if (file) {
char *line = NULL;
size_t size = 0;
if (getline(&line, &size, file))
if (getline(&line, &size, file) > 0)
cpumask_parse_user(line, strlen(line), cache_mask);
fclose(file);
free(line);
Expand Down
12 changes: 6 additions & 6 deletions procinterrupts.c
Expand Up @@ -161,7 +161,7 @@ GList* collect_full_irq_list()
return NULL;

/* first line is the header we don't need; nuke it */
if (getline(&line, &size, file)==0) {
if (getline(&line, &size, file)<=0) {
free(line);
fclose(file);
return NULL;
Expand All @@ -174,7 +174,7 @@ GList* collect_full_irq_list()
char *c;
char *savedline = NULL;

if (getline(&line, &size, file)==0)
if (getline(&line, &size, file)<=0)
break;

/* lines with letters in front are special, like NMI count. Ignore */
Expand Down Expand Up @@ -248,7 +248,7 @@ void parse_proc_interrupts(void)
return;

/* first line is the header we don't need; nuke it */
if (getline(&line, &size, file)==0) {
if (getline(&line, &size, file)<=0) {
free(line);
fclose(file);
return;
Expand All @@ -262,7 +262,7 @@ void parse_proc_interrupts(void)
struct irq_info *info;
char savedline[1024];

if (getline(&line, &size, file)==0)
if (getline(&line, &size, file)<=0)
break;

if (!proc_int_has_msi)
Expand Down Expand Up @@ -444,7 +444,7 @@ void parse_proc_stat(void)
}

/* first line is the header we don't need; nuke it */
if (getline(&line, &size, file)==0) {
if (getline(&line, &size, file)<=0) {
free(line);
log(TO_ALL, LOG_WARNING, "WARNING read /proc/stat. balancing is broken\n");
fclose(file);
Expand All @@ -453,7 +453,7 @@ void parse_proc_stat(void)

cpucount = 0;
while (!feof(file)) {
if (getline(&line, &size, file)==0)
if (getline(&line, &size, file)<=0)
break;

if (!strstr(line, "cpu"))
Expand Down

0 comments on commit 735c024

Please sign in to comment.