From 0e5e14fe7cd97fa83e822c1e105cf498dbb4d276 Mon Sep 17 00:00:00 2001
From: Paul Sokolovsky <pfalcon@users.sourceforge.net>
Date: Fri, 8 Jul 2016 20:45:15 +0300
Subject: [PATCH] unix/main: Error out on unknown value of suffix in -X
 heapsize= option.

E.g. -X heapsize=16Kfoo, -X heapsize=1G will lead to error.
---
 unix/main.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/unix/main.c b/unix/main.c
index a463d2e10..17423de4d 100644
--- a/unix/main.c
+++ b/unix/main.c
@@ -351,12 +351,20 @@ STATIC void pre_process_options(int argc, char **argv) {
                         heap_size *= 1024;
                     } else if ((*end | 0x20) == 'm') {
                         heap_size *= 1024 * 1024;
+                    } else {
+                        // Compensate for ++ below
+                        --end;
+                    }
+                    if (*++end != 0) {
+                        goto invalid_arg;
                     }
                     if (word_adjust) {
                         heap_size = heap_size * BYTES_PER_WORD / 4;
                     }
 #endif
                 } else {
+invalid_arg:
+                    printf("Invalid option\n");
                     exit(usage(argv));
                 }
                 a++;
-- 
GitLab