Skip to content

Commit

Permalink
turbostat: Check return value of fscanf
Browse files Browse the repository at this point in the history
Some systems declare fscanf with the warn_unused_result attribute.  On
such systems, turbostat generates the following warnings:

turbostat.c: In function 'get_core_id':
turbostat.c:1203:8: warning: ignoring return value of 'fscanf', declared with attribute warn_unused_result [-Wunused-result]
turbostat.c: In function 'get_physical_package_id':
turbostat.c:1186:8: warning: ignoring return value of 'fscanf', declared with attribute warn_unused_result [-Wunused-result]
turbostat.c: In function 'cpu_is_first_core_in_package':
turbostat.c:1169:8: warning: ignoring return value of 'fscanf', declared with attribute warn_unused_result [-Wunused-result]
turbostat.c: In function 'cpu_is_first_sibling_in_core':
turbostat.c:1148:8: warning: ignoring return value of 'fscanf', declared with attribute warn_unused_result [-Wunused-result]

Fix these by checking the return value of those four calls to fscanf.

Signed-off-by: Josh Triplett <[email protected]>
Signed-off-by: Len Brown <[email protected]>
  • Loading branch information
joshtriplett authored and lenb committed Jan 19, 2014
1 parent 2b92865 commit 7482341
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions tools/power/x86/turbostat/turbostat.c
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,10 @@ int cpu_is_first_sibling_in_core(int cpu)
perror(path);
exit(1);
}
fscanf(filep, "%d", &first_cpu);
if (fscanf(filep, "%d", &first_cpu) != 1) {
perror(path);
exit(1);
}
fclose(filep);
return (cpu == first_cpu);
}
Expand All @@ -1210,7 +1213,10 @@ int cpu_is_first_core_in_package(int cpu)
perror(path);
exit(1);
}
fscanf(filep, "%d", &first_cpu);
if (fscanf(filep, "%d", &first_cpu) != 1) {
perror(path);
exit(1);
}
fclose(filep);
return (cpu == first_cpu);
}
Expand All @@ -1227,7 +1233,10 @@ int get_physical_package_id(int cpu)
perror(path);
exit(1);
}
fscanf(filep, "%d", &pkg);
if (fscanf(filep, "%d", &pkg) != 1) {
perror(path);
exit(1);
}
fclose(filep);
return pkg;
}
Expand All @@ -1244,7 +1253,10 @@ int get_core_id(int cpu)
perror(path);
exit(1);
}
fscanf(filep, "%d", &core);
if (fscanf(filep, "%d", &core) != 1) {
perror(path);
exit(1);
}
fclose(filep);
return core;
}
Expand Down

0 comments on commit 7482341

Please sign in to comment.