Move the check for the error case (variable ends without a closing

paranthesis or brace) into the loop and don't leak the buffer in this
case. Remove the check for Var_Parse returning NULL - it can't.

Patch:		7.92

Submitted by:	Max Okumoto <okumoto@ucsd.edu>
This commit is contained in:
harti 2005-03-02 15:52:04 +00:00
parent 4d2ae547ed
commit 0724297b39

View File

@ -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 */