aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Giessen <charles@lunarg.com>2023-01-16 12:07:34 -0700
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>2023-01-18 18:37:52 -0700
commit3d015f42a4ec56f20fbf1ccc3f55c36dc04fea40 (patch)
tree36c0f34f993bd27e26167dd1636237da751214fd
parent3327bd3ace8ebb6102f061be452f9fcfd512677b (diff)
downloadusermoji-3d015f42a4ec56f20fbf1ccc3f55c36dc04fea40.tar.xz
cube: Check for width & height less are than zero
The code would correctly reject widhth & height command line prameters that weren't greater than 0, but without a helpful error message about what was actually wrong.
-rw-r--r--cube/cube.c26
-rw-r--r--cube/cube.cpp34
2 files changed, 40 insertions, 20 deletions
diff --git a/cube/cube.c b/cube/cube.c
index 0e279da1..75d573b4 100644
--- a/cube/cube.c
+++ b/cube/cube.c
@@ -4085,13 +4085,27 @@ static void demo_init(struct demo *demo, int argc, char **argv) {
i++;
continue;
}
- if (strcmp(argv[i], "--width") == 0 && i < argc - 1 && sscanf(argv[i + 1], "%d", &demo->width) == 1 && demo->width > 0) {
- i++;
- continue;
+ if (strcmp(argv[i], "--width") == 0) {
+ if (i < argc - 1 && sscanf(argv[i + 1], "%d", &demo->width) == 1) {
+ if (demo->width > 0) {
+ i++;
+ continue;
+ } else {
+ ERR_EXIT("The --width parameter must be greater than 0", "User Error");
+ }
+ }
+ ERR_EXIT("The --width parameter must be followed by a number", "User Error");
}
- if (strcmp(argv[i], "--height") == 0 && i < argc - 1 && sscanf(argv[i + 1], "%d", &demo->height) == 1 && demo->height > 0) {
- i++;
- continue;
+ if (strcmp(argv[i], "--height") == 0) {
+ if (i < argc - 1 && sscanf(argv[i + 1], "%d", &demo->height) == 1) {
+ if (demo->height > 0) {
+ i++;
+ continue;
+ } else {
+ ERR_EXIT("The --height parameter must be greater than 0", "User Error");
+ }
+ }
+ ERR_EXIT("The --height parameter must be followed by a number", "User Error");
}
if (strcmp(argv[i], "--suppress_popups") == 0) {
demo->suppress_popups = true;
diff --git a/cube/cube.cpp b/cube/cube.cpp
index 8950d81e..ff24b5d4 100644
--- a/cube/cube.cpp
+++ b/cube/cube.cpp
@@ -888,25 +888,31 @@ void Demo::init(int argc, char **argv) {
i++;
continue;
}
- if (strcmp(argv[i], "--width") == 0 && i < argc - 1) {
+ if (strcmp(argv[i], "--width") == 0) {
int32_t in_width = 0;
- if (sscanf(argv[i + 1], "%d", &in_width) == 1 && in_width > 0) {
- width = static_cast<uint32_t>(in_width);
- i++;
- continue;
- } else {
- ERR_EXIT("The --width parameter must be greater than 0", "User Error");
+ if (i < argc - 1 && sscanf(argv[i + 1], "%d", &in_width) == 1) {
+ if (in_width > 0) {
+ width = static_cast<uint32_t>(in_width);
+ i++;
+ continue;
+ } else {
+ ERR_EXIT("The --width parameter must be greater than 0", "User Error");
+ }
}
+ ERR_EXIT("The --width parameter must be followed by a number", "User Error");
}
- if (strcmp(argv[i], "--height") == 0 && i < argc - 1) {
+ if (strcmp(argv[i], "--height") == 0) {
int32_t in_height = 0;
- if (sscanf(argv[i + 1], "%d", &height) == 1 && height > 0) {
- height = static_cast<uint32_t>(in_height);
- i++;
- continue;
- } else {
- ERR_EXIT("The --height parameter must be greater than 0", "User Error");
+ if (i < argc - 1 && sscanf(argv[i + 1], "%d", &height) == 1) {
+ if (height > 0) {
+ height = static_cast<uint32_t>(in_height);
+ i++;
+ continue;
+ } else {
+ ERR_EXIT("The --height parameter must be greater than 0", "User Error");
+ }
}
+ ERR_EXIT("The --height parameter must be followed by a number", "User Error");
}
if (strcmp(argv[i], "--suppress_popups") == 0) {
suppress_popups = true;