diff options
feat: Check for invalid values in widths and heights
1 files changed, 45 insertions, 19 deletions
| -rw-r--r-- | src/LEDVideoWall.cpp | 64 |
diff --git a/src/LEDVideoWall.cpp b/src/LEDVideoWall.cpp index 45f66ba..f4f4e16 100644 --- a/src/LEDVideoWall.cpp +++ b/src/LEDVideoWall.cpp @@ -38,12 +38,20 @@ enum class LEDVideoWallType { LEDVideoWall* LEDVideoWall::fromCommandLine() { mm ipanel_width = 0, ipanel_height = 0; - cli::scanTwoValues( - "%dx%d", - ipanel_width, - ipanel_height, - "Enter panel size (in the format 'WIDTHxHEIGHT'): ", - "Invalid size, try again!"); + do { + cli::scanTwoValues( + "%dx%d", + ipanel_width, + ipanel_height, + "Enter panel size (in the format 'WIDTHxHEIGHT'): ", + "Invalid size, try again!"); + + if (ipanel_width == 0 || ipanel_height == 0) { + std::cerr << "The panel width or height cannot be zero!" << std::endl; + continue; + } + break; + } while (true); unsigned int itype = 2; cli::readUserInputMax( @@ -56,24 +64,42 @@ LEDVideoWall* LEDVideoWall::fromCommandLine() { switch (type) { case LEDVideoWallType::Freeform: { mm iwall_max_width = 0, iwall_max_height = 0; - cli::scanTwoValues( - "%dx%d", - iwall_max_width, - iwall_max_height, - "Enter singe wall size (in the format 'WIDTHxHEIGHT'): ", - "Invalid size, try again!"); + do { + cli::scanTwoValues( + "%dx%d", + iwall_max_width, + iwall_max_height, + "Enter singe wall size (in the format 'WIDTHxHEIGHT'): ", + "Invalid size, try again!"); + + if (iwall_max_width == 0 || iwall_max_height == 0) { + std::cerr << "The wall width or height cannot be zero!" << std::endl; + continue; + } + if (iwall_max_width < panel_width || iwall_max_height < panel_height) { + std::cerr << "The wall cannot be smaller than the panel!" << std::endl; + continue; + } + } while (true); return LEDVideoWall::Freeform(ipanel_width, ipanel_height, iwall_max_width, iwall_max_height); }; case LEDVideoWallType::Aspect: { - mm i_width = 0, i_height = 0; - cli::scanTwoValues( - "%d:%d", - i_width, - i_height, - "Enter aspect ratio (in the format 'width:height'): ", - "Invalid input, try again!"); + mm iaspect_width = 0, iaspect_height = 0; + do { + cli::scanTwoValues( + "%d:%d", + iaspect_width, + iaspect_height, + "Enter aspect ratio (in the format 'WIDTH:HEIGHT'): ", + "Invalid input, try again!"); + + if (iaspect_width == 0 || iaspect_height == 0) { + std::cerr << "The aspect ratio width or height cannot be zero!" << std::endl; + continue; + } + } while (true); return LEDVideoWall::Aspect(ipanel_width, ipanel_height, i_width, i_height); }; |