summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Whitlock2014-03-22 18:54:24 -0400
committerDenys Vlasenko2014-03-23 18:36:22 +0100
commitc3a27b0bfdf758f649caab2c474e690067af3402 (patch)
treebe6d8243a249e362f7a079a46fc817def5f1ed4d
parent504fe45f35bab29752d39cc2d39d2e8c43fe6eac (diff)
downloadbusybox-c3a27b0bfdf758f649caab2c474e690067af3402.zip
busybox-c3a27b0bfdf758f649caab2c474e690067af3402.tar.gz
avoid calling bb_strtou twice in MIN macro expansion
Also, the maximum allowable value of swap priority is technically SWAP_FLAG_PRIO_MASK >> SWAP_FLAG_PRIO_SHIFT. Signed-off-by: Matt Whitlock <busybox@mattwhitlock.name> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--util-linux/swaponoff.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/util-linux/swaponoff.c b/util-linux/swaponoff.c
index 3f22334..bcceff7 100644
--- a/util-linux/swaponoff.c
+++ b/util-linux/swaponoff.c
@@ -100,12 +100,12 @@ static int do_em_all(void)
g_flags = 0; /* each swap space might have different flags */
p = hasmntopt(m, "pri");
if (p) {
- /* Max allowed 32767 (==SWAP_FLAG_PRIO_MASK) */
- unsigned int swap_prio = MIN(bb_strtou(p + 4 , NULL, 10), SWAP_FLAG_PRIO_MASK);
+ /* Max allowed 32767 (== SWAP_FLAG_PRIO_MASK) */
+ unsigned prio = bb_strtou(p + 4, NULL, 10);
/* We want to allow "NNNN,foo", thus errno == EINVAL is allowed too */
if (errno != ERANGE) {
g_flags = SWAP_FLAG_PREFER |
- (swap_prio << SWAP_FLAG_PRIO_SHIFT);
+ MIN(prio, SWAP_FLAG_PRIO_MASK);
}
}
#endif
@@ -124,6 +124,9 @@ int swap_on_off_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int swap_on_off_main(int argc UNUSED_PARAM, char **argv)
{
int ret;
+#if ENABLE_FEATURE_SWAPON_PRI
+ unsigned prio;
+#endif
INIT_G();
@@ -132,11 +135,11 @@ int swap_on_off_main(int argc UNUSED_PARAM, char **argv)
#else
if (applet_name[5] == 'n')
opt_complementary = "p+";
- ret = getopt32(argv, (applet_name[5] == 'n') ? "ap:" : "a", &g_flags);
+ ret = getopt32(argv, (applet_name[5] == 'n') ? "ap:" : "a", &prio);
if (ret & 2) { // -p
g_flags = SWAP_FLAG_PREFER |
- ((g_flags & SWAP_FLAG_PRIO_MASK) << SWAP_FLAG_PRIO_SHIFT);
+ MIN(prio, SWAP_FLAG_PRIO_MASK);
ret &= 1;
}
#endif