aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/cutils.c5
-rw-r--r--util/oslib-posix.c4
2 files changed, 5 insertions, 4 deletions
diff --git a/util/cutils.c b/util/cutils.c
index c2250d1ba5..144b25c05a 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -537,16 +537,17 @@ int parse_debug_env(const char *name, int max, int initial)
{
char *debug_env = getenv(name);
char *inv = NULL;
- int debug;
+ long debug;
if (!debug_env) {
return initial;
}
+ errno = 0;
debug = strtol(debug_env, &inv, 10);
if (inv == debug_env) {
return initial;
}
- if (debug < 0 || debug > max) {
+ if (debug < 0 || debug > max || errno != 0) {
fprintf(stderr, "warning: %s not in [0, %d]", name, max);
return initial;
}
diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index 16fcec2f37..37ffd96245 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -399,10 +399,10 @@ void os_mem_prealloc(int fd, char *area, size_t memory)
} else {
int i;
size_t hpagesize = fd_getpagesize(fd);
+ size_t numpages = DIV_ROUND_UP(memory, hpagesize);
/* MAP_POPULATE silently ignores failures */
- memory = (memory + hpagesize - 1) & -hpagesize;
- for (i = 0; i < (memory / hpagesize); i++) {
+ for (i = 0; i < numpages; i++) {
memset(area + (hpagesize * i), 0, 1);
}