summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
authorPaul Smith <psmith@gnu.org>2009-09-24 02:41:44 +0000
committerPaul Smith <psmith@gnu.org>2009-09-24 02:41:44 +0000
commit0afbbf8595b6035a5a930399d20320d2e2852d72 (patch)
tree6c74d485e4d57b2bf41bb5d6afaac1b4569dd554 /misc.c
parent3cc351decdd7d53fea0c730fd919163f20706762 (diff)
downloadgunmake-0afbbf8595b6035a5a930399d20320d2e2852d72.tar.gz
- 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.
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c9
1 files changed, 6 insertions, 3 deletions
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;