From 0809286db1636b6a981e0b397d6d2bdea2a00e15 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Wed, 4 Oct 2023 22:56:06 +0200 Subject: Assert that the argument to ‘-p’ isn’t empty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.l | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/main.l b/main.l index 3ccae4a..2d26cd0 100644 --- a/main.l +++ b/main.l @@ -12,6 +12,8 @@ const char empty_field[] = "argument to the -p option contains an empty field"; const char invalid_char[] = "argument to the -p option must be a " "comma-seperated list of positive integers"; const char final_comma[] = "argument to the -p option contains trailing comma"; +const char empty_string[] = "argument to the -p option cannot be " + "the empty string"; const char *argv0; unsigned pos; @@ -102,6 +104,11 @@ append_positions(char *raw) usage(); } + if (*raw == '\0') { + warnx(empty_string); + usage(); + } + for (s = raw, positions.len++; *s; s++) { switch (*s) { case ',': -- cgit v1.2.3