commit b1b88c75fd763ee768d88cd60e61aabf9efeb642
parent d5b2552b9582cf10a4fce1fde3584415246d4ef9
Author: Russ Cox <rsc@golang.org>
Date: Sat, 6 Apr 2024 11:13:59 -0400
tpic: clean up
Diffstat:
5 files changed, 14 insertions(+), 8 deletions(-)
diff --git 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
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <signal.h>
+#include <stdarg.h>
#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
@@ -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
@@ -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
@@ -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