mem: handle potential error from sysconf(_SC_PAGESIZE)

Reported by Coverity scan.

* mem.c (get_pagesize): Handle the case when sysconf(_SC_PAGESIZE)
returns an error.
This commit is contained in:
Eugene Syromyatnikov 2018-05-02 20:04:23 +02:00 committed by Dmitry V. Levin
parent e1499151e9
commit 4eb79a767d

14
mem.c
View File

@ -40,8 +40,18 @@ get_pagesize(void)
{
static unsigned long pagesize;
if (!pagesize)
pagesize = sysconf(_SC_PAGESIZE);
if (!pagesize) {
long ret = sysconf(_SC_PAGESIZE);
if (ret < 0)
perror_func_msg_and_die("sysconf(_SC_PAGESIZE)");
if (ret == 0)
error_func_msg_and_die("sysconf(_SC_PAGESIZE) "
"returned 0");
pagesize = (unsigned long) ret;
}
return pagesize;
}