fix unterminated result in subst_token()

This commit is contained in:
Stefan SChippers 2020-08-17 14:35:45 +02:00
parent 8e4e23cf2d
commit 7cab8d9e73
2 changed files with 7 additions and 4 deletions

View File

@ -1149,7 +1149,8 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
{
char *s=NULL;
my_strdup(894, &s, subst_token(argv[2], argv[3], strcmp(argv[4], "NULL") ? argv[4] : NULL));
Tcl_SetResult(interp, s, TCL_VOLATILE);
Tcl_ResetResult(interp);
Tcl_AppendResult(interp, s, NULL);
my_free(1150, &s);
}
@ -1157,14 +1158,16 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
{
char s[30];
my_snprintf(s, S(s), "%d", (int)get_tok_size);
Tcl_SetResult(interp, s, TCL_VOLATILE);
Tcl_ResetResult(interp);
Tcl_AppendResult(interp, s, NULL);
}
else if(!strcmp(argv[1],"get_tok") )
{
char *s=NULL;
my_strdup(648, &s, get_tok_value(argv[2], argv[3], 0));
Tcl_SetResult(interp, s, TCL_VOLATILE);
Tcl_ResetResult(interp);
Tcl_AppendResult(interp, s, NULL);
my_free(649, &s);
}
else if(!strcmp(argv[1],"load_symbol") )

View File

@ -859,7 +859,7 @@ char *subst_token(const char *s, const char *tok, const char *new_val)
}
else result[result_pos++]=c;
} else if(state == XEND || state == XBEGIN) {
if(cmptok || new_val) result[result_pos++] = c; /* if deleting a token skip also following spaces up to next token */
if(c == '\0' || cmptok || new_val) result[result_pos++] = c; /* if deleting a token skip also following spaces up to next token */
state = XBEGIN;
}
if(c == '\0') break;