Module Name: src Committed By: rillig Date: Sun Dec 12 22:41:47 UTC 2021
Modified Files: src/usr.bin/make: arch.c Log Message: make: use simpler memory management for parsing archive members No functional change. To generate a diff of this commit: cvs rdiff -u -r1.204 -r1.205 src/usr.bin/make/arch.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/make/arch.c diff -u src/usr.bin/make/arch.c:1.204 src/usr.bin/make/arch.c:1.205 --- src/usr.bin/make/arch.c:1.204 Sun Nov 28 19:51:06 2021 +++ src/usr.bin/make/arch.c Sun Dec 12 22:41:47 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: arch.c,v 1.204 2021/11/28 19:51:06 rillig Exp $ */ +/* $NetBSD: arch.c,v 1.205 2021/12/12 22:41:47 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -126,7 +126,7 @@ #include "config.h" /* "@(#)arch.c 8.2 (Berkeley) 1/2/94" */ -MAKE_RCSID("$NetBSD: arch.c,v 1.204 2021/11/28 19:51:06 rillig Exp $"); +MAKE_RCSID("$NetBSD: arch.c,v 1.205 2021/12/12 22:41:47 rillig Exp $"); typedef struct List ArchList; typedef struct ListNode ArchListNode; @@ -202,7 +202,7 @@ Arch_ParseArchive(char **pp, GNodeList * char *cp; /* Pointer into line */ GNode *gn; /* New node */ MFStr libName; /* Library-part of specification */ - char *memName; /* Member-part of specification */ + FStr mem; /* Member-part of specification */ char saveChar; /* Ending delimiter of member-name */ bool expandLibName; /* Whether the parsed libName contains * variable expressions that need to be @@ -253,7 +253,7 @@ Arch_ParseArchive(char **pp, GNodeList * pp_skip_whitespace(&cp); - memName = cp; + mem = FStr_InitRefer(cp); while (*cp != '\0' && *cp != ')' && !ch_isspace(*cp)) { if (*cp == '$') { /* Expand nested variable expressions. */ @@ -294,7 +294,7 @@ Arch_ParseArchive(char **pp, GNodeList * /* * If we didn't move anywhere, we must be done */ - if (cp == memName) + if (cp == mem.str) break; saveChar = *cp; @@ -315,22 +315,22 @@ Arch_ParseArchive(char **pp, GNodeList * */ if (doSubst) { char *fullName; - char *p; - char *unexpandedMemName = memName; + char *p, *expandedMem; + const char *unexpandedMem = mem.str; - (void)Var_Subst(memName, scope, VARE_UNDEFERR, - &memName); + (void)Var_Subst(mem.str, scope, VARE_UNDEFERR, + &expandedMem); /* TODO: handle errors */ + mem = FStr_InitOwn(expandedMem); /* * Now form an archive spec and recurse to deal with * nested variables and multi-word variable values. */ - fullName = FullName(libName.str, memName); + fullName = FullName(libName.str, mem.str); p = fullName; - if (strchr(memName, '$') != NULL && - strcmp(memName, unexpandedMemName) == 0) { + if (strcmp(mem.str, unexpandedMem) == 0) { /* * Must contain dynamic sources, so we can't * deal with it now. Just create an ARCHV node @@ -350,9 +350,9 @@ Arch_ParseArchive(char **pp, GNodeList * free(fullName); /* XXX: does unexpandedMemName leak? */ - } else if (Dir_HasWildcards(memName)) { + } else if (Dir_HasWildcards(mem.str)) { StringList members = LST_INIT; - SearchPath_Expand(&dirSearchPath, memName, &members); + SearchPath_Expand(&dirSearchPath, mem.str, &members); while (!Lst_IsEmpty(&members)) { char *member = Lst_Dequeue(&members); @@ -368,7 +368,7 @@ Arch_ParseArchive(char **pp, GNodeList * Lst_Done(&members); } else { - char *fullname = FullName(libName.str, memName); + char *fullname = FullName(libName.str, mem.str); gn = Targ_GetNode(fullname); free(fullname); @@ -382,8 +382,7 @@ Arch_ParseArchive(char **pp, GNodeList * gn->type |= OP_ARCHV; Lst_Append(gns, gn); } - if (doSubst) - free(memName); + FStr_Done(&mem); *cp = saveChar; }