From 134ca7390986e6e61f29753f7a3f54794078ea67 Mon Sep 17 00:00:00 2001 From: "Jan Chren (rindeal)" Date: Sat, 19 Oct 2019 01:05:54 +0200 Subject: [PATCH] cpp: prevent crashes when last argument expects a value --- src/main/cpp/tiv.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/cpp/tiv.cpp b/src/main/cpp/tiv.cpp index d74440e..bafdd0d 100644 --- a/src/main/cpp/tiv.cpp +++ b/src/main/cpp/tiv.cpp @@ -480,15 +480,18 @@ int main(int argc, char* argv[]) { if (arg == "-0") { flags |= FLAG_NOOPT; } else if (arg == "-c") { - columns = std::stoi(argv[++i]); + if (i < argc - 1) + columns = std::stoi(argv[++i]); } else if (arg == "-d") { mode = THUMBNAILS; } else if (arg == "-f") { mode = FULL_SIZE; } else if (arg == "-w") { - maxWidth = 4 * std::stoi(argv[++i]); + if (i < argc - 1) + maxWidth = 4 * std::stoi(argv[++i]); } else if (arg == "-h") { - maxHeight = 8 * std::stoi(argv[++i]); + if (i < argc - 1) + maxHeight = 8 * std::stoi(argv[++i]); } else if (arg == "-256") { flags |= FLAG_MODE_256; } else if (arg == "--help" || arg == "-help") {