summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common.h5
-rw-r--r--mboxd.c4
2 files changed, 9 insertions, 0 deletions
diff --git a/common.h b/common.h
index ee537a8..14fdfe9 100644
--- a/common.h
+++ b/common.h
@@ -83,6 +83,11 @@ static inline int log_2(int val)
return ret;
}
+static inline bool is_power_of_2(unsigned val)
+{
+ return __builtin_popcount(val) == 1;
+}
+
char *get_dev_mtd(void);
#endif /* COMMON_H */
diff --git a/mboxd.c b/mboxd.c
index 0ebba56..1307fe6 100644
--- a/mboxd.c
+++ b/mboxd.c
@@ -241,6 +241,10 @@ static bool parse_cmdline(int argc, char **argv,
fprintf(stderr, "Unparseable window size\n");
return false;
}
+ if (!is_power_of_2(context->windows.default_size)) {
+ fprintf(stderr, "Window size not power of 2\n");
+ return false;
+ }
break;
case 'v':
verbosity++;
OpenPOWER on IntegriCloud