diff --git a/src/cmd/tpic/input.c b/src/cmd/tpic/input.c index 85b7dbb570..c4c975b0c2 100644 --- a/src/cmd/tpic/input.c +++ b/src/cmd/tpic/input.c @@ -586,7 +586,7 @@ char shellbuf[1000], *shellp; void shell_init(void) /* set up to interpret a shell command */ { - sprintf(shellbuf, "sh -c '"); + snprintf(shellbuf, sizeof shellbuf, "sh -c '"); shellp = shellbuf + strlen(shellbuf); } diff --git a/src/cmd/tpic/main.c b/src/cmd/tpic/main.c index ed310d5d6e..f38278ffca 100644 --- a/src/cmd/tpic/main.c +++ b/src/cmd/tpic/main.c @@ -1,5 +1,6 @@ #include #include +#include #include "pic.h" #include "y.tab.h" @@ -62,7 +63,7 @@ main(int argc, char **argv) text = (Text *) grow((char *)text, "text", ntextlist += 1000, sizeof(Text)); attr = (Attr *) grow((char *)attr, "attr", nattrlist += 100, sizeof(Attr)); - sprintf(buf, "/%d/", getpid()); + snprintf(buf, sizeof buf, "/%d/", getpid()); pushsrc(String, buf); definition("pid"); @@ -275,3 +276,11 @@ reset(void) xmin = ymin = 30000; xmax = ymax = -30000; } + +void +tpicsnprintf(char *buf, int n, const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vsnprintf(buf, n, fmt, args); +} diff --git a/src/cmd/tpic/misc.c b/src/cmd/tpic/misc.c index 1dbdffcc6d..ce63bc4485 100644 --- a/src/cmd/tpic/misc.c +++ b/src/cmd/tpic/misc.c @@ -92,7 +92,7 @@ sprintgen(char *fmt) { char buf[1000]; - sprintf(buf, fmt, exprlist[0], exprlist[1], exprlist[2], exprlist[3], exprlist[4]); + snprintf(buf, sizeof buf, fmt, exprlist[0], exprlist[1], exprlist[2], exprlist[3], exprlist[4]); nexpr = 0; free(fmt); return tostring(buf); diff --git a/src/cmd/tpic/pic.h b/src/cmd/tpic/pic.h index 104cacebf0..faa177cec8 100644 --- a/src/cmd/tpic/pic.h +++ b/src/cmd/tpic/pic.h @@ -13,9 +13,7 @@ extern char errbuf[1000]; -#undef sprintf /* Snow Leopard */ - -#define ERROR sprintf(errbuf, +#define ERROR tpicsnprintf(errbuf, sizeof errbuf, #define FATAL ), yyerror(errbuf), exit(1) #define WARNING ), yyerror(errbuf) @@ -283,5 +281,6 @@ int unput(int c); int whatpos(obj *p, int corner, double *px, double *py) /* what is the position (no side effect) */; void yyerror(char *s); int yyparse(void); +void tpicsnprintf(char*, int, const char*, ...); #include "tex.h" diff --git a/src/cmd/tpic/picl.l b/src/cmd/tpic/picl.l index 8a706dc587..2e40fb2132 100644 --- a/src/cmd/tpic/picl.l +++ b/src/cmd/tpic/picl.l @@ -14,10 +14,8 @@ #include "pic.h" #include "y.tab.h" -extern double atof(); extern char *filename; extern struct symtab symtab[]; -extern struct symtab*copythru(); #define CADD cbuf[clen++]=yytext[0]; if(clen>=CBUFLEN-1) {ERROR "string too long" WARNING; BEGIN A;} #define CBUFLEN 500