summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Giessen <charles@lunarg.com>2022-12-01 14:39:43 -0600
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>2023-01-18 18:37:52 -0700
commit3327bd3ace8ebb6102f061be452f9fcfd512677b (patch)
tree038383aca852862274cf0e0aa01e54ad27bb312f
parentc37dcfbae606437a59d35d7bd5384b1a425efd41 (diff)
downloadVulkan-Tools-3327bd3ace8ebb6102f061be452f9fcfd512677b.tar.gz
Vulkan-Tools-3327bd3ace8ebb6102f061be452f9fcfd512677b.tar.bz2
Vulkan-Tools-3327bd3ace8ebb6102f061be452f9fcfd512677b.zip
cubepp: Make sure width & height are > 0
This check was present in cube but wasn't added to cubepp. Because width and height are stored as uint32_t, we first need to read them in as int32_t and make sure they aren't negative.
-rw-r--r--cube/cube.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/cube/cube.cpp b/cube/cube.cpp
index 9bdb17ce..8950d81e 100644
--- a/cube/cube.cpp
+++ b/cube/cube.cpp
@@ -888,13 +888,25 @@ void Demo::init(int argc, char **argv) {
i++;
continue;
}
- if (strcmp(argv[i], "--width") == 0 && i < argc - 1 && sscanf(argv[i + 1], "%" SCNu32, &width) == 1) {
- i++;
- continue;
+ if (strcmp(argv[i], "--width") == 0 && i < argc - 1) {
+ 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 (strcmp(argv[i], "--height") == 0 && i < argc - 1 && sscanf(argv[i + 1], "%" SCNu32, &height) == 1) {
- i++;
- continue;
+ if (strcmp(argv[i], "--height") == 0 && i < argc - 1) {
+ 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 (strcmp(argv[i], "--suppress_popups") == 0) {
suppress_popups = true;