linux: don't abort on malformed /proc/stat

Return an error instead of aborting when /proc/stat doesn't have the
expected format.

PR-URL: https://github.com/libuv/libuv/pull/822
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
Ben Noordhuis 2016-04-11 18:03:00 +02:00
parent 2bf7b3855c
commit 732fb03ac6

View File

@ -562,7 +562,7 @@ static int uv__cpu_num(FILE* statfile_fp, unsigned int* numcpus) {
char buf[1024];
if (!fgets(buf, sizeof(buf), statfile_fp))
abort();
return -EIO;
num = 0;
while (fgets(buf, sizeof(buf), statfile_fp)) {
@ -571,6 +571,9 @@ static int uv__cpu_num(FILE* statfile_fp, unsigned int* numcpus) {
num++;
}
if (num == 0)
return -EIO;
*numcpus = num;
return 0;
}
@ -593,9 +596,6 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
if (err < 0)
goto out;
assert(numcpus != (unsigned int) -1);
assert(numcpus != 0);
err = -ENOMEM;
ci = uv__calloc(numcpus, sizeof(*ci));
if (ci == NULL)