From e0a591fb93a17e0a0f6ee8a8a285392d04a02c01 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Sun, 9 Jan 2022 01:03:49 +0100 Subject: [PATCH] Add safety assert in parse_movement_unit Let's add this just in case a caller passes argc == 0. References: https://github.com/swaywm/sway/issues/6737#issuecomment-1008082540 (cherry picked from commit 6cb69a40c757cc44906fd928c43e60612c0e7ce8) --- common/util.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/common/util.c b/common/util.c index 199f3ee1c..5d4c0673d 100644 --- a/common/util.c +++ b/common/util.c @@ -80,6 +80,12 @@ enum movement_unit parse_movement_unit(const char *unit) { int parse_movement_amount(int argc, char **argv, struct movement_amount *amount) { + if (!sway_assert(argc > 0, "Expected args in parse_movement_amount")) { + amount->amount = 0; + amount->unit = MOVEMENT_UNIT_INVALID; + return 0; + } + char *err; amount->amount = (int)strtol(argv[0], &err, 10); if (*err) {