summaryrefslogtreecommitdiffstats
path: root/usr.bin/make/var.c
diff options
context:
space:
mode:
authorharti <harti@FreeBSD.org>2005-03-15 15:05:14 +0000
committerharti <harti@FreeBSD.org>2005-03-15 15:05:14 +0000
commit6fc3b6df1c0916bc4f43236c1d1a20721540c440 (patch)
tree1c8e7aa7931241151a8db237bb49c3fb184d60dd /usr.bin/make/var.c
parentc3d17f2e0346df737f3d9959b4f181039e65a741 (diff)
downloadFreeBSD-src-6fc3b6df1c0916bc4f43236c1d1a20721540c440.zip
FreeBSD-src-6fc3b6df1c0916bc4f43236c1d1a20721540c440.tar.gz
modifier_M: instead of going through the string twice to compute the
size of the buffer we need, just allocate the possible maximum. Patch: 7.117 Submitted by: Max Okumoto <okumoto@ucsd.edu>
Diffstat (limited to 'usr.bin/make/var.c')
-rw-r--r--usr.bin/make/var.c31
1 files changed, 10 insertions, 21 deletions
diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c
index b228e4a..dc8cd0b 100644
--- a/usr.bin/make/var.c
+++ b/usr.bin/make/var.c
@@ -898,35 +898,24 @@ static char *
modifier_M(const char mod[], const char value[], char endc, size_t *consumed)
{
const char *cur;
- const char *end;
char *patt;
char *ptr;
char *newValue;
- for (cur = mod + 1; *cur != '\0'; cur++) {
- if (cur[0] == endc) {
- break;
- } else if (cur[0] == ':') {
- break;
- } else if ((cur[0] == '\\') &&
- (cur[1] == ':' || cur[1] == endc)) {
- cur++;
- }
- }
- end = cur;
-
/*
* Compress the \:'s out of the pattern, so allocate enough
* room to hold the uncompressed pattern and compress the
- * pattern into the space. (note that cur started at mod+1
- * so cur-mod takes the null byte into account)
+ * pattern into that space.
*/
- patt = emalloc(cur - mod);
+ patt = estrdup(mod);
ptr = patt;
- for (cur = mod + 1; cur != end; cur++) {
+ for (cur = mod + 1; cur != '\0'; cur++) {
+ if ((cur[0] == endc) || (cur[0] == ':')) {
+ break;
+ }
if ((cur[0] == '\\') &&
- (cur[1] == ':' || cur[1] == endc)) {
- cur++;
+ ((cur[1] == endc) || (cur[1] == ':'))) {
+ cur++; /* skip over backslash */
}
*ptr = *cur;
ptr++;
@@ -940,9 +929,9 @@ modifier_M(const char mod[], const char value[], char endc, size_t *consumed)
}
free(patt);
- *consumed += (end - mod);
+ *consumed += (cur - mod);
- if (*end == ':') {
+ if (*cur == ':') {
*consumed += 1; /* include colon as part of modifier */
}
OpenPOWER on IntegriCloud