From 8f30b68871bde8687c7fcff8bac66e2b5765129e Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Wed, 16 Sep 2009 17:07:01 +0000 Subject: - Add xcalloc() and call it - Fix memory errors found by valgrind - Remove multi_glob() and empower parse_file_seq() to do its job: the goal here is to remove the confusing reverse/re-reverse we do on the file lists: needed for future fixes. - Add a prefix arg to parse_file_seq() - Make concat() variadic so it can take arbitrary #'s of strings --- ar.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'ar.c') diff --git a/ar.c b/ar.c index 304ee9c..728f8bc 100644 --- a/ar.c +++ b/ar.c @@ -196,9 +196,8 @@ ar_glob_match (int desc UNUSED, const char *mem, int truncated UNUSED, if (fnmatch (state->pattern, mem, FNM_PATHNAME|FNM_PERIOD) == 0) { /* We have a match. Add it to the chain. */ - struct nameseq *new = xmalloc (state->size); - memset (new, '\0', state->size); - new->name = strcache_add (concat (state->arname, mem, ")")); + struct nameseq *new = xcalloc (state->size); + new->name = strcache_add (concat (4, state->arname, "(", mem, ")")); new->next = state->chain; state->chain = new; ++state->n; @@ -249,7 +248,6 @@ ar_glob (const char *arname, const char *member_pattern, unsigned int size) struct ar_glob_state state; struct nameseq *n; const char **names; - char *name; unsigned int i; if (! glob_pattern_p (member_pattern, 1)) @@ -257,12 +255,7 @@ ar_glob (const char *arname, const char *member_pattern, unsigned int size) /* Scan the archive for matches. ar_glob_match will accumulate them in STATE.chain. */ - i = strlen (arname); - name = alloca (i + 2); - memcpy (name, arname, i); - name[i] = '('; - name[i + 1] = '\0'; - state.arname = name; + state.arname = arname; state.pattern = member_pattern; state.size = size; state.chain = 0; -- cgit v1.2.3