Skip to content

Commit

Permalink
Add safety assert in parse_movement_unit
Browse files Browse the repository at this point in the history
Let's add this just in case a caller passes argc == 0.

References: #6737 (comment)
  • Loading branch information
emersion committed Jan 9, 2022
1 parent e2b4c57 commit 6cb69a4
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions common/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 6cb69a4

Please sign in to comment.