aboutsummaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar Christoph Gysin <christoph.gysin@gmail.com>2015-11-29 15:46:30 +0200
committerLibravatar Christoph Gysin <christoph.gysin@gmail.com>2015-11-29 22:36:17 +0200
commit3c8763af22b3ffe0a281b5a6d9a018f952238ff4 (patch)
tree9c6212ef9690ed3328cd3a7671bf3bbbfe01f3df /sway
parentAdd text rendering support to wayland clients (diff)
downloadsway-3c8763af22b3ffe0a281b5a6d9a018f952238ff4.tar.gz
sway-3c8763af22b3ffe0a281b5a6d9a018f952238ff4.tar.zst
sway-3c8763af22b3ffe0a281b5a6d9a018f952238ff4.zip
cmd_output: check for missing subcommand arguments
Diffstat (limited to 'sway')
-rw-r--r--sway/commands.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/sway/commands.c b/sway/commands.c
index ba42a9ae..d6ee4553 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -722,7 +722,6 @@ static struct cmd_results *cmd_output(int argc, char **argv) {
722 output->enabled = true; 722 output->enabled = true;
723 723
724 // TODO: atoi doesn't handle invalid numbers 724 // TODO: atoi doesn't handle invalid numbers
725 // TODO: Check missing params after each sub-command
726 725
727 int i; 726 int i;
728 for (i = 1; i < argc; ++i) { 727 for (i = 1; i < argc; ++i) {
@@ -731,7 +730,10 @@ static struct cmd_results *cmd_output(int argc, char **argv) {
731 if (strcasecmp(command, "disable") == 0) { 730 if (strcasecmp(command, "disable") == 0) {
732 output->enabled = false; 731 output->enabled = false;
733 } else if (strcasecmp(command, "resolution") == 0 || strcasecmp(command, "res") == 0) { 732 } else if (strcasecmp(command, "resolution") == 0 || strcasecmp(command, "res") == 0) {
734 char *res = argv[++i]; 733 if (++i >= argc) {
734 return cmd_results_new(CMD_INVALID, "output", "Missing resolution argument.");
735 }
736 char *res = argv[i];
735 char *x = strchr(res, 'x'); 737 char *x = strchr(res, 'x');
736 int width = -1, height = -1; 738 int width = -1, height = -1;
737 if (x != NULL) { 739 if (x != NULL) {
@@ -743,13 +745,19 @@ static struct cmd_results *cmd_output(int argc, char **argv) {
743 } else { 745 } else {
744 // Format is 1234 4321 746 // Format is 1234 4321
745 width = atoi(res); 747 width = atoi(res);
746 res = argv[++i]; 748 if (++i >= argc) {
749 return cmd_results_new(CMD_INVALID, "output", "Missing resolution argument (height).");
750 }
751 res = argv[i];
747 height = atoi(res); 752 height = atoi(res);
748 } 753 }
749 output->width = width; 754 output->width = width;
750 output->height = height; 755 output->height = height;
751 } else if (strcasecmp(command, "position") == 0 || strcasecmp(command, "pos") == 0) { 756 } else if (strcasecmp(command, "position") == 0 || strcasecmp(command, "pos") == 0) {
752 char *res = argv[++i]; 757 if (++i >= argc) {
758 return cmd_results_new(CMD_INVALID, "output", "Missing position argument.");
759 }
760 char *res = argv[i];
753 char *c = strchr(res, ','); 761 char *c = strchr(res, ',');
754 int x = -1, y = -1; 762 int x = -1, y = -1;
755 if (c != NULL) { 763 if (c != NULL) {
@@ -761,7 +769,10 @@ static struct cmd_results *cmd_output(int argc, char **argv) {
761 } else { 769 } else {
762 // Format is 1234 4321 770 // Format is 1234 4321
763 x = atoi(res); 771 x = atoi(res);
764 res = argv[++i]; 772 if (++i >= argc) {
773 return cmd_results_new(CMD_INVALID, "output", "Missing position argument (y).");
774 }
775 res = argv[i];
765 y = atoi(res); 776 y = atoi(res);
766 } 777 }
767 output->x = x; 778 output->x = x;