Commit 74823419 authored by Josh Triplett's avatar Josh Triplett Committed by Len Brown

turbostat: Check return value of fscanf

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: default avatarJosh Triplett <josh@joshtriplett.org>
Signed-off-by: default avatarLen Brown <len.brown@intel.com>
parent 2b92865e
...@@ -1189,7 +1189,10 @@ int cpu_is_first_sibling_in_core(int cpu) ...@@ -1189,7 +1189,10 @@ int cpu_is_first_sibling_in_core(int cpu)
perror(path); perror(path);
exit(1); exit(1);
} }
fscanf(filep, "%d", &first_cpu); if (fscanf(filep, "%d", &first_cpu) != 1) {
perror(path);
exit(1);
}
fclose(filep); fclose(filep);
return (cpu == first_cpu); return (cpu == first_cpu);
} }
...@@ -1210,7 +1213,10 @@ int cpu_is_first_core_in_package(int cpu) ...@@ -1210,7 +1213,10 @@ int cpu_is_first_core_in_package(int cpu)
perror(path); perror(path);
exit(1); exit(1);
} }
fscanf(filep, "%d", &first_cpu); if (fscanf(filep, "%d", &first_cpu) != 1) {
perror(path);
exit(1);
}
fclose(filep); fclose(filep);
return (cpu == first_cpu); return (cpu == first_cpu);
} }
...@@ -1227,7 +1233,10 @@ int get_physical_package_id(int cpu) ...@@ -1227,7 +1233,10 @@ int get_physical_package_id(int cpu)
perror(path); perror(path);
exit(1); exit(1);
} }
fscanf(filep, "%d", &pkg); if (fscanf(filep, "%d", &pkg) != 1) {
perror(path);
exit(1);
}
fclose(filep); fclose(filep);
return pkg; return pkg;
} }
...@@ -1244,7 +1253,10 @@ int get_core_id(int cpu) ...@@ -1244,7 +1253,10 @@ int get_core_id(int cpu)
perror(path); perror(path);
exit(1); exit(1);
} }
fscanf(filep, "%d", &core); if (fscanf(filep, "%d", &core) != 1) {
perror(path);
exit(1);
}
fclose(filep); fclose(filep);
return core; return core;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment