summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFurkan Sahin <furkan-dev@proton.me>2022-01-09 01:03:49 +0100
committerFurkan Sahin <furkan-dev@proton.me>2022-01-09 01:03:49 +0100
commit66d333b0e6fff724b0f89d0da9d330e9112c37ab (patch)
treec705a62c29a042d06270874f82610d743384345c
parenta6ddb04a1057cafc0c456a32f74150aaaa74d52b (diff)
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)
-rw-r--r--common/util.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/common/util.c b/common/util.c
index 199f3ee1..5d4c0673 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) {