From 0afbbf8595b6035a5a930399d20320d2e2852d72 Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Thu, 24 Sep 2009 02:41:44 +0000 Subject: - Rework secondary expansion so we only defer it if there's a possibility it might be needed: for most situations we parse prereqs immediately as we used to. Reduces memory usage. - Fixes Savannah bug #18622. --- misc.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'misc.c') diff --git a/misc.c b/misc.c index f822747..67d1563 100644 --- a/misc.c +++ b/misc.c @@ -430,7 +430,8 @@ xstrndup (const char *str, unsigned int length) fatal (NILF, _("virtual memory exhausted")); #else result = xmalloc (length + 1); - strncpy (result, str, length); + if (length > 0) + strncpy (result, str, length); result[length] = '\0'; #endif @@ -524,8 +525,7 @@ find_next_token (const char **ptr, unsigned int *lengthptr) } -/* Copy a chain of `struct dep', making a new chain - with the same contents as the old one. */ +/* Copy a chain of `struct dep'. For 2nd expansion deps, dup the name. */ struct dep * copy_dep_chain (const struct dep *d) @@ -538,6 +538,9 @@ copy_dep_chain (const struct dep *d) struct dep *c = xmalloc (sizeof (struct dep)); memcpy (c, d, sizeof (struct dep)); + if (c->need_2nd_expansion) + c->name = xstrdup (c->name); + c->next = 0; if (firstnew == 0) firstnew = lastnew = c; -- cgit v1.2.3