diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-02-28 18:15:15 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-02-28 18:15:15 -0500 |
| commit | 39e169d5b4171487c5348b981a8574fd98b49ed0 (patch) | |
| tree | 2ff82fec6cf0ddb5e46bdf0aa642102c5d6ab0f6 /stdlib | |
| parent | 12569cb933c0642a4fd1df074115cc21e198d677 (diff) | |
Check for missing argument
Diffstat (limited to 'stdlib')
| -rw-r--r-- | stdlib/stdlib.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/stdlib/stdlib.c b/stdlib/stdlib.c index d07fa68e..8e10f40e 100644 --- a/stdlib/stdlib.c +++ b/stdlib/stdlib.c @@ -69,6 +69,8 @@ public void tomo_init(void) static bool parse_single_arg(const TypeInfo_t *info, char *arg, void *dest) { + if (!arg) return false; + while (info->tag == OptionalInfo) info = info->OptionalInfo.type; @@ -241,6 +243,8 @@ public void _tomo_parse_args(int argc, char *argv[], Text_t usage, Text_t help, populated_args[s] = true; *(OptionalBool_t*)spec[s].dest = true; } else { + if (i + 1 >= argc) + errx(1, "Missing argument: %s\n%k", argv[i], &usage); used_args[i+1] = true; populated_args[s] = parse_single_arg(spec[s].type, argv[i+1], spec[s].dest); if (!populated_args[s]) |
