summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/make/var.c35
1 files changed, 17 insertions, 18 deletions
diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c
index e6f81844b2e1..3f2a9f76fb5d 100644
--- a/usr.bin/make/var.c
+++ b/usr.bin/make/var.c
@@ -1526,8 +1526,20 @@ VarParseLong(char foo[], GNode *ctxt, Boolean err, size_t *lengthPtr,
endc = (startc == OPEN_PAREN) ? CLOSE_PAREN : CLOSE_BRACE;
tstr = rw_str + 2;
- while (*tstr != '\0' && *tstr != endc && *tstr != ':') {
- if (*tstr == '$') {
+ while (*tstr != endc && *tstr != ':') {
+ if (*tstr == '\0') {
+ /*
+ * If we did not find the end character,
+ * return var_Error right now, setting the
+ * length to be the distance to the end of
+ * the string, since that's what make does.
+ */
+ *freePtr = FALSE;
+ *lengthPtr = tstr - input;
+ Buf_Destroy(buf, TRUE);
+ return (var_Error);
+
+ } else if (*tstr == '$') {
size_t rlen;
Boolean rfree;
char *rval;
@@ -1537,11 +1549,9 @@ VarParseLong(char foo[], GNode *ctxt, Boolean err, size_t *lengthPtr,
if (rval == var_Error) {
Fatal("Error expanding embedded variable.");
}
- if (rval != NULL) {
- Buf_Append(buf, rval);
- if (rfree)
- free(rval);
- }
+ Buf_Append(buf, rval);
+ if (rfree)
+ free(rval);
tstr += rlen - 1;
} else {
Buf_AddByte(buf, (Byte)*tstr);
@@ -1549,17 +1559,6 @@ VarParseLong(char foo[], GNode *ctxt, Boolean err, size_t *lengthPtr,
tstr++;
}
- if (*tstr == '\0') {
- /*
- * If we never did find the end character, return NULL
- * right now, setting the length to be the distance to
- * the end of the string, since that's what make does.
- */
- *freePtr = FALSE;
- *lengthPtr = tstr - input;
- return (var_Error);
- }
-
haveModifier = (*tstr == ':');
vname = Buf_GetAll(buf, (size_t *)NULL); /* REPLACE str */