summaryrefslogtreecommitdiffstats
path: root/src/parse.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2023-06-19 12:11:36 -0400
committerTavian Barnes <tavianator@tavianator.com>2023-06-20 14:26:09 -0400
commit90ded13e589b0089167ef25ca3d26be599dfec9b (patch)
treed5a007948587f62fff62c851ddd3886b5a5e78ed /src/parse.c
parent9ceb2b27577f1be3f30edb40a45117066fc78c51 (diff)
downloadbfs-90ded13e589b0089167ef25ca3d26be599dfec9b.tar.xz
alloc: New header for memory allocation utilities
Diffstat (limited to 'src/parse.c')
-rw-r--r--src/parse.c28
1 files changed, 3 insertions, 25 deletions
diff --git a/src/parse.c b/src/parse.c
index 64e08cd..cf4f696 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -9,6 +9,7 @@
*/
#include "parse.h"
+#include "alloc.h"
#include "bfstd.h"
#include "bftw.h"
#include "color.h"
@@ -55,39 +56,16 @@ static char *fake_print_arg = "-print";
static char *fake_true_arg = "-true";
struct bfs_expr *bfs_expr_new(bfs_eval_fn *eval_fn, size_t argc, char **argv) {
- struct bfs_expr *expr = malloc(sizeof(*expr));
+ struct bfs_expr *expr = ZALLOC(struct bfs_expr);
if (!expr) {
- perror("malloc()");
+ perror("zalloc()");
return NULL;
}
expr->eval_fn = eval_fn;
expr->argc = argc;
expr->argv = argv;
- expr->persistent_fds = 0;
- expr->ephemeral_fds = 0;
- expr->pure = false;
- expr->always_true = false;
- expr->always_false = false;
- expr->cost = 0.0;
expr->probability = 0.5;
- expr->evaluations = 0;
- expr->successes = 0;
- expr->elapsed.tv_sec = 0;
- expr->elapsed.tv_nsec = 0;
-
- // Prevent bfs_expr_free() from freeing uninitialized pointers on error paths
- if (bfs_expr_is_parent(expr)) {
- expr->lhs = NULL;
- expr->rhs = NULL;
- } else if (eval_fn == eval_exec) {
- expr->exec = NULL;
- } else if (eval_fn == eval_fprintf) {
- expr->printf = NULL;
- } else if (eval_fn == eval_regex) {
- expr->regex = NULL;
- }
-
return expr;
}