Browse Source

Fix a bug: do not read in front of string s by s[-1].

Still needs more checking: we remmove and add 'params:'?
pre-master-46
Holger Vogt 9 months ago
parent
commit
dd1690521c
  1. 114
      src/frontend/inpcom.c

114
src/frontend/inpcom.c

@ -3645,74 +3645,76 @@ static char *inp_fix_subckt(struct names *subckt_w_params, char *s)
char *equal, *beg, *buffer, *ptr1, *ptr2, *new_str; char *equal, *beg, *buffer, *ptr1, *ptr2, *new_str;
equal = strchr(s, '='); equal = strchr(s, '=');
if (equal &&
(!strstr(s, "params:") || !isspace_c(s[-1]))) {
/* get subckt name (ptr1 will point to name) */
if (equal) {
char* paramstr = strstr(s, "params:");
if (!paramstr || !isspace_c(paramstr[-1])) {
ptr1 = skip_token(s);
for (ptr2 = ptr1; *ptr2 && !isspace_c(*ptr2) && !isquote(*ptr2);
/* get subckt name (ptr1 will point to name) */
ptr1 = skip_token(s);
for (ptr2 = ptr1; *ptr2 && !isspace_c(*ptr2) && !isquote(*ptr2);
ptr2++) ptr2++)
;
add_name(subckt_w_params, copy_substring(ptr1, ptr2));
/* go to beginning of first parameter word */
/* s will contain only subckt definition */
/* beg will point to start of param list */
beg = skip_back_ws(equal, s);
beg = skip_back_non_ws(beg, s);
beg[-1] = '\0'; /* fixme can be < s */
head = insert_new_line(NULL, NULL, 0, 0, "internal");
/* create list of parameters that need to get sorted */
first_param_card = c = NULL;
while ((ptr1 = strchr(beg, '=')) != NULL) {
ptr2 = skip_ws(ptr1 + 1);
ptr1 = skip_back_ws(ptr1, beg);
ptr1 = skip_back_non_ws(ptr1, beg);
/* ptr1 points to beginning of parameter */
if (*ptr2 == '{')
ptr2 = inp_spawn_brace(ptr2);
else
ptr2 = skip_non_ws(ptr2);
;
if (!ptr2) {
fprintf(stderr, "Error: Missing } in line %s\n", s);
controlled_exit(EXIT_FAILURE);
}
add_name(subckt_w_params, copy_substring(ptr1, ptr2));
/* go to beginning of first parameter word */
/* s will contain only subckt definition */
/* beg will point to start of param list */
beg = skip_back_ws(equal, s);
beg = skip_back_non_ws(beg, s);
beg[-1] = '\0'; /* fixme can be < s */
head = insert_new_line(NULL, NULL, 0, 0, "internal");
/* create list of parameters that need to get sorted */
first_param_card = c = NULL;
while ((ptr1 = strchr(beg, '=')) != NULL) {
ptr2 = skip_ws(ptr1 + 1);
ptr1 = skip_back_ws(ptr1, beg);
ptr1 = skip_back_non_ws(ptr1, beg);
/* ptr1 points to beginning of parameter */
if (*ptr2 == '{')
ptr2 = inp_spawn_brace(ptr2);
else
ptr2 = skip_non_ws(ptr2);
beg = ptr2;
if (!ptr2) {
fprintf(stderr, "Error: Missing } in line %s\n", s);
controlled_exit(EXIT_FAILURE);
}
c = insert_new_line(c, copy_substring(ptr1, ptr2), 0, 0, "internal");
beg = ptr2;
if (!first_param_card)
first_param_card = c;
}
/* now sort parameters in order of dependencies */
inp_sort_params(first_param_card, head, NULL, NULL);
c = insert_new_line(c, copy_substring(ptr1, ptr2), 0, 0, "internal");
/* create new ordered parameter string for subckt call */
new_str = NULL;
for (c = head->nextcard; c; c = c->nextcard)
if (new_str == NULL) {
new_str = copy(c->line);
}
else {
char *x = tprintf("%s %s", new_str, c->line);
tfree(new_str);
new_str = x;
if (!first_param_card)
first_param_card = c;
} }
/* now sort parameters in order of dependencies */
inp_sort_params(first_param_card, head, NULL, NULL);
/* create new ordered parameter string for subckt call */
new_str = NULL;
for (c = head->nextcard; c; c = c->nextcard)
if (new_str == NULL) {
new_str = copy(c->line);
}
else {
char* x = tprintf("%s %s", new_str, c->line);
tfree(new_str);
new_str = x;
}
line_free_x(head, TRUE);
line_free_x(head, TRUE);
/* create buffer and insert params: */
buffer = tprintf("%s params: %s", s, new_str);
/* create buffer and insert params: */
buffer = tprintf("%s params: %s", s, new_str);
tfree(s);
tfree(new_str);
tfree(s);
tfree(new_str);
s = buffer;
s = buffer;
}
} }
return s; return s;

Loading…
Cancel
Save