diff --git a/src/frontend/device.c b/src/frontend/device.c index 78a9bb4e1..181f7e49b 100644 --- a/src/frontend/device.c +++ b/src/frontend/device.c @@ -1106,8 +1106,7 @@ if_set_binned_model(CKTcircuit *ckt, char *devname, char *param, struct dvec *va else l = *val->v_realdata; /* overwrite the length with the alter param */ - width_length = TMALLOC(char, 36); - (void) sprintf(width_length, "w=%15.7e l=%15.7e", w, l); + width_length = tprintf("w=%15.7e l=%15.7e", w, l); if_setparam_model(ft_curckt->ci_ckt, &devname, width_length); FREE(width_length); diff --git a/src/frontend/inp.c b/src/frontend/inp.c index 18bd83c7a..13d18a2bd 100644 --- a/src/frontend/inp.c +++ b/src/frontend/inp.c @@ -1646,8 +1646,7 @@ static void inp_savecurrents(struct line *deck, struct line *options, wordlist * devline = tmp_deck->li_line; devname = gettok(&devline); /* .save @q1[id] @q1[is] @q1[ig] @q1[ib] */ - newline = TMALLOC(char, 4 * strlen(devname) + 30); - sprintf(newline, ".save @%s[id] @%s[is] @%s[ig] @%s[ib]", + newline = tprintf(".save @%s[id] @%s[is] @%s[ig] @%s[ib]", devname, devname, devname, devname); wl_append_word(NULL, wl, newline); break; @@ -1655,8 +1654,7 @@ static void inp_savecurrents(struct line *deck, struct line *options, wordlist * devline = tmp_deck->li_line; devname = gettok(&devline); /* .save @q1[id] @q1[is] @q1[ig] @q1[igd] */ - newline = TMALLOC(char, 4 * strlen(devname) + 31); - sprintf(newline, ".save @%s[id] @%s[is] @%s[ig] @%s[igd]", + newline = tprintf(".save @%s[id] @%s[is] @%s[ig] @%s[igd]", devname, devname, devname, devname); wl_append_word(NULL, wl, newline); break; @@ -1664,8 +1662,7 @@ static void inp_savecurrents(struct line *deck, struct line *options, wordlist * devline = tmp_deck->li_line; devname = gettok(&devline); /* .save @q1[ic] @q1[ie] @q1[ib] @q1[is] */ - newline = TMALLOC(char, 4 * strlen(devname) + 30); - sprintf(newline, ".save @%s[ic] @%s[ie] @%s[ib] @%s[is]", + newline = tprintf(".save @%s[ic] @%s[ie] @%s[ib] @%s[is]", devname, devname, devname, devname); wl_append_word(NULL, wl, newline); break; @@ -1673,8 +1670,7 @@ static void inp_savecurrents(struct line *deck, struct line *options, wordlist * devline = tmp_deck->li_line; devname = gettok(&devline); /* .save @d1[id] */ - newline = TMALLOC(char, strlen(devname) + 12); - sprintf(newline, ".save @%s[id]", devname); + newline = tprintf(".save @%s[id]", devname); wl_append_word(NULL, wl, newline); break; case 'r': @@ -1688,16 +1684,14 @@ static void inp_savecurrents(struct line *deck, struct line *options, wordlist * devline = tmp_deck->li_line; devname = gettok(&devline); /* .save @r1[i] */ - newline = TMALLOC(char, strlen(devname) + 11); - sprintf(newline, ".save @%s[i]", devname); + newline = tprintf(".save @%s[i]", devname); wl_append_word(NULL, wl, newline); break; case 'i': devline = tmp_deck->li_line; devname = gettok(&devline); /* .save @i1[current] */ - newline = TMALLOC(char, strlen(devname) + 17); - sprintf(newline, ".save @%s[current]", devname); + newline = tprintf(".save @%s[current]", devname); wl_append_word(NULL, wl, newline); break; default: diff --git a/src/frontend/inpcom.c b/src/frontend/inpcom.c index d4157ca5d..b0ed67961 100644 --- a/src/frontend/inpcom.c +++ b/src/frontend/inpcom.c @@ -382,8 +382,7 @@ inp_stitch_continuation_lines(struct line *working) } /* create buffer and write last and current line into it. */ - buffer = TMALLOC(char, strlen(prev->li_line) + strlen(s) + 2); - (void) sprintf(buffer, "%s %s", prev->li_line, s + 1); + buffer = tprintf("%s %s", prev->li_line, s + 1); /* replace prev->li_line by buffer */ s = prev->li_line; @@ -873,8 +872,7 @@ inp_read(FILE *fp, int call_depth, char *dir_name, bool comfile, bool intfile) } if (shell_eol_continuation) { - char *new_buffer = TMALLOC(char, strlen(buffer) + 2); - sprintf(new_buffer, "+%s", buffer); + char *new_buffer = tprintf("+%s", buffer); tfree(buffer); buffer = new_buffer; @@ -1331,8 +1329,7 @@ inp_add_control_section(struct line *deck, int *line_number) } if (cp_getvar("rawfile", CP_STRING, rawfile)) { - line = TMALLOC(char, strlen("write") + strlen(rawfile) + 2); - sprintf(line, "write %s", rawfile); + line = tprintf("write %s", rawfile); prev_card->li_next = xx_new_line(c, line, (*line_number)++, 0); prev_card = prev_card->li_next; } @@ -1347,8 +1344,7 @@ inp_add_control_section(struct line *deck, int *line_number) deck->li_next = xx_new_line(deck->li_next, copy(".endc"), (*line_number)++, 0); if (cp_getvar("rawfile", CP_STRING, rawfile)) { - line = TMALLOC(char, strlen("write") + strlen(rawfile) + 2); - sprintf(line, "write %s", rawfile); + line = tprintf("write %s", rawfile); deck->li_next = xx_new_line(deck->li_next, line, (*line_number)++, 0); } @@ -1404,11 +1400,9 @@ inp_fix_macro_param_func_paren_io(struct line *card) str_ptr = skip_non_ws(card->li_line); if (ciprefix(".macro", card->li_line)) { - new_str = TMALLOC(char, strlen(".subckt") + strlen(str_ptr) + 1); - sprintf(new_str, ".subckt%s", str_ptr); + new_str = tprintf(".subckt%s", str_ptr); } else { - new_str = TMALLOC(char, strlen(".ends") + strlen(str_ptr) + 1); - sprintf(new_str, ".ends%s", str_ptr); + new_str = tprintf(".ends%s", str_ptr); } tfree(card->li_line); @@ -2218,8 +2212,7 @@ inp_fix_subckt(struct names *subckt_w_params, char *s) if (new_str == NULL) { new_str = strdup(c->li_line); } else { - char *x = TMALLOC(char, strlen(new_str) + strlen(c->li_line) + 2); - sprintf(x, "%s %s", new_str, c->li_line); + char *x = tprintf("%s %s", new_str, c->li_line); tfree(new_str); new_str = x; } @@ -2230,8 +2223,7 @@ inp_fix_subckt(struct names *subckt_w_params, char *s) } /* create buffer and insert params: */ - buffer = TMALLOC(char, strlen(s) + 9 + strlen(new_str) + 1); - sprintf(buffer, "%s params: %s", s, new_str); + buffer = tprintf("%s params: %s", s, new_str); tfree(s); tfree(new_str); @@ -2576,8 +2568,7 @@ inp_fix_inst_line(char *inst_line, } for (i = 0; i < num_subckt_params; i++) { - new_line = TMALLOC(char, strlen(curr_line) + strlen(subckt_param_values[i]) + 2); - sprintf(new_line, "%s %s", curr_line, subckt_param_values[i]); + new_line = tprintf("%s %s", curr_line, subckt_param_values[i]); tfree(curr_line); tfree(subckt_param_names[i]); @@ -2634,12 +2625,10 @@ inp_fix_subckt_multiplier(struct names *subckt_w_params, struct line *subckt_car num_subckt_params ++; if (!strstr(subckt_card->li_line, "params:")) { - new_str = TMALLOC(char, strlen(subckt_card->li_line) + 13); - sprintf(new_str, "%s params: m=1", subckt_card->li_line); + new_str = tprintf("%s params: m=1", subckt_card->li_line); add_name(subckt_w_params, get_subckt_model_name(subckt_card->li_line)); } else { - new_str = TMALLOC(char, strlen(subckt_card->li_line) + 5); - sprintf(new_str, "%s m=1", subckt_card->li_line); + new_str = tprintf("%s m=1", subckt_card->li_line); } tfree(subckt_card->li_line); @@ -2655,8 +2644,7 @@ inp_fix_subckt_multiplier(struct names *subckt_w_params, struct line *subckt_car /* no 'm' for model cards */ if (ciprefix(".model", card->li_line)) continue; - new_str = TMALLOC(char, strlen(card->li_line) + 7); - sprintf(new_str, "%s m={m}", card->li_line); + new_str = tprintf("%s m={m}", card->li_line); tfree(card->li_line); card->li_line = new_str; @@ -3048,8 +3036,7 @@ inp_do_macro_param_replace(struct function *fcn, char *params[]) if (curr_str == NULL) { curr_str = curr_ptr; } else { - new_str = TMALLOC(char, strlen(curr_str) + strlen(curr_ptr) + 1); - sprintf(new_str, "%s%s", curr_str, curr_ptr); + new_str = tprintf("%s%s", curr_str, curr_ptr); tfree(curr_str); curr_str = new_str; } @@ -3416,8 +3403,7 @@ inp_fix_param_values(struct line *c) wl_free(nwl); /* insert new vector into actual line */ *equal_ptr = '\0'; - new_str = TMALLOC(char, strlen(c->li_line) + strlen(newvec) + strlen(end_of_str + 1) + 5); - sprintf(new_str, "%s=[%s] %s", c->li_line, newvec, end_of_str+1); + new_str = tprintf("%s=[%s] %s", c->li_line, newvec, end_of_str+1); tfree(newvec); old_str = c->li_line; @@ -3459,8 +3445,7 @@ inp_fix_param_values(struct line *c) wl_free(nwl); /* insert new complex value into actual line */ *equal_ptr = '\0'; - new_str = TMALLOC(char, strlen(c->li_line) + strlen(newvec) + strlen(end_of_str + 1) + 5); - sprintf(new_str, "%s=<%s> %s", c->li_line, newvec, end_of_str+1); + new_str = tprintf("%s=<%s> %s", c->li_line, newvec, end_of_str+1); tfree(newvec); old_str = c->li_line; @@ -3484,13 +3469,11 @@ inp_fix_param_values(struct line *c) *equal_ptr = '\0'; if (*end_of_str == '\0') { - new_str = TMALLOC(char, strlen(c->li_line) + strlen(beg_of_str) + 4); - sprintf(new_str, "%s={%s}", c->li_line, beg_of_str); + new_str = tprintf("%s={%s}", c->li_line, beg_of_str); } else { *end_of_str = '\0'; - new_str = TMALLOC(char, strlen(c->li_line) + strlen(beg_of_str) + strlen(end_of_str + 1) + 5); - sprintf(new_str, "%s={%s} %s", c->li_line, beg_of_str, end_of_str+1); + new_str = tprintf("%s={%s} %s", c->li_line, beg_of_str, end_of_str+1); } old_str = c->li_line; c->li_line = new_str; @@ -3878,11 +3861,9 @@ inp_sort_params(struct line *start_card, struct line *end_card, struct line *car } *str_ptr = '\0'; if (*end != '\0') { - new_str = TMALLOC(char, strlen(curr_line) + strlen(param_names[i]) + strlen(end) + 3); - sprintf(new_str, "%s{%s}%s", curr_line, param_names[i], end); + new_str = tprintf("%s{%s}%s", curr_line, param_names[i], end); } else { - new_str = TMALLOC(char, strlen(curr_line) + strlen(param_names[i]) + 3); - sprintf(new_str, "%s{%s}", curr_line, param_names[i]); + new_str = tprintf("%s{%s}", curr_line, param_names[i]); } str_ptr = new_str + strlen(curr_line) + strlen(param_names[i]); @@ -3953,16 +3934,14 @@ inp_add_params_to_subckt(struct names *subckt_w_params, struct line *subckt_card param_ptr = skip_ws(param_ptr); if (!strstr(subckt_line, "params:")) { - new_line = TMALLOC(char, strlen(subckt_line) + strlen("params: ") + strlen(param_ptr) + 2); - sprintf(new_line, "%s params: %s", subckt_line, param_ptr); + new_line = tprintf("%s params: %s", subckt_line, param_ptr); subckt_name = skip_non_ws(subckt_line); subckt_name = skip_ws(subckt_name); end_ptr = skip_non_ws(subckt_name); add_name(subckt_w_params, copy_substring(subckt_name, end_ptr)); } else { - new_line = TMALLOC(char, strlen(subckt_line) + strlen(param_ptr) + 2); - sprintf(new_line, "%s %s", subckt_line, param_ptr); + new_line = tprintf("%s %s", subckt_line, param_ptr); } tfree(subckt_line); @@ -4159,8 +4138,7 @@ inp_split_multi_param_lines(struct line *card, int line_num) } keep = *end_param; *end_param = '\0'; - new_line = TMALLOC(char, strlen(".param ") + strlen(beg_param) + 1); - sprintf(new_line, ".param %s", beg_param); + new_line = tprintf(".param %s", beg_param); array[counter++] = new_line; *end_param = keep; curr_line = end_param; @@ -4342,10 +4320,7 @@ inp_compat(struct line *card) node1 = gettok(&cut_line); node2 = gettok(&cut_line); // Exxx n1 n2 int1 0 1 - xlen = 2*strlen(title_tok) + strlen(node1) + strlen(node2) - + 20 - 4*2 + 1; - ckt_array[0] = TMALLOC(char, xlen); - sprintf(ckt_array[0], "%s %s %s %s_int1 0 1", + ckt_array[0] = tprintf("%s %s %s %s_int1 0 1", title_tok, node1, node2, title_tok); // get the expression str_ptr = gettok(&cut_line); /* ignore 'table' */ @@ -4411,11 +4386,7 @@ inp_compat(struct line *card) card->li_linenum_orig, card->li_line); controlled_exit(EXIT_BAD); } - xlen = 2*strlen(title_tok) + strlen(expression) + 14 + strlen(firstno) + - 2*strlen(secondno) + strlen(midline) + 14 + - strlen(lastlastno) + 50; - ckt_array[1] = TMALLOC(char, xlen); - sprintf(ckt_array[1], "b%s %s_int1 0 v = pwl(%s, %e, %s, %s, %s, %s, %e, %s)", + ckt_array[1] = tprintf("b%s %s_int1 0 v = pwl(%s, %e, %s, %s, %s, %s, %e, %s)", title_tok, title_tok, expression, fnumber-delta, secondno, firstno, secondno, midline, lnumber + delta, lastlastno); @@ -4465,16 +4436,10 @@ inp_compat(struct line *card) } // Exxx n1 n2 int1 0 1 - xlen = 2*strlen(title_tok) + strlen(node1) + strlen(node2) - + 20 - 4*2 + 1; - ckt_array[0] = TMALLOC(char, xlen); - sprintf(ckt_array[0], "%s %s %s %s_int1 0 1", + ckt_array[0] = tprintf("%s %s %s %s_int1 0 1", title_tok, node1, node2, title_tok); // BExxx int1 0 V = {equation} - xlen = 2*strlen(title_tok) + strlen(str_ptr) - + 20 - 3*2 + 1; - ckt_array[1] = TMALLOC(char, xlen); - sprintf(ckt_array[1], "b%s %s_int1 0 v = %s", + ckt_array[1] = tprintf("b%s %s_int1 0 v = %s", title_tok, title_tok, str_ptr); // insert new B source line immediately after current line @@ -4543,10 +4508,7 @@ inp_compat(struct line *card) } else m_token = copy("1"); - xlen = 2*strlen(title_tok) + strlen(node1) + strlen(node2) - + 20 - 4*2 + strlen(m_token); - ckt_array[0] = TMALLOC(char, xlen); - sprintf(ckt_array[0], "%s %s %s %s_int1 0 %s", + ckt_array[0] = tprintf("%s %s %s %s_int1 0 %s", title_tok, node1, node2, title_tok, m_token); // get the expression str_ptr = gettok(&cut_line); /* ignore 'table' */ @@ -4608,11 +4570,7 @@ inp_compat(struct line *card) controlled_exit(EXIT_BAD); } /* BGxxx int1 0 V = pwl (expression, x0-(x2-x0)/2, y0, x0, y0, x1, y1, x2, y2, x2+(x2-x0)/2, y2) */ - xlen = 2*strlen(title_tok) + strlen(expression) + 14 + strlen(firstno) + - 2*strlen(secondno) + strlen(midline) + 14 + - strlen(lastlastno) + 50; - ckt_array[1] = TMALLOC(char, xlen); - sprintf(ckt_array[1], "b%s %s_int1 0 v = pwl(%s, %e, %s, %s, %s, %s, %e, %s)", + ckt_array[1] = tprintf("b%s %s_int1 0 v = pwl(%s, %e, %s, %s, %s, %s, %e, %s)", title_tok, title_tok, expression, fnumber-delta, secondno, firstno, secondno, midline, lnumber + delta, lastlastno); @@ -4674,16 +4632,10 @@ inp_compat(struct line *card) // Gxxx n1 n2 int1 0 1 // or // Gxxx n1 n2 int1 0 m='expr' - xlen = 2*strlen(title_tok) + strlen(node1) + strlen(node2) - + 20 - 4*2 + strlen(m_token); - ckt_array[0] = TMALLOC(char, xlen); - sprintf(ckt_array[0], "%s %s %s %s_int1 0 %s", + ckt_array[0] = tprintf("%s %s %s %s_int1 0 %s", title_tok, node1, node2, title_tok, m_token); // BGxxx int1 0 V = {equation} - xlen = 2*strlen(title_tok) + strlen(str_ptr) - + 20 - 3*2 + 1; - ckt_array[1] = TMALLOC(char, xlen); - sprintf(ckt_array[1], "b%s %s_int1 0 v = %s", + ckt_array[1] = tprintf("b%s %s_int1 0 v = %s", title_tok, title_tok, str_ptr); // insert new B source line immediately after current line @@ -4748,22 +4700,14 @@ inp_compat(struct line *card) bFxxx int1 0 i = i(vnam)*{equation} vbFxxx int1 0 0 */ - xlen = 2*strlen(title_tok) + strlen(node1) + strlen(node2) + 9; - ckt_array[0] = TMALLOC(char, xlen); //Fxxx n1 n2 VBFxxx -1 - sprintf(ckt_array[0], "%s %s %s vb%s -1", + ckt_array[0] = tprintf("%s %s %s vb%s -1", title_tok, node1, node2, title_tok); //BFxxx BFxxx_int1 0 I = I(vnam)*{equation} - xlen = 2*strlen(title_tok) + strlen(vnamstr) + strlen(equastr) - + 23; - ckt_array[1] = TMALLOC(char, xlen); - sprintf(ckt_array[1], "b%s %s_int1 0 i = i(%s) * (%s)", + ckt_array[1] = tprintf("b%s %s_int1 0 i = i(%s) * (%s)", title_tok, title_tok, vnamstr, equastr); //VBFxxx int1 0 0 - xlen = 2*strlen(title_tok) - + 16; - ckt_array[2] = TMALLOC(char, xlen); - sprintf(ckt_array[2], "vb%s %s_int1 0 dc 0", + ckt_array[2] = tprintf("vb%s %s_int1 0 dc 0", title_tok, title_tok); // insert new three lines immediately after current line for (i = 0; i < 3; i++) { @@ -4828,22 +4772,14 @@ inp_compat(struct line *card) bHxxx int1 0 i = i(vnam)*{equation} vbHxxx int1 0 0 */ - xlen = 2*strlen(title_tok) + strlen(node1) + strlen(node2) + 9; - ckt_array[0] = TMALLOC(char, xlen); //Hxxx n1 n2 VBHxxx -1 - sprintf(ckt_array[0], "%s %s %s vb%s -1", + ckt_array[0] = tprintf("%s %s %s vb%s -1", title_tok, node1, node2, title_tok); //BHxxx BHxxx_int1 0 I = I(vnam)*{equation} - xlen = 2*strlen(title_tok) + strlen(vnamstr) + strlen(equastr) - + 23; - ckt_array[1] = TMALLOC(char, xlen); - sprintf(ckt_array[1], "b%s %s_int1 0 i = i(%s) * (%s)", + ckt_array[1] = tprintf("b%s %s_int1 0 i = i(%s) * (%s)", title_tok, title_tok, vnamstr, equastr); //VBHxxx int1 0 0 - xlen = 2*strlen(title_tok) - + 16; - ckt_array[2] = TMALLOC(char, xlen); - sprintf(ckt_array[2], "vb%s %s_int1 0 dc 0", + ckt_array[2] = tprintf("vb%s %s_int1 0 dc 0", title_tok, title_tok); // insert new three lines immediately after current line for (i = 0; i < 3; i++) { @@ -4924,25 +4860,13 @@ inp_compat(struct line *card) } } if ((tc1_ptr == NULL) && (tc2_ptr == NULL)) { - xlen = strlen(title_tok) + strlen(node1) + strlen(node2) + - strlen(node1) + strlen(node2) + strlen(equation) + - 28 - 6*2 + 1; - xline = TMALLOC(char, xlen); - sprintf(xline, "b%s %s %s i = v(%s, %s)/(%s)", title_tok, node1, node2, + xline = tprintf("b%s %s %s i = v(%s, %s)/(%s)", title_tok, node1, node2, node1, node2, equation); } else if (tc2_ptr == NULL) { - xlen = strlen(title_tok) + strlen(node1) + strlen(node2) + - strlen(node1) + strlen(node2) + strlen(equation) + - 28 - 6*2 + 1 + 21 + 13; - xline = TMALLOC(char, xlen); - sprintf(xline, "b%s %s %s i = v(%s, %s)/(%s) tc1=%15.8e reciproctc=1", title_tok, node1, node2, + xline = tprintf("b%s %s %s i = v(%s, %s)/(%s) tc1=%15.8e reciproctc=1", title_tok, node1, node2, node1, node2, equation, tc1); } else { - xlen = strlen(title_tok) + strlen(node1) + strlen(node2) + - strlen(node1) + strlen(node2) + strlen(equation) + - 28 - 6*2 + 1 + 21 + 21 + 13; - xline = TMALLOC(char, xlen); - sprintf(xline, "b%s %s %s i = v(%s, %s)/(%s) tc1=%15.8e tc2=%15.8e reciproctc=1", title_tok, node1, node2, + xline = tprintf("b%s %s %s i = v(%s, %s)/(%s) tc1=%15.8e tc2=%15.8e reciproctc=1", title_tok, node1, node2, node1, node2, equation, tc1, tc2); } tc1_ptr = NULL; @@ -5011,34 +4935,19 @@ inp_compat(struct line *card) } } // Exxx n-aux 0 n1 n2 1 - xlen = 2*strlen(title_tok) + strlen(node1) + strlen(node2) - + 21 - 4*2 + 1; - ckt_array[0] = TMALLOC(char, xlen); - sprintf(ckt_array[0], "e%s %s_int2 0 %s %s 1", + ckt_array[0] = tprintf("e%s %s_int2 0 %s %s 1", title_tok, title_tok, node1, node2); // Cxxx n-aux 0 1 - xlen = 2*strlen(title_tok) - + 15 - 2*2 + 1; - ckt_array[1] = TMALLOC(char, xlen); - sprintf(ckt_array[1], "c%s %s_int2 0 1", title_tok, title_tok); + ckt_array[1] = tprintf("c%s %s_int2 0 1", title_tok, title_tok); // Bxxx n2 n1 I = i(Exxx) * equation if ((tc1_ptr == NULL) && (tc2_ptr == NULL)) { - xlen = 2*strlen(title_tok) + strlen(node2) + strlen(node1) - + strlen(equation) + 27 - 2*5 + 1; - ckt_array[2] = TMALLOC(char, xlen); - sprintf(ckt_array[2], "b%s %s %s i = i(e%s) * (%s)", + ckt_array[2] = tprintf("b%s %s %s i = i(e%s) * (%s)", title_tok, node2, node1, title_tok, equation); } else if (tc2_ptr == NULL) { - xlen = 2*strlen(title_tok) + strlen(node2) + strlen(node1) - + strlen(equation) + 27 - 2*5 + 1 + 21 + 13; - ckt_array[2] = TMALLOC(char, xlen); - sprintf(ckt_array[2], "b%s %s %s i = i(e%s) * (%s) tc1=%15.8e reciproctc=1", + ckt_array[2] = tprintf("b%s %s %s i = i(e%s) * (%s) tc1=%15.8e reciproctc=1", title_tok, node2, node1, title_tok, equation, tc1); } else { - xlen = 2*strlen(title_tok) + strlen(node2) + strlen(node1) - + strlen(equation) + 27 - 2*5 + 1 + 21 + 21 + 13; - ckt_array[2] = TMALLOC(char, xlen); - sprintf(ckt_array[2], "b%s %s %s i = i(e%s) * (%s) tc1=%15.8e tc2=%15.8e reciproctc=1", + ckt_array[2] = tprintf("b%s %s %s i = i(e%s) * (%s) tc1=%15.8e tc2=%15.8e reciproctc=1", title_tok, node2, node1, title_tok, equation, tc1, tc2); } tc1_ptr = NULL; @@ -5120,34 +5029,19 @@ inp_compat(struct line *card) } } // Fxxx n-aux 0 Bxxx 1 - xlen = 3*strlen(title_tok) - + 20 - 3*2 + 1; - ckt_array[0] = TMALLOC(char, xlen); - sprintf(ckt_array[0], "f%s %s_int2 0 b%s -1", + ckt_array[0] = tprintf("f%s %s_int2 0 b%s -1", title_tok, title_tok, title_tok); // Lxxx n-aux 0 1 - xlen = 2*strlen(title_tok) - + 15 - 2*2 + 1; - ckt_array[1] = TMALLOC(char, xlen); - sprintf(ckt_array[1], "l%s %s_int2 0 1", title_tok, title_tok); + ckt_array[1] = tprintf("l%s %s_int2 0 1", title_tok, title_tok); // Bxxx n1 n2 V = v(n-aux) * equation if ((tc1_ptr == NULL) && (tc2_ptr == NULL)) { - xlen = 2*strlen(title_tok) + strlen(node2) + strlen(node1) - + strlen(equation) + 31 - 2*5 + 1; - ckt_array[2] = TMALLOC(char, xlen); - sprintf(ckt_array[2], "b%s %s %s v = v(%s_int2) * (%s)", + ckt_array[2] = tprintf("b%s %s %s v = v(%s_int2) * (%s)", title_tok, node1, node2, title_tok, equation); } else if (tc2_ptr == NULL) { - xlen = 2*strlen(title_tok) + strlen(node2) + strlen(node1) - + strlen(equation) + 31 - 2*5 + 1 + 21 + 13; - ckt_array[2] = TMALLOC(char, xlen); - sprintf(ckt_array[2], "b%s %s %s v = v(%s_int2) * (%s) tc1=%15.8e reciproctc=0", + ckt_array[2] = tprintf("b%s %s %s v = v(%s_int2) * (%s) tc1=%15.8e reciproctc=0", title_tok, node2, node1, title_tok, equation, tc1); } else { - xlen = 2*strlen(title_tok) + strlen(node2) + strlen(node1) - + strlen(equation) + 31 - 2*5 + 1 + 21 + 21 + 13; - ckt_array[2] = TMALLOC(char, xlen); - sprintf(ckt_array[2], "b%s %s %s v = v(%s_int2) * (%s) tc1=%15.8e tc2=%15.8e reciproctc=0", + ckt_array[2] = tprintf("b%s %s %s v = v(%s_int2) * (%s) tc1=%15.8e tc2=%15.8e reciproctc=0", title_tok, node2, node1, title_tok, equation, tc1, tc2); } tc1_ptr = NULL; @@ -5251,18 +5145,13 @@ inp_compat(struct line *card) exp_ptr = copy_substring(beg_ptr, end_ptr-2); cut_line = str_ptr; // generate node - out_ptr = TMALLOC(char, 6); - sprintf(out_ptr, "pa_%02d", (int)pai); + out_ptr = tprintf("pa_%02d", (int)pai); // Bout_ptr out_ptr 0 V = v(expr_ptr) - xlen = 2*strlen(out_ptr) + strlen(exp_ptr)+ 15 - 2*3 + 1; - ckt_array[pai] = TMALLOC(char, xlen); - sprintf(ckt_array[pai], "b%s %s 0 v = %s", + ckt_array[pai] = tprintf("b%s %s 0 v = %s", out_ptr, out_ptr, exp_ptr); ckt_array[++pai] = NULL; // length of the replacement V(out_ptr) - xlen = strlen(out_ptr) + 4; - del_ptr = copy_ptr = TMALLOC(char, xlen); - sprintf(copy_ptr, "v(%s)", out_ptr); + del_ptr = copy_ptr = tprintf("v(%s)", out_ptr); // length of the replacement part in original line xlen = strlen(exp_ptr) + 7; // copy the replacement without trailing '\0' @@ -5284,18 +5173,13 @@ inp_compat(struct line *card) end_ptr++; exp_ptr = copy_substring(beg_ptr, end_ptr-3); // generate node - out_ptr = TMALLOC(char, 6); - sprintf(out_ptr, "pa_%02d", (int)pai); + out_ptr = tprintf("pa_%02d", (int)pai); // Bout_ptr out_ptr 0 V = v(expr_ptr) - xlen = 2*strlen(out_ptr) + strlen(exp_ptr)+ 15 - 2*3 + 1; - ckt_array[pai] = TMALLOC(char, xlen); - sprintf(ckt_array[pai], "b%s %s 0 v = %s", + ckt_array[pai] = tprintf("b%s %s 0 v = %s", out_ptr, out_ptr, exp_ptr); ckt_array[++pai] = NULL; // length of the replacement V(out_ptr) - xlen = strlen(out_ptr) + 4; - del_ptr = copy_ptr = TMALLOC(char, xlen); - sprintf(copy_ptr, "v(%s)", out_ptr); + del_ptr = copy_ptr = tprintf("v(%s)", out_ptr); // length of the replacement part in original line xlen = strlen(exp_ptr) + 9; // skip '=' @@ -5367,18 +5251,13 @@ inp_compat(struct line *card) exp_ptr = copy_substring(beg_ptr, end_ptr-2); cut_line = str_ptr; // generate node - out_ptr = TMALLOC(char, 6); - sprintf(out_ptr, "pa_%02d", (int)pai); + out_ptr = tprintf("pa_%02d", (int)pai); // Bout_ptr out_ptr 0 V = v(expr_ptr) - xlen = 2*strlen(out_ptr) + strlen(exp_ptr)+ 15 - 2*3 + 1; - ckt_array[pai] = TMALLOC(char, xlen); - sprintf(ckt_array[pai], "b%s %s 0 v = %s", + ckt_array[pai] = tprintf("b%s %s 0 v = %s", out_ptr, out_ptr, exp_ptr); ckt_array[++pai] = NULL; // length of the replacement V(out_ptr) - xlen = strlen(out_ptr) + 1; - del_ptr = copy_ptr = TMALLOC(char, xlen); - sprintf(copy_ptr, "%s", out_ptr); + del_ptr = copy_ptr = tprintf("%s", out_ptr); // length of the replacement part in original line xlen = strlen(exp_ptr) + 7; // copy the replacement without trailing '\0' @@ -5407,15 +5286,11 @@ inp_compat(struct line *card) end_ptr++; exp_ptr = copy_substring(beg_ptr, end_ptr-3); // Bout_ptr out_ptr 0 V = v(expr_ptr) - xlen = 2*strlen(out_ptr) + strlen(exp_ptr)+ 15 - 2*3 + 1; - ckt_array[pai] = TMALLOC(char, xlen); - sprintf(ckt_array[pai], "b%s %s 0 v = %s", + ckt_array[pai] = tprintf("b%s %s 0 v = %s", out_ptr, out_ptr, exp_ptr); ckt_array[++pai] = NULL; // length of the replacement V(out_ptr) - xlen = strlen(out_ptr) + 1; - del_ptr = copy_ptr = TMALLOC(char, xlen); - sprintf(copy_ptr, "%s", out_ptr); + del_ptr = copy_ptr = tprintf("%s", out_ptr); // length of the replacement part in original line xlen = strlen(out_ptr) + strlen(exp_ptr) + 10; // copy the replacement without trailing '\0' @@ -5517,7 +5392,7 @@ inp_bsource_compat(struct line *card) struct line *new_line; wordlist *wl = NULL, *wlist = NULL; char buf[512]; - size_t i, xlen, ustate = 0; + size_t i, ustate = 0; int skip_control = 0; int error1; @@ -5712,18 +5587,12 @@ inp_bsource_compat(struct line *card) str_ptr++; wl->wl_word = copy(buf); } else { - xlen = strlen(buf); - tmp_char = TMALLOC(char, xlen + 3); - sprintf(tmp_char, "{%s}", buf); - wl->wl_word = tmp_char; + wl->wl_word = tprintf("{%s}", buf); } } else { /* {} around all other tokens */ - xlen = strlen(buf); - tmp_char = TMALLOC(char, xlen + 3); - sprintf(tmp_char, "{%s}", buf); - wl->wl_word = tmp_char; + wl->wl_word = tprintf("{%s}", buf); } } ustate = 0; /* we have a number */ @@ -5762,9 +5631,7 @@ inp_bsource_compat(struct line *card) } /* cut the tmp_char after the equal sign */ equal_ptr[1] = '\0'; - xlen = strlen(tmp_char) + strlen(new_str) + 2; - final_str = TMALLOC(char, xlen); - sprintf(final_str, "%s %s", tmp_char, new_str); + final_str = tprintf("%s %s", tmp_char, new_str); /* Copy old line numbers into new B source line */ new_line = xx_new_line(card->li_next, final_str, card->li_linenum, card->li_linenum_orig); @@ -5884,11 +5751,11 @@ inp_temper_compat(struct line *card) static char * inp_modify_exp(char* expr) { - char * str_ptr, *tmp_char, *new_str; + char * str_ptr, *new_str; char actchar; wordlist *wl = NULL, *wlist = NULL; char buf[512]; - size_t i, xlen, ustate = 0; + size_t i, ustate = 0; int error1; /* scan the expression and remove all '{' and '}' */ @@ -5998,18 +5865,12 @@ inp_modify_exp(char* expr) str_ptr++; wl->wl_word = copy(buf); } else { - xlen = strlen(buf); - tmp_char = TMALLOC(char, xlen + 3); - sprintf(tmp_char, "{%s}", buf); - wl->wl_word = tmp_char; + wl->wl_word = tprintf("{%s}", buf); } } else { /* {} around all other tokens */ - xlen = strlen(buf); - tmp_char = TMALLOC(char, xlen + 3); - sprintf(tmp_char, "{%s}", buf); - wl->wl_word = tmp_char; + wl->wl_word = tprintf("{%s}", buf); } } ustate = 0; /* we have a number */ @@ -6103,7 +5964,7 @@ get_quoted_token(char *string, char **token) static void inp_add_series_resistor(struct line *deck) { - size_t skip_control = 0, xlen, i; + size_t skip_control = 0, i; bool has_rseries = FALSE; struct line *card; char *tmp_p, *title_tok, *node1, *node2, *rval = NULL; @@ -6156,14 +6017,10 @@ inp_add_series_resistor(struct line *deck) node1 = gettok(&cut_line); node2 = gettok(&cut_line); /* new L line */ - xlen = strlen(curr_line) + 10; - ckt_array[0] = TMALLOC(char, xlen); - sprintf(ckt_array[0], "%s %s %s_intern__ %s", + ckt_array[0] = tprintf("%s %s %s_intern__ %s", title_tok, node1, node2, cut_line); /* new R line */ - xlen = strlen(curr_line) + 19; - ckt_array[1] = TMALLOC(char, xlen); - sprintf(ckt_array[1], "R%s_intern__ %s_intern__ %s %s", + ckt_array[1] = tprintf("R%s_intern__ %s_intern__ %s %s", title_tok, node2, node2, rval); /* assemble new L and R lines */ for (i = 0; i < 2; i++) { @@ -6605,8 +6462,7 @@ inp_new_func(char *funcname, char *funcbody, struct line *card, struct func_temp } /* replace line in deck */ - new_str = TMALLOC(char, strlen(funcname) + strlen(funcbody) + 10); - sprintf(new_str, ".func %s() %s", funcname, funcbody); + new_str = tprintf(".func %s() %s", funcname, funcbody); card->li_next = xx_new_line(card->li_next, new_str, 0, card->li_linenum); *card->li_line = '*'; } diff --git a/src/frontend/options.c b/src/frontend/options.c index 3dfc57262..1110f8268 100644 --- a/src/frontend/options.c +++ b/src/frontend/options.c @@ -207,11 +207,10 @@ inp_getoptsc(char *in_line, struct line *com_options) struct line *next = NULL; char *line; - line = TMALLOC(char, strlen(in_line) + 3); /* option -> .options */ /* skip option */ gettok(&in_line); - sprintf(line, ".options %s", in_line); + line = tprintf(".options %s", in_line); next = TMALLOC(struct line, 1); next->li_line = line; diff --git a/src/frontend/plotting/graf.c b/src/frontend/plotting/graf.c index 8c198ae84..bab14a351 100644 --- a/src/frontend/plotting/graf.c +++ b/src/frontend/plotting/graf.c @@ -135,8 +135,7 @@ gr_init(double *xlims, double *ylims, /* The size of the screen. */ if (!plotname) plotname = "(unknown)"; - comb_title = TMALLOC(char, strlen(plotname) + strlen(pname) + 3); - sprintf(comb_title, "%s: %s", pname, plotname); + comb_title = tprintf("%s: %s", pname, plotname); graph->plotname = comb_title; /* note: have enum here or some better convention */ diff --git a/src/frontend/subckt.c b/src/frontend/subckt.c index 86b47280d..3ba33eb8f 100644 --- a/src/frontend/subckt.c +++ b/src/frontend/subckt.c @@ -938,11 +938,9 @@ translate(struct line *deck, char *formal, char *actual, char *scname, char *sub t = gettrans(name, NULL); if (t) { - new_str = TMALLOC(char, strlen(s) + strlen(t) + strlen(paren_ptr + 1) + 3); - sprintf(new_str, "%s(%s)%s", s, t, paren_ptr+1); + new_str = tprintf("%s(%s)%s", s, t, paren_ptr+1); } else { - new_str = TMALLOC(char, strlen(s) + strlen(scname) + strlen(name) + strlen(paren_ptr + 1) + 4); - sprintf(new_str, "%s(%s.%s)%s", s, scname, name, paren_ptr+1); + new_str = tprintf("%s(%s.%s)%s", s, scname, name, paren_ptr+1); } paren_ptr = new_str + strlen(s) + 1; diff --git a/src/main.c b/src/main.c index b460301dd..0e1cbb455 100644 --- a/src/main.c +++ b/src/main.c @@ -746,9 +746,8 @@ read_initialisation_file(char *dir, char *name) asprintf(&path, "%s" DIR_PATHSEP "%s", dir, name); if(path==NULL) return FALSE; /* memory allocation error */ #else /* ~ HAVE_ASPRINTF */ - path = TMALLOC(char, 2 + strlen(dir) + strlen(name)); + path = tprintf("%s" DIR_PATHSEP "%s", dir, name); if(path==NULL) return FALSE; /* memory allocation error */ - sprintf(path, "%s" DIR_PATHSEP "%s", dir, name); #endif /* HAVE_ASPRINTF */ } @@ -1232,9 +1231,7 @@ main(int argc, char **argv) if (!tp) { char *lbuffer = getenv("NGSPICE_INPUT_DIR"); if (lbuffer && *lbuffer) { - char *p = - TMALLOC(char, strlen(lbuffer) + strlen(DIR_PATHSEP) + strlen(arg) + 1); - sprintf(p, "%s%s%s", lbuffer, DIR_PATHSEP, arg); + char *p = tprintf("%s%s%s", lbuffer, DIR_PATHSEP, arg); tp = fopen(p, "r"); tfree(p); } diff --git a/src/misc/ivars.c b/src/misc/ivars.c index 43cfc26d9..ae6ac6239 100644 --- a/src/misc/ivars.c +++ b/src/misc/ivars.c @@ -46,13 +46,11 @@ mkvar(char **p, char *path_prefix, char *var_dir, char *env_var) asprintf(p, "%s%s%s", path_prefix, DIR_PATHSEP, var_dir); #else /* ~ HAVE_ASPRINTF */ if (buffer){ - *p = TMALLOC(char, strlen(buffer) + 1); - sprintf(*p,"%s",buffer); + *p = tprintf("%s",buffer); /* asprintf(p, "%s", buffer); */ } else{ - *p = TMALLOC(char, strlen(path_prefix) + strlen(DIR_PATHSEP) + strlen(var_dir) + 1); - sprintf(*p, "%s%s%s", path_prefix, DIR_PATHSEP, var_dir); + *p = tprintf("%s%s%s", path_prefix, DIR_PATHSEP, var_dir); /* asprintf(p, "%s%s%s", path_prefix, DIR_PATHSEP, var_dir); */ } #endif /* HAVE_ASPRINTF */ diff --git a/src/sharedspice.c b/src/sharedspice.c index 67e406c7f..f93008feb 100644 --- a/src/sharedspice.c +++ b/src/sharedspice.c @@ -620,8 +620,7 @@ ngSpice_Init(SendChar* printfcn, SendStat* statusfcn, ControlledExit* ngspiceexi struct passwd *pw; pw = getpwuid(getuid()); - s = TMALLOC(char, 1 + strlen(pw->pw_dir) + strlen(INITSTR)); - sprintf(s, "%s%s", pw->pw_dir, INITSTR); + s = tprintf("%s%s", pw->pw_dir, INITSTR); if (access(s, 0) == 0) inp_source(s); @@ -1109,9 +1108,7 @@ sh_fputsll(const char *input, FILE* outf) newstring = gettok_char(&outstringerr, '\n', FALSE, FALSE); if(!newstring) break; - prstring = TMALLOC(char, 7 + strlen(newstring) + 1); - strcat(prstring, "stderr "); - strcat(prstring, newstring); + prstring = tprintf("stderr %s", newstring); result = pfcn(prstring, ng_ident, userptr); tfree(newstring); @@ -1144,9 +1141,7 @@ sh_fputsll(const char *input, FILE* outf) newstring = gettok_char(&outstringout, '\n', FALSE, FALSE); if(!newstring) break; - prstring = TMALLOC(char, 7 + strlen(newstring) + 1); - strcat(prstring, "stdout "); - strcat(prstring, newstring); + prstring = tprintf("stdout %s", newstring); result = pfcn(prstring, ng_ident, userptr); tfree(newstring); tfree(prstring); @@ -1219,9 +1214,7 @@ sh_fputs(const char *input, FILE* outf) newstring = gettok_char(&outstringerr, '\n', FALSE, FALSE); if(!newstring) break; - prstring = TMALLOC(char, 7 + strlen(newstring) + 1); - strcat(prstring, "stderr "); - strcat(prstring, newstring); + prstring = tprintf("stderr %s", newstring); mutex_lock(&fputsMutex); outstorage(prstring, TRUE); mutex_unlock(&fputsMutex); @@ -1257,9 +1250,7 @@ sh_fputs(const char *input, FILE* outf) newstring = gettok_char(&outstringout, '\n', FALSE, FALSE); if(!newstring) break; - prstring = TMALLOC(char, 7 + strlen(newstring) + 1); - strcat(prstring, "stdout "); - strcat(prstring, newstring); + prstring = tprintf("stdout %s", newstring); mutex_lock(&fputsMutex); outstorage(prstring, TRUE); mutex_unlock(&fputsMutex); diff --git a/src/spicelib/analysis/tfanal.c b/src/spicelib/analysis/tfanal.c index 25b2d4d67..548972827 100644 --- a/src/spicelib/analysis/tfanal.c +++ b/src/spicelib/analysis/tfanal.c @@ -97,9 +97,7 @@ TFanal(CKTcircuit *ckt, int restart) if (job->TFoutIsI) { SPfrontEnd->IFnewUid (ckt, &outuid, job->TFoutSrc ,"Output_impedance", UID_OTHER, NULL); } else { - name = TMALLOC(char, strlen(job->TFoutName) + 22); - (void)sprintf(name,"output_impedance_at_%s", - job->TFoutName); + name = tprintf("output_impedance_at_%s", job->TFoutName); SPfrontEnd->IFnewUid (ckt, &outuid, NULL, name, UID_OTHER, NULL); } diff --git a/src/spicelib/devices/nbjt/nbjtset.c b/src/spicelib/devices/nbjt/nbjtset.c index ab17c84bc..45b86db0b 100644 --- a/src/spicelib/devices/nbjt/nbjtset.c +++ b/src/spicelib/devices/nbjt/nbjtset.c @@ -34,8 +34,6 @@ NBJTsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states) MODLcard *models; OPTNcard *options; OUTPcard *outputs; - char *icFileName = NULL; - size_t nameLen; int error; int xMeshSize; ONEdevice *pDevice; @@ -160,16 +158,9 @@ NBJTsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states) } if (!inst->NBJTicFileGiven) { if (options->OPTNunique) { - nameLen = strlen(options->OPTNicFile) + strlen(inst->NBJTname) + 1; - TSCALLOC(icFileName, nameLen+1, char); - sprintf(icFileName, "%s.%s", options->OPTNicFile, inst->NBJTname); - icFileName[nameLen] = '\0'; - inst->NBJTicFile = icFileName; + inst->NBJTicFile = tprintf("%s.%s", options->OPTNicFile, inst->NBJTname); } else if (options->OPTNicFile != NULL) { - nameLen = strlen(options->OPTNicFile); - TSCALLOC(icFileName, nameLen+1, char); - icFileName = strcpy(icFileName, options->OPTNicFile); - inst->NBJTicFile = icFileName; + inst->NBJTicFile = tprintf("%s", options->OPTNicFile); } else { inst->NBJTicFile = NULL; } diff --git a/src/spicelib/devices/nbjt2/nbt2set.c b/src/spicelib/devices/nbjt2/nbt2set.c index 882c05a61..d52667ea6 100644 --- a/src/spicelib/devices/nbjt2/nbt2set.c +++ b/src/spicelib/devices/nbjt2/nbt2set.c @@ -35,8 +35,6 @@ NBJT2setup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states) MODLcard *models; OPTNcard *options; OUTPcard *outputs; - char *icFileName = NULL; - size_t nameLen; int error, xIndex; int xMeshSize, yMeshSize; TWOdevice *pDevice; @@ -176,16 +174,9 @@ NBJT2setup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states) } if (!inst->NBJT2icFileGiven) { if (options->OPTNunique) { - nameLen = strlen(options->OPTNicFile) + strlen(inst->NBJT2name) + 1; - TSCALLOC(icFileName, nameLen+1, char); - sprintf(icFileName, "%s.%s", options->OPTNicFile, inst->NBJT2name); - icFileName[nameLen] = '\0'; - inst->NBJT2icFile = icFileName; + inst->NBJT2icFile = tprintf("%s.%s", options->OPTNicFile, inst->NBJT2name); } else if (options->OPTNicFile != NULL) { - nameLen = strlen(options->OPTNicFile); - TSCALLOC(icFileName, nameLen+1, char); - icFileName = strcpy(icFileName, options->OPTNicFile); - inst->NBJT2icFile = icFileName; + inst->NBJT2icFile = tprintf("%s", options->OPTNicFile); } else { inst->NBJT2icFile = NULL; } diff --git a/src/spicelib/devices/numd/numdset.c b/src/spicelib/devices/numd/numdset.c index 86f16ccc0..ed5b42314 100644 --- a/src/spicelib/devices/numd/numdset.c +++ b/src/spicelib/devices/numd/numdset.c @@ -35,8 +35,6 @@ NUMDsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states) MODLcard *models; OPTNcard *options; OUTPcard *outputs; - char *icFileName = NULL; - size_t nameLen; int error; int xMeshSize; ONEdevice *pDevice; @@ -155,16 +153,9 @@ NUMDsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states) } if ((!inst->NUMDicFileGiven)) { if (options->OPTNunique) { - nameLen = strlen(options->OPTNicFile) + strlen(inst->NUMDname) + 1; - TSCALLOC(icFileName, nameLen+1, char); - sprintf(icFileName, "%s.%s", options->OPTNicFile, inst->NUMDname); - icFileName[nameLen] = '\0'; - inst->NUMDicFile = icFileName; + inst->NUMDicFile = tprintf("%s.%s", options->OPTNicFile, inst->NUMDname); } else if (options->OPTNicFile != NULL) { - nameLen = strlen(options->OPTNicFile); - TSCALLOC(icFileName, nameLen+1, char); - icFileName = strcpy(icFileName, options->OPTNicFile); - inst->NUMDicFile = icFileName; + inst->NUMDicFile = tprintf("%s", options->OPTNicFile); } else { inst->NUMDicFile = NULL; } diff --git a/src/spicelib/devices/numd2/nud2set.c b/src/spicelib/devices/numd2/nud2set.c index ae200715d..c1074cac0 100644 --- a/src/spicelib/devices/numd2/nud2set.c +++ b/src/spicelib/devices/numd2/nud2set.c @@ -35,8 +35,6 @@ NUMD2setup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states) MODLcard *models; OPTNcard *options; OUTPcard *outputs; - char *icFileName = NULL; - size_t nameLen; int error, xIndex; int xMeshSize, yMeshSize; TWOdevice *pDevice; @@ -175,16 +173,9 @@ NUMD2setup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states) } if (!inst->NUMD2icFileGiven) { if (options->OPTNunique) { - nameLen = strlen(options->OPTNicFile) + strlen(inst->NUMD2name) + 1; - TSCALLOC(icFileName, nameLen+1, char); - sprintf(icFileName, "%s.%s", options->OPTNicFile, inst->NUMD2name); - icFileName[nameLen] = '\0'; - inst->NUMD2icFile = icFileName; + inst->NUMD2icFile = tprintf("%s.%s", options->OPTNicFile, inst->NUMD2name); } else if (options->OPTNicFile != NULL) { - nameLen = strlen(options->OPTNicFile); - TSCALLOC(icFileName, nameLen+1, char); - icFileName = strcpy(icFileName, options->OPTNicFile); - inst->NUMD2icFile = icFileName; + inst->NUMD2icFile = tprintf("%s", options->OPTNicFile); } else { inst->NUMD2icFile = NULL; } diff --git a/src/spicelib/devices/numos/nummset.c b/src/spicelib/devices/numos/nummset.c index 8ad6944d7..046e8be8b 100644 --- a/src/spicelib/devices/numos/nummset.c +++ b/src/spicelib/devices/numos/nummset.c @@ -35,8 +35,6 @@ NUMOSsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states) MODLcard *models; OPTNcard *options; OUTPcard *outputs; - char *icFileName = NULL; - size_t nameLen; int error, xIndex; int xMeshSize, yMeshSize; TWOdevice *pDevice; @@ -174,16 +172,9 @@ NUMOSsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states) } if (!inst->NUMOSicFileGiven) { if (options->OPTNunique) { - nameLen = strlen(options->OPTNicFile) + strlen(inst->NUMOSname) + 1; - TSCALLOC(icFileName, nameLen+1, char); - sprintf(icFileName, "%s.%s", options->OPTNicFile, inst->NUMOSname); - icFileName[nameLen] = '\0'; - inst->NUMOSicFile = icFileName; + inst->NUMOSicFile = tprintf("%s.%s", options->OPTNicFile, inst->NUMOSname); } else if (options->OPTNicFile != NULL) { - nameLen = strlen(options->OPTNicFile); - TSCALLOC(icFileName, nameLen+1, char); - icFileName = strcpy(icFileName, options->OPTNicFile); - inst->NUMOSicFile = icFileName; + inst->NUMOSicFile = tprintf("%s", options->OPTNicFile); } else { inst->NUMOSicFile = NULL; } diff --git a/src/spicelib/devices/res/resask.c b/src/spicelib/devices/res/resask.c index aacb5f66d..5c00d9a28 100644 --- a/src/spicelib/devices/res/resask.c +++ b/src/spicelib/devices/res/resask.c @@ -149,11 +149,8 @@ RESask(CKTcircuit *ckt, GENinstance *inst, int which, IFvalue *value, value->rValue *= fast->RESm; return(OK); } else { - char msgloc[BSIZE_SP]; - sprintf(msgloc, "No current values available for %s", fast->RESname); - errMsg = TMALLOC(char, strlen(msgloc) + 1); + errMsg = tprintf("No current values available for %s", fast->RESname); errRtn = "RESask"; - strcpy(errMsg, msgloc); return(E_ASKCURRENT); } case RES_POWER: @@ -171,11 +168,8 @@ RESask(CKTcircuit *ckt, GENinstance *inst, int which, IFvalue *value, value->rValue *= fast->RESm; return(OK); } else { - char msgloc[BSIZE_SP]; - sprintf(msgloc, "No power values available for %s", fast->RESname); - errMsg = TMALLOC(char, strlen(msgloc) + 1); + errMsg = tprintf("No power values available for %s", fast->RESname); errRtn = "RESask"; - strcpy(errMsg, msgloc); return(E_ASKCURRENT); } diff --git a/src/spicelib/devices/urc/urcsetup.c b/src/spicelib/devices/urc/urcsetup.c index 36cc967ac..2df4ef01f 100644 --- a/src/spicelib/devices/urc/urcsetup.c +++ b/src/spicelib/devices/urc/urcsetup.c @@ -130,16 +130,14 @@ URCsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *state) lowl = CKTnum2nod(ckt,here->URCposNode); hir = CKTnum2nod(ckt,here->URCnegNode); for(i=1;i<=here->URClumps;i++) { - namehi = TMALLOC(char, 10); - (void)sprintf(namehi,"hi%d",i); + namehi = tprintf("hi%d", i); error = CKTmkVolt(ckt, &nodehi, here->URCname, namehi); if(error) return(error); hil = nodehi; if(i==here->URClumps) { lowr = hil; } else { - namelo = TMALLOC(char, 10); - (void)sprintf(namelo,"lo%d",i); + namelo = tprintf("lo%d", i); error = CKTmkVolt(ckt, &nodelo, here->URCname, namelo); if(error) return(error); @@ -148,8 +146,7 @@ URCsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *state) r = prop*r1; c = prop*c1; - nameelt = TMALLOC(char, 10); - (void)sprintf(nameelt,"rlo%d",i); + nameelt = tprintf("rlo%d", i); error = SPfrontEnd->IFnewUid (ckt, &eltUid, here->URCname, nameelt, UID_INSTANCE, NULL); if(error) return(error); @@ -164,8 +161,7 @@ URCsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *state) error = CKTpName("resistance",&ptemp,ckt,rtype,nameelt,&fast); if(error) return(error); - nameelt = TMALLOC(char, 10); - (void)sprintf(nameelt,"rhi%d",i); + nameelt = tprintf("rhi%d", i); error = SPfrontEnd->IFnewUid (ckt, &eltUid, here->URCname, nameelt, UID_INSTANCE, NULL); if(error) return(error); @@ -182,8 +178,7 @@ URCsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *state) if(model->URCisPerLGiven) { /* use diode */ - nameelt = TMALLOC(char, 10); - (void)sprintf(nameelt,"dlo%d",i); + nameelt = tprintf("dlo%d", i); error = SPfrontEnd->IFnewUid (ckt, &eltUid, here->URCname,nameelt,UID_INSTANCE, NULL); @@ -201,8 +196,7 @@ URCsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *state) if(error) return(error); } else { /* use simple capacitor */ - nameelt = TMALLOC(char, 10); - (void)sprintf(nameelt,"clo%d",i); + nameelt = tprintf("clo%d", i); error = SPfrontEnd->IFnewUid (ckt, &eltUid, here->URCname ,nameelt, UID_INSTANCE, NULL); if(error) return(error); @@ -223,8 +217,7 @@ URCsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *state) if(i!=here->URClumps){ if(model->URCisPerLGiven) { /* use diode */ - nameelt = TMALLOC(char, 10); - (void)sprintf(nameelt,"dhi%d",i); + nameelt = tprintf("dhi%d", i); error = SPfrontEnd->IFnewUid (ckt, &eltUid, here->URCname,nameelt,UID_INSTANCE, NULL); @@ -242,8 +235,7 @@ URCsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *state) if(error) return(error); } else { /* use simple capacitor */ - nameelt = TMALLOC(char, 10); - (void)sprintf(nameelt,"chi%d",i); + nameelt = tprintf("chi%d", i); error = SPfrontEnd->IFnewUid (ckt, &eltUid, here->URCname,nameelt,UID_INSTANCE, NULL); diff --git a/src/spicelib/parser/ifnewuid.c b/src/spicelib/parser/ifnewuid.c index cad6a5a5c..5b874e136 100644 --- a/src/spicelib/parser/ifnewuid.c +++ b/src/spicelib/parser/ifnewuid.c @@ -39,8 +39,7 @@ IFnewUid(CKTcircuit *ckt, IFuid * newuid, IFuid olduid, char *suffix, int type, #ifdef HAVE_ASPRINTF asprintf(&newname, "%s#%s", olduid, suffix); #else /* ~ HAVE_ASPRINTF */ - newname = TMALLOC(char, strlen(olduid) + strlen(suffix) + 2); /* 2 = strlen("#\0") */ - sprintf(newname, "%s#%s", olduid, suffix); + newname = tprintf("%s#%s", olduid, suffix); #endif /* HAVE_ASPRINTF */ } else { @@ -48,8 +47,7 @@ IFnewUid(CKTcircuit *ckt, IFuid * newuid, IFuid olduid, char *suffix, int type, #ifdef HAVE_ASPRINTF asprintf(&newname, "%s", suffix); #else /* ~ HAVE_ASPRINTF */ - newname = TMALLOC(char, strlen(suffix) + 1); - sprintf(newname, "%s", suffix); + newname = tprintf("%s", suffix); #endif /* HAVE_ASPRINTF */ } diff --git a/src/spicelib/parser/inp2dot.c b/src/spicelib/parser/inp2dot.c index e0d1b1a41..6c946cd7e 100644 --- a/src/spicelib/parser/inp2dot.c +++ b/src/spicelib/parser/inp2dot.c @@ -322,16 +322,12 @@ dot_tf(char *line, CKTcircuit *ckt, INPtables *tab, card *current, INPtermInsert(ckt, &nname2, tab, &node2); ptemp.nValue = node2; GCA(INPapName, (ckt, which, foo, "outneg", &ptemp)); - ptemp.sValue = - TMALLOC(char, 5 + strlen(nname1) + strlen(nname2)); - (void) sprintf(ptemp.sValue, "V(%s,%s)", nname1, nname2); + ptemp.sValue = tprintf("V(%s,%s)", nname1, nname2); GCA(INPapName, (ckt, which, foo, "outname", &ptemp)); } else { ptemp.nValue = gnode; GCA(INPapName, (ckt, which, foo, "outneg", &ptemp)); - ptemp.sValue = - TMALLOC(char, 4 + strlen(nname1)); - (void) sprintf(ptemp.sValue, "V(%s)", nname1); + ptemp.sValue = tprintf("V(%s)", nname1); GCA(INPapName, (ckt, which, foo, "outname", &ptemp)); } } else if (*name == 'i' && strlen(name) == 1) { @@ -445,15 +441,12 @@ dot_sens(char *line, CKTcircuit *ckt, INPtables *tab, card *current, INPtermInsert(ckt, &nname2, tab, &node2); ptemp.nValue = node2; GCA(INPapName, (ckt, which, foo, "outneg", &ptemp)); - ptemp.sValue = TMALLOC(char, 5 + strlen(nname1) + strlen(nname2)); - (void) sprintf(ptemp.sValue, "V(%s,%s)", nname1, nname2); + ptemp.sValue = tprintf("V(%s,%s)", nname1, nname2); GCA(INPapName, (ckt, which, foo, "outname", &ptemp)); } else { ptemp.nValue = gnode; GCA(INPapName, (ckt, which, foo, "outneg", &ptemp)); - ptemp.sValue = - TMALLOC(char, 4 + strlen(nname1)); - (void) sprintf(ptemp.sValue, "V(%s)", nname1); + ptemp.sValue = tprintf("V(%s)", nname1); GCA(INPapName, (ckt, which, foo, "outname", &ptemp)); } } else if (*name == 'i' && strlen(name) == 1) { diff --git a/src/spicelib/parser/inp2q.c b/src/spicelib/parser/inp2q.c index a1b075d23..34b201240 100644 --- a/src/spicelib/parser/inp2q.c +++ b/src/spicelib/parser/inp2q.c @@ -155,8 +155,7 @@ void INP2Q(CKTcircuit *ckt, INPtables * tab, card * current, CKTnode *gnode) char *err; IFnewUid(ckt, &uid, NULL, "Q", UID_MODEL, NULL); IFC(newModel, (ckt, type, &(tab->defQmod), uid)); - err = TMALLOC(char, 70 + strlen(model)); - (void) sprintf(err, "Unable to find definition of model %s\n", model); + err = tprintf("Unable to find definition of model %s\n", model); LITERR(err); tfree(err); } diff --git a/src/spicelib/parser/inpdomod.c b/src/spicelib/parser/inpdomod.c index 317b7641d..7c79cc41b 100644 --- a/src/spicelib/parser/inpdomod.c +++ b/src/spicelib/parser/inpdomod.c @@ -292,8 +292,7 @@ char *INPdomodel(CKTcircuit *ckt, card * image, INPtables * tab) type = INPtypelook("BSIM3"); } if (type < 0) { - err = TMALLOC(char, 60 + strlen(ver)); - sprintf(err,"Device type BSIM3 version %s not available in this binary\n",ver); + err = tprintf("Device type BSIM3 version %s not available in this binary\n", ver); } break; case 9: @@ -318,8 +317,7 @@ char *INPdomodel(CKTcircuit *ckt, card * image, INPtables * tab) type = INPtypelook("BSIM4"); } if (type < 0) { - err = TMALLOC(char, 60 + strlen(ver)); - sprintf(err,"Device type BSIM4 version %s not available in this binary\n",ver); + err = tprintf("Device type BSIM4 version %s not available in this binary\n", ver); } break; case 15: @@ -622,8 +620,7 @@ char *INPdomodel(CKTcircuit *ckt, card * image, INPtables * tab) else { #ifndef XSPICE type = -1; - err = TMALLOC(char, 35 + strlen(type_name)); - (void) sprintf(err, "unknown model type %s - ignored\n", type_name); + err = tprintf("unknown model type %s - ignored\n", type_name); #else /* gtri - modify - wbk - 10/23/90 - modify to look for code models */ @@ -634,8 +631,7 @@ char *INPdomodel(CKTcircuit *ckt, card * image, INPtables * tab) /* look for this model type and put it in the table of models */ type = INPtypelook(type_name); if(type < 0) { - err = TMALLOC(char, 35 + strlen(type_name)); - sprintf(err,"Unknown model type %s - ignored\n",type_name); + err = tprintf("Unknown model type %s - ignored\n", type_name); #ifdef TRACE printf("In INPdomodel, ignoring unknown model typ typename = %s . . .\n", type_name); diff --git a/src/spicelib/parser/inpdoopt.c b/src/spicelib/parser/inpdoopt.c index 6dd048146..33d388e56 100644 --- a/src/spicelib/parser/inpdoopt.c +++ b/src/spicelib/parser/inpdoopt.c @@ -52,8 +52,7 @@ INPdoOpts( if_parm = ft_find_analysis_parm(which, token); if(if_parm && !(if_parm->dataType & IF_UNIMP_MASK)) { - errmsg = TMALLOC(char, 45 + strlen(token)); - (void) sprintf(errmsg, " Warning: %s not yet implemented - ignored \n",token); + errmsg = tprintf(" Warning: %s not yet implemented - ignored \n", token); optCard->error = INPerrCat(optCard->error,errmsg); val = INPgetValue(ckt,&line, if_parm->dataType, tab); continue; @@ -63,8 +62,7 @@ INPdoOpts( val = INPgetValue(ckt,&line, if_parm->dataType&IF_VARTYPES, tab); error = ft_sim->setAnalysisParm (ckt, anal, if_parm->id, val, NULL); if(error) { - errmsg = TMALLOC(char, 35 + strlen(token)); - (void) sprintf(errmsg, "Warning: can't set option %s\n", token); + errmsg = tprintf("Warning: can't set option %s\n", token); optCard->error = INPerrCat(optCard->error, errmsg); } continue; diff --git a/src/spicelib/parser/inpdpar.c b/src/spicelib/parser/inpdpar.c index fedf1a4ae..9f0e52850 100644 --- a/src/spicelib/parser/inpdpar.c +++ b/src/spicelib/parser/inpdpar.c @@ -86,8 +86,7 @@ char *INPdevParse(char **line, CKTcircuit *ckt, int dev, GENinstance *fast, } } if (i == *(ft_sim->devices[dev]->numInstanceParms)) { - errbuf = TMALLOC(char, strlen(parm) + 25); - (void) sprintf(errbuf, " unknown parameter (%s) \n", parm); + errbuf = tprintf(" unknown parameter (%s) \n", parm); rtn = errbuf; goto quit; } diff --git a/src/spicelib/parser/inperror.c b/src/spicelib/parser/inperror.c index 219114b1b..d6da34f40 100644 --- a/src/spicelib/parser/inperror.c +++ b/src/spicelib/parser/inperror.c @@ -48,11 +48,9 @@ char *INPerror(int type) asprintf(&ebuf, "%s\n", val); #else /* ~ HAVE_ASPRINTF */ if (errRtn) { - ebuf = TMALLOC(char, strlen(val) + strlen(errRtn) + 25); - sprintf(ebuf, "%s detected in routine \"%s\"\n", val, errRtn); + ebuf = tprintf("%s detected in routine \"%s\"\n", val, errRtn); } else { - ebuf = TMALLOC(char, strlen(val) + 2); - sprintf(ebuf, "%s\n", val); + ebuf = tprintf("%s\n", val); } #endif /* HAVE_ASPRINTF */ tfree(val); diff --git a/src/spicelib/parser/inpgmod.c b/src/spicelib/parser/inpgmod.c index 97df9cb84..6511cf86c 100644 --- a/src/spicelib/parser/inpgmod.c +++ b/src/spicelib/parser/inpgmod.c @@ -121,9 +121,7 @@ create_model( CKTcircuit* ckt, INPmodel* modtmp, INPtables* tab ) controlled_exit(EXIT_FAILURE); } if (endptr == parm) { /* it was no number - it is really a string */ - temp = TMALLOC(char, 40 + strlen(parm)); - (void) sprintf(temp, - "unrecognized parameter (%s) - ignored", parm); + temp = tprintf("unrecognized parameter (%s) - ignored", parm); err = INPerrCat(err, temp); } } @@ -230,8 +228,7 @@ INPgetModBin( CKTcircuit* ckt, char* name, INPmodel** model, INPtables* tab, cha if (modtmp->INPmodType < 0) { /* First check for illegal model type */ /* illegal device type, so can't handle */ *model = NULL; - err = TMALLOC(char, 35 + strlen(name)); - (void) sprintf(err,"Unknown device type for model %s \n", name); + err = tprintf("Unknown device type for model %s \n", name); return (err); } /* end of checking for illegal model */ @@ -279,8 +276,7 @@ char *INPgetMod(CKTcircuit *ckt, char *name, INPmodel ** model, INPtables * tab) if (modtmp->INPmodType < 0) { /* First check for illegal model type */ /* illegal device type, so can't handle */ *model = NULL; - err = TMALLOC(char, 35 + strlen(name)); - (void) sprintf(err,"Unknown device type for model %s \n", name); + err = tprintf("Unknown device type for model %s \n", name); #ifdef TRACE /* SDB debug statement */ @@ -300,8 +296,7 @@ char *INPgetMod(CKTcircuit *ckt, char *name, INPmodel ** model, INPtables * tab) } /* didn't find model - ERROR - return model */ *model = NULL; - err = TMALLOC(char, 60 + strlen(name)); - (void) sprintf(err, "Unable to find definition of model %s - default assumed \n", name); + err = tprintf("Unable to find definition of model %s - default assumed \n", name); #ifdef TRACE /* SDB debug statement */ @@ -372,10 +367,8 @@ INPparseNumMod( CKTcircuit* ckt, INPmodel *model, INPtables *tab, char **errMess cardType = lastType; while (*line == '+') line++; /* Skip leading '+'s */ } else { - tmp = TMALLOC(char, 55); - (void) sprintf(tmp, - "Error on card %d : illegal continuation \'+\' - ignored", - cardNum); + tmp = tprintf("Error on card %d : illegal continuation \'+\' - ignored", + cardNum); err = INPerrCat(err,tmp); lastType = E_MISSING; break; @@ -404,10 +397,8 @@ INPparseNumMod( CKTcircuit* ckt, INPmodel *model, INPtables *tab, char **errMess cardType = E_MISSING; } else { /* Error */ - tmp = TMALLOC(char, 55 + strlen(cardName)); - (void) sprintf(tmp, - "Error on card %d : unrecognized name (%s) - ignored", - cardNum, cardName ); + tmp = tprintf("Error on card %d : unrecognized name (%s) - ignored", + cardNum, cardName); err = INPerrCat(err,tmp); } } @@ -427,17 +418,13 @@ INPparseNumMod( CKTcircuit* ckt, INPmodel *model, INPtables *tab, char **errMess idx = INPfindParm(parm, info->cardParms, info->numParms); if (idx == E_MISSING) { /* parm not found */ - tmp = TMALLOC(char, 60 + strlen(parm)); - (void)sprintf(tmp, - "Error on card %d : unrecognized parameter (%s) - ignored", - cardNum, parm); + tmp = tprintf("Error on card %d : unrecognized parameter (%s) - ignored", + cardNum, parm); err = INPerrCat(err, tmp); } else if (idx == E_AMBIGUOUS) { /* parm ambiguous */ - tmp = TMALLOC(char, 58 + strlen(parm)); - (void)sprintf(tmp, - "Error on card %d : ambiguous parameter (%s) - ignored", - cardNum, parm); + tmp = tprintf("Error on card %d : ambiguous parameter (%s) - ignored", + cardNum, parm); err = INPerrCat(err, tmp); } else { value = INPgetValue( ckt, &line, @@ -447,10 +434,8 @@ INPparseNumMod( CKTcircuit* ckt, INPmodel *model, INPtables *tab, char **errMess == IF_FLAG) { value->iValue = 0; } else { - tmp = TMALLOC(char, 63 + strlen(parm)); - (void)sprintf(tmp, - "Error on card %d : non-boolean parameter (%s) - \'^\' ignored", - cardNum, parm); + tmp = tprintf("Error on card %d : non-boolean parameter (%s) - \'^\' ignored", + cardNum, parm); err = INPerrCat(err, tmp); } } diff --git a/src/tclspice.c b/src/tclspice.c index 505115337..bec11a907 100644 --- a/src/tclspice.c +++ b/src/tclspice.c @@ -2535,8 +2535,7 @@ Spice_Init(Tcl_Interp *interp) #ifdef HAVE_ASPRINTF asprintf(&s, "%s%s", pw->pw_dir, INITSTR); #else - s = TMALLOC(char, 1 + strlen(pw->pw_dir) + strlen(INITSTR)); - sprintf(s, "%s%s", pw->pw_dir, INITSTR); + s = tprintf("%s%s", pw->pw_dir, INITSTR); #endif if (access(s, 0) == 0) inp_source(s); diff --git a/src/xspice/evt/evtinit.c b/src/xspice/evt/evtinit.c index 960159d9c..e11a33e75 100644 --- a/src/xspice/evt/evtinit.c +++ b/src/xspice/evt/evtinit.c @@ -217,10 +217,9 @@ static int EVTcheck_nodes( analog_node = ckt->CKTnodes; while(analog_node) { if(strcmp(event_node->name, analog_node->name) == 0) { - errMsg = TMALLOC(char, strlen(err_prefix) + strlen(event_node->name) + strlen(err_collide) + 1); - sprintf(errMsg, "%s%s%s", err_prefix, - event_node->name, - err_collide); + errMsg = tprintf("%s%s%s", err_prefix, + event_node->name, + err_collide); fprintf(stdout, "%s\n", errMsg); return(E_PRIVATE); } diff --git a/src/xspice/mif/mifgetmod.c b/src/xspice/mif/mifgetmod.c index b5fdf29d6..8a2c4b683 100644 --- a/src/xspice/mif/mifgetmod.c +++ b/src/xspice/mif/mifgetmod.c @@ -146,14 +146,7 @@ char *MIFgetMod( if(modtmp->INPmodType < 0) { /* illegal device type, so can't handle */ *model = NULL; - - /* fixed by SDB -- magic number is 39, not 35. - * Also needed parens to correctly compute # of bytes to malloc - */ - err = TMALLOC(char, 39 + strlen(name)); - - sprintf(err, "MIF: Unknown device type for model %s \n",name); - return(err); + return tprintf("MIF: Unknown device type for model %s\n", name); } /* check to see if this model's parameters have been processed */ @@ -199,8 +192,7 @@ char *MIFgetMod( ft_sim->devices[modtmp->INPmodType]->modelParms[j].dataType, tab, &err1); if(err1) { - err2 = TMALLOC(char, 25 + strlen(name) + strlen(err1)); - sprintf(err2, "MIF-ERROR - model: %s - %s\n", name, err1); + err2 = tprintf("MIF-ERROR - model: %s - %s\n", name, err1); return(err2); } error = ft_sim->setModelParm (ckt, @@ -214,8 +206,7 @@ char *MIFgetMod( } /* gtri modification: processing of special parameter "level" removed */ if(j >= *(ft_sim->devices[modtmp->INPmodType]->numModelParms)) { - char *temp = TMALLOC(char, 41 + strlen(parm)); - sprintf(temp, "MIF: unrecognized parameter (%s) - ignored", parm); + char *temp = tprintf("MIF: unrecognized parameter (%s) - ignored", parm); err = INPerrCat(err, temp); } FREE(parm); @@ -236,8 +227,7 @@ char *MIFgetMod( /* didn't find model - ERROR - return NULL model */ *model = NULL; - err = TMALLOC(char, 60 + strlen(name)); - sprintf(err, " MIF-ERROR - unable to find definition of model %s\n",name); + err = tprintf(" MIF-ERROR - unable to find definition of model %s\n", name); return(err); } diff --git a/src/xspice/mif/mifsetup.c b/src/xspice/mif/mifsetup.c index d993d7b40..86401420d 100644 --- a/src/xspice/mif/mifsetup.c +++ b/src/xspice/mif/mifsetup.c @@ -307,8 +307,7 @@ MIFsetup( (type == MIF_RESISTANCE || type == MIF_DIFF_RESISTANCE) ) { /* first, make the current equation */ - suffix = TMALLOC(char, strlen(here->MIFname) + 100); - sprintf(suffix, "branch_%d_%d", i, j); + suffix = tprintf("branch_%d_%d", i, j); error = CKTmkCur(ckt, &tmp, here->MIFname, suffix); FREE(suffix); if(error) @@ -330,8 +329,7 @@ MIFsetup( if(is_input && (type == MIF_CURRENT || type == MIF_DIFF_CURRENT)) { /* first, make the current equation */ - suffix = TMALLOC(char, strlen(here->MIFname) + 100); - sprintf(suffix, "ibranch_%d_%d", i, j); + suffix = tprintf("ibranch_%d_%d", i, j); error = CKTmkCur(ckt, &tmp, here->MIFname, suffix); FREE(suffix); if(error)