From 1e00b18cb5a22b59e86605dc4255915e43131f21 Mon Sep 17 00:00:00 2001 From: night0721 Date: Sun, 17 Nov 2024 19:30:14 +0000 Subject: [PATCH] Reduce use of malloc --- ccc.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/ccc.c b/ccc.c index dca3918..21fd97a 100644 --- a/ccc.c +++ b/ccc.c @@ -82,9 +82,9 @@ unsigned int focus = 0; long sel_file = 0; int file_picker = 1; int to_open_file = 0; -char *argv_cp; -char cwd[4096]; -char p_cwd[4096]; /* previous cwd */ +char argv_cp[PATH_MAX]; +char cwd[PATH_MAX]; +char p_cwd[PATH_MAX]; /* previous cwd */ int half_width; ArrayList *files; ArrayList *marked; @@ -115,7 +115,7 @@ int main(int argc, char **argv) perror("ccc"); die("Error from chdir"); } else if (S_ISREG(st.st_mode)) { - argv_cp = estrdup(argv[1]); + strcpy(argv_cp, argv[1]); char *last_slash = strrchr(argv_cp, '/'); if (last_slash) { *last_slash = '\0'; @@ -432,8 +432,6 @@ void handle_sigwinch(int ignore) void cleanup(void) { - if (argv_cp) - free(argv_cp); if (files->length != 0) { arraylist_free(files); }