aboutsummaryrefslogtreecommitdiff
path: root/booki.c
diff options
context:
space:
mode:
authorBen Winston2024-06-07 21:42:53 -0400
committerBen Winston2024-06-07 21:42:53 -0400
commitea9226df0bd7e820d1dbcad839265f1d5c4a8ff7 (patch)
tree5f7243b20d96ca857e14d92a5498d3da1d415484 /booki.c
parentae60a8385a97689a61680b49400d70d553cfb299 (diff)
prevent null dereference on bad search term
Diffstat (limited to 'booki.c')
-rw-r--r--booki.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/booki.c b/booki.c
index 5b884d9..c780c44 100644
--- a/booki.c
+++ b/booki.c
@@ -765,6 +765,11 @@ struct search_opt parse_search_options(int argc, char* argv[]) {
edit = true;
break;
case '?':
+ if (!argv[optind] || argv[optind][0] == '-') {
+ printf("%s requires an operand\n", argv[optind-1]);
+ opt_out.count = -1;
+ return opt_out;
+ }
// optind points at the argument (one past the option)
opt_out.opts[count] = argv[optind-1] + 2; // '--example' -> 'example'
opt_out.args[count] = argv[optind];
@@ -786,6 +791,9 @@ struct search_opt parse_search_options(int argc, char* argv[]) {
void search(int argc, char* argv[], char* booki_file) {
struct search_opt search_opts = parse_search_options(argc, argv);
+ if (search_opts.count == -1) {
+ return;
+ }
// get the books array
char* data = load_file(booki_file);