diff --git a/src/frontend/breakp2.c b/src/frontend/breakp2.c index 61b043cdc..7509e1f00 100644 --- a/src/frontend/breakp2.c +++ b/src/frontend/breakp2.c @@ -157,11 +157,9 @@ copynode(char *s) r = strchr(s, /*(*/')'); *r = '\0'; - if (*(l - 1) == 'i' || *(l - 1) == 'I') { - char buf[513]; - sprintf(buf, "%s#branch", l + 1); - ret = copy(buf); - } else + if (*(l - 1) == 'i' || *(l - 1) == 'I') + ret = tprintf("%s#branch", l + 1); + else ret = copy(l + 1); tfree(s); diff --git a/src/frontend/com_history.c b/src/frontend/com_history.c index 47423fa19..29c2cd8c4 100644 --- a/src/frontend/com_history.c +++ b/src/frontend/com_history.c @@ -56,16 +56,15 @@ wordlist * cp_histsubst(wordlist *wlist) { wordlist *nwl, *w, *n; - char buf[BSIZE_SP], *s, *b; + char *s, *b; /* Replace ^old^new with !:s^old^new. */ cp_didhsubst = FALSE; if (*wlist->wl_word == cp_hat) { - (void) sprintf(buf, "%c%c:s%s", cp_bang, cp_bang, - wlist->wl_word); - tfree(wlist->wl_word); - wlist->wl_word = copy(buf); + char *x = wlist->wl_word; + wlist->wl_word = tprintf("%c%c:s%s", cp_bang, cp_bang, wlist->wl_word); + tfree(x); } for (w = wlist; w; w = w->wl_next) { @@ -78,10 +77,10 @@ cp_histsubst(wordlist *wlist) wlist->wl_word = NULL; return (wlist); } - if (b < s) { - (void) sprintf(buf, "%.*s%s", (int)(s-b), b, n->wl_word); - tfree(n->wl_word); - n->wl_word = copy(buf); + if (s > b) { + char *x = n->wl_word; + n->wl_word = tprintf("%.*s%s", (int)(s-b), b, n->wl_word); + tfree(x); } nwl = wl_splice(w, n); if (wlist == w) @@ -182,11 +181,12 @@ dohsubst(char *string) return (NULL); if (*string) { + char *x; for (wl = nwl; wl->wl_next; wl = wl->wl_next) ; - (void) sprintf(buf, "%s%s", wl->wl_word, string); - tfree(wl->wl_word); - wl->wl_word = copy(buf); + x = wl->wl_word; + wl->wl_word = tprintf("%s%s", wl->wl_word, string); + tfree(x); } return (nwl); diff --git a/src/frontend/evaluate.c b/src/frontend/evaluate.c index 507bd9a41..0c678dfd7 100644 --- a/src/frontend/evaluate.c +++ b/src/frontend/evaluate.c @@ -1001,20 +1001,18 @@ op_not(struct pnode *arg) static char * mkcname(char what, char *v1, char *v2) { - char buf[BSIZE_SP], *s; - - if (what == 'a') - (void) sprintf(buf, "%s(%s)", v1, v2); - else if (what == 'b') - (void) sprintf(buf, "-(%s)", v1); - else if (what == 'c') - (void) sprintf(buf, "~(%s)", v1); - else if (what == '[') - (void) sprintf(buf, "%s[%s]", v1, v2); - else if (what == 'R') - (void) sprintf(buf, "%s[[%s]]", v1, v2); - else - (void) sprintf(buf, "(%s)%c(%s)", v1, what, v2); - s = copy(buf); - return (s); + switch (what) { + case 'a': + return tprintf("%s(%s)", v1, v2); + case 'b': + return tprintf("-(%s)", v1); + case 'c': + return tprintf("~(%s)", v1); + case '[': + return tprintf("%s[%s]", v1, v2); + case 'R': + return tprintf("%s[[%s]]", v1, v2); + default: + return tprintf("(%s)%c(%s)", v1, what, v2); + } } diff --git a/src/frontend/fourier.c b/src/frontend/fourier.c index 285c4198c..40f993d58 100644 --- a/src/frontend/fourier.c +++ b/src/frontend/fourier.c @@ -51,7 +51,6 @@ fourier(wordlist *wl, struct plot *current_plot) int shift; int rv = 1; - char newvecname[32]; struct dvec *n; int newveccount = 1; static int callstof = 1; @@ -190,14 +189,13 @@ fourier(wordlist *wl, struct plot *current_plot) } fputs("\n", cp_out); - /* generate name for new vector, using vec->name */ - sprintf(newvecname, "fourier%d%d", callstof, newveccount); - /* create and assign a new vector n */ /* with size 3 * nfreqs in current plot */ n = alloc(struct dvec); ZERO(n, struct dvec); - n->v_name = copy(newvecname); + + /* generate name for new vector, using vec->name */ + n->v_name = tprintf("fourier%d%d", callstof, newveccount); n->v_type = SV_NOTYPE; n->v_flags = (VF_REAL | VF_PERMANENT); n->v_length = 3 * nfreqs; @@ -255,18 +253,15 @@ com_fourier(wordlist *wl) static char * pnum(double num) { - char buf[BSIZE_SP]; int i = cp_numdgt; if (i < 1) i = 6; if (num < 0.0) - sprintf(buf, "%.*g", i - 1, num); + return tprintf("%.*g", i - 1, num); else - sprintf(buf, "%.*g", i, num); - - return (copy(buf)); + return tprintf("%.*g", i, num); } diff --git a/src/frontend/inp.c b/src/frontend/inp.c index 5088338cc..9faa3c4e4 100644 --- a/src/frontend/inp.c +++ b/src/frontend/inp.c @@ -1561,12 +1561,10 @@ inp_evaluate_temper(void) { struct pt_temper *d; double result; - char fts[128]; for(d = devtlist; d; d = d->next) { IFeval((IFparseTree *) d->pt, 1e-12, &result, NULL, NULL); - sprintf(fts, "%g", result); - d->wlend->wl_word = copy(fts); + d->wlend->wl_word = tprintf("%g", result); com_alter(d->wl); } @@ -1576,8 +1574,7 @@ inp_evaluate_temper(void) if (ft_sim->findModel (ft_curckt->ci_ckt, d->wl->wl_word) == NULL) continue; IFeval((IFparseTree *) d->pt, 1e-12, &result, NULL, NULL); - sprintf(fts, "%g", result); - d->wlend->wl_word = copy(fts); + d->wlend->wl_word = tprintf("%g", result); com_altermod(d->wl); } } diff --git a/src/frontend/linear.c b/src/frontend/linear.c index e0b28d3c1..6052dedaf 100644 --- a/src/frontend/linear.c +++ b/src/frontend/linear.c @@ -25,7 +25,6 @@ com_linearize(wordlist *wl) struct dvec *newtime, *v; struct dvec *oldtime; int len, i; - char buf[BSIZE_SP]; if (!ft_curckt || !ft_curckt->ci_ckt || !if_tranparams(ft_curckt, &tstart, &tstop, &tstep)) { @@ -55,8 +54,7 @@ com_linearize(wordlist *wl) old = plot_cur; oldtime = old->pl_scale; new = plot_alloc("transient"); - (void) sprintf(buf, "%s (linearized)", old->pl_name); - new->pl_name = copy(buf); + new->pl_name = tprintf("%s (linearized)", old->pl_name); new->pl_title = copy(old->pl_title); new->pl_date = copy(old->pl_date); new->pl_next = plot_list; diff --git a/src/frontend/measure.c b/src/frontend/measure.c index 546bf92d3..25041593d 100644 --- a/src/frontend/measure.c +++ b/src/frontend/measure.c @@ -37,10 +37,10 @@ void com_meas(wordlist *wl) { /* wl: in, input line of meas command */ - char *line_in, *outvar, newvec[1000]; + char *line_in, *outvar; wordlist *wl_count, *wl_let; - char *vec_found, *token, *equal_ptr, newval[256]; + char *vec_found, *token, *equal_ptr; wordlist *wl_index; struct dvec *d; int err = 0; @@ -79,9 +79,8 @@ com_meas(wordlist *wl) of the rigt hand side does make sense */ if (d && (d->v_length == 1) && (d->v_numdims == 1)) { /* get its value */ - sprintf(newval, "%e", d->v_realdata[0]); + wl_index->wl_word = tprintf("%e", d->v_realdata[0]); tfree(vec_found); - wl_index->wl_word = copy(newval); } } } @@ -96,11 +95,10 @@ com_meas(wordlist *wl) /* Only if we have a single valued vector, replacing of the rigt hand side does make sense */ if (d && (d->v_length == 1) && (d->v_numdims == 1)) { - *equal_ptr = '\0'; - sprintf(newval, "%s=%e", token, d->v_realdata[0]); - // memory leak with first part of vec_found ? + int lhs_len = (int)(equal_ptr - token); + wl_index->wl_word = + tprintf("%.*s=%e", lhs_len, token, d->v_realdata[0]); tfree(token); - wl_index->wl_word = copy(newval); } } } @@ -129,8 +127,7 @@ com_meas(wordlist *wl) return; } - sprintf(newvec, "%s = %e", outvar, result); - wl_let = wl_cons(copy(newvec), NULL); + wl_let = wl_cons(tprintf("%s = %e", outvar, result), NULL); com_let(wl_let); wl_free(wl_let); tfree(line_in); diff --git a/src/frontend/mw_coms.c b/src/frontend/mw_coms.c index aaed036a0..7f01a262d 100644 --- a/src/frontend/mw_coms.c +++ b/src/frontend/mw_coms.c @@ -27,7 +27,6 @@ com_removecirc(wordlist *wl) int auxCir = 1, i, auxPlot; char* namecircuit; - char buf[80]; NG_IGNORE(wl); @@ -113,15 +112,13 @@ com_removecirc(wordlist *wl) if (ft_circuits && caux->ci_next) { struct wordlist *wlist; - sprintf(buf, "%d", auxCir); - wlist = wl_cons(copy(buf), NULL); + wlist = wl_cons(tprintf("%d", auxCir), NULL); com_scirc(wlist); wl_free(wlist); } else if (ft_circuits) { struct wordlist *wlist; - sprintf(buf, "%d", auxCir-1); - wlist = wl_cons(copy(buf), NULL); + wlist = wl_cons(tprintf("%d", auxCir - 1), NULL); com_scirc(wlist); wl_free(wlist); } diff --git a/src/frontend/outitf.c b/src/frontend/outitf.c index eb13a93c9..2ca77f5a1 100644 --- a/src/frontend/outitf.c +++ b/src/frontend/outitf.c @@ -1009,7 +1009,6 @@ static void plotInit(runDesc *run) { struct plot *pl = plot_alloc(run->type); - char buf[100]; struct dvec *v; dataDesc *dd; int i; @@ -1033,8 +1032,7 @@ plotInit(runDesc *run) dd = &run->data[i]; v = alloc(struct dvec); if (isdigit(*dd->name)) { - (void) sprintf(buf, "V(%s)", dd->name); - v->v_name = copy(buf); + v->v_name = tprintf("V(%s)", dd->name); } else { v->v_name = copy(dd->name); } diff --git a/src/frontend/parse.c b/src/frontend/parse.c index b2180ae4e..7b1b98d3c 100644 --- a/src/frontend/parse.c +++ b/src/frontend/parse.c @@ -341,7 +341,6 @@ mknnode(double number) { struct pnode *p; struct dvec *v; - char buf[BSIZE_SP]; p = alloc(struct pnode); v = alloc(struct dvec); @@ -359,10 +358,9 @@ mknnode(double number) * large... */ if (number < MAXPOSINT) - (void) sprintf(buf, "%d", (int) number); + v->v_name = tprintf("%d", (int) number); else - (void) sprintf(buf, "%G", number); - v->v_name = copy(buf); + v->v_name = tprintf("%G", number); v->v_type = SV_NOTYPE; v->v_flags = VF_REAL; v->v_realdata = TMALLOC(double, 1); diff --git a/src/frontend/rawfile.c b/src/frontend/rawfile.c index 8874a0b4b..de6527212 100644 --- a/src/frontend/rawfile.c +++ b/src/frontend/rawfile.c @@ -295,7 +295,7 @@ raw_read(char *name) { char *title = "default title"; char *date = 0; struct plot *plots = NULL, *curpl = NULL; - char buf[BSIZE_SP], buf2[BSIZE_SP], *s, *t, *r; + char buf[BSIZE_SP], *s, *t, *r; int flags = 0, nvars = 0, npoints = 0, i, j; int ndimpoints, numdims = 0, dims[MAXDIMS]; bool raw_padded = TRUE, is_ascii = FALSE; @@ -499,8 +499,7 @@ raw_read(char *name) { /* Fix the name... */ if (isdigit(*v->v_name) && (r = ft_typabbrev(v ->v_type)) != NULL) { char *x = v->v_name; - (void) sprintf(buf2, "%s(%s)", r, v->v_name); - v->v_name = copy(buf2); + v->v_name = tprintf("%s(%s)", r, v->v_name); tfree(x); } diff --git a/src/frontend/spiceif.c b/src/frontend/spiceif.c index 71667960c..8e916e211 100644 --- a/src/frontend/spiceif.c +++ b/src/frontend/spiceif.c @@ -655,11 +655,9 @@ spif_getparam_special(CKTcircuit *ckt, char **name, char *param, int ind, int do /* With the following we pack the name and the acronym of the parameter */ { - char auxiliar[70], *aux_pointer; - sprintf(auxiliar, "%s [%s]", tv->va_name, device->instanceParms[i].keyword); - aux_pointer = tv->va_name; - free(aux_pointer); - tv->va_name = copy(auxiliar); + char *x = tv->va_name; + tv->va_name = tprintf("%s [%s]", tv->va_name, device->instanceParms[i].keyword); + free(x); } if (vv) tv->va_next = vv; @@ -702,12 +700,9 @@ spif_getparam_special(CKTcircuit *ckt, char **name, char *param, int ind, int do * tv->va_name += device->modelParms[i].keyword; */ { - char auxiliar[70], *aux_pointer; - sprintf(auxiliar, "%s [%s]", tv->va_name, device->modelParms[i].keyword); - aux_pointer = tv->va_name; - free(aux_pointer); - tv->va_name = copy(auxiliar); - /* strcpy(aux_pointer, auxiliar); */ + char *x = tv->va_name; + tv->va_name = tprintf("%s [%s]", tv->va_name, device->modelParms[i].keyword); + free(x); } /* tv->va_string = device->modelParms[i].keyword; Put the name of the variable */ if (vv) diff --git a/src/frontend/variable.c b/src/frontend/variable.c index 73db4b799..d8e796694 100644 --- a/src/frontend/variable.c +++ b/src/frontend/variable.c @@ -33,26 +33,23 @@ wordlist * cp_varwl(struct variable *var) { wordlist *wl = NULL, *w, *wx = NULL; - char buf[BSIZE_SP], *copystring; + char *buf; struct variable *vt; switch (var->va_type) { case CP_BOOL: /* Can't ever be FALSE. */ - sprintf(buf, "%s", var->va_bool ? "TRUE" : "FALSE"); + buf = copy(var->va_bool ? "TRUE" : "FALSE"); break; case CP_NUM: - sprintf(buf, "%d", var->va_num); + buf = tprintf("%d", var->va_num); break; case CP_REAL: /* This is a case where printnum isn't too good... */ - sprintf(buf, "%G", var->va_real); + buf = tprintf("%G", var->va_real); break; case CP_STRING: - /*strcpy(buf, cp_unquote(var->va_string)); DG: memory leak here*/ - copystring = cp_unquote(var->va_string); /*DG*/ - strcpy(buf, copystring); - tfree(copystring); + buf = cp_unquote(var->va_string); break; case CP_LIST: /* The tricky case. */ for (vt = var->va_vlist; vt; vt = vt->va_next) { @@ -73,8 +70,7 @@ cp_varwl(struct variable *var) return (NULL); } - wl = wl_cons(copy(buf), NULL); - return (wl); + return wl_cons(buf, NULL); } @@ -787,8 +783,7 @@ vareval(char *string) switch (*string) { case '$': - (void) sprintf(buf, "%d", getpid()); - wl = wl_cons(copy(buf), NULL); + wl = wl_cons(tprintf("%d", getpid()), NULL); tfree(oldstring); return (wl); @@ -836,8 +831,7 @@ vareval(char *string) i++; else i = (v->va_type != CP_BOOL); - (void) sprintf(buf, "%d", i); - wl = wl_cons(copy(buf), NULL); + wl = wl_cons(tprintf("%d", i), NULL); tfree(oldstring); return (wl); diff --git a/src/frontend/vectors.c b/src/frontend/vectors.c index f57dbf0f5..78fb97a4b 100644 --- a/src/frontend/vectors.c +++ b/src/frontend/vectors.c @@ -1080,7 +1080,7 @@ vec_mkfamily(struct dvec *v) { int size, numvecs, i, j, count[MAXDIMS]; struct dvec *vecs, *d; - char buf[BSIZE_SP], buf2[BSIZE_SP]; + char buf2[BSIZE_SP]; if (v->v_numdims < 2) return (v); @@ -1101,8 +1101,7 @@ vec_mkfamily(struct dvec *v) count[i] = 0; for (d = vecs, j = 0; d; j++, d = d->v_link2) { indexstring(count, v->v_numdims - 1, buf2); - (void) sprintf(buf, "%s%s", v->v_name, buf2); - d->v_name = copy(buf); + d->v_name = tprintf("%s%s", v->v_name, buf2); d->v_type = v->v_type; d->v_flags = v->v_flags; d->v_minsignal = v->v_minsignal;