aboutsummaryrefslogtreecommitdiffstats
path: root/src/jalv_console.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2024-09-29 19:30:13 -0400
committerDavid Robillard <d@drobilla.net>2024-10-12 14:07:10 -0400
commit8c7b645094d026367cecadb05f66a49800dd4235 (patch)
tree1c0819e5fba57222ad4749ba670458de7da3eb86 /src/jalv_console.c
parent64033dfbb9e9d2fff0df887fc5730c9f97ea4e0d (diff)
downloadjalv-8c7b645094d026367cecadb05f66a49800dd4235.tar.gz
jalv-8c7b645094d026367cecadb05f66a49800dd4235.tar.bz2
jalv-8c7b645094d026367cecadb05f66a49800dd4235.zip
Handle realloc failure everywhere
Diffstat (limited to 'src/jalv_console.c')
-rw-r--r--src/jalv_console.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/jalv_console.c b/src/jalv_console.c
index 635b668..3cbd76c 100644
--- a/src/jalv_console.c
+++ b/src/jalv_console.c
@@ -128,10 +128,17 @@ jalv_frontend_init(int* argc, char*** argv, JalvOptions* opts)
fprintf(stderr, "Missing argument for -c\n");
return 1;
}
- opts->controls =
- (char**)realloc(opts->controls, (++n_controls + 1) * sizeof(char*));
- opts->controls[n_controls - 1] = (*argv)[a];
- opts->controls[n_controls] = NULL;
+
+ char** new_controls =
+ (char**)realloc(opts->controls, (n_controls + 2) * sizeof(char*));
+ if (!new_controls) {
+ fprintf(stderr, "Out of memory\n");
+ return 12;
+ }
+
+ opts->controls = new_controls;
+ opts->controls[n_controls++] = (*argv)[a];
+ opts->controls[n_controls] = NULL;
} else if ((*argv)[a][1] == 'i') {
opts->non_interactive = true;
} else if ((*argv)[a][1] == 'd') {