--- a/libperf_events/operf_counter.cpp
+++ b/libperf_events/operf_counter.cpp
@@ -618,8 +618,7 @@
 		goto error;
 	}
 	memset(cpus_online, 0, sizeof(cpus_online));
-	fgets(cpus_online, sizeof(cpus_online), online_cpus);
-	if (!cpus_online[0]) {
+	if (fgets(cpus_online, sizeof(cpus_online), online_cpus) == NULL) {
 		fclose(online_cpus);
 		err_msg = "Internal Error: Number of online cpus cannot be determined.";
 		rc = -1;