Skip to content

Commit

Permalink
tpic: clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
rsc committed Apr 6, 2024
1 parent d5b2552 commit b1b88c7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/cmd/tpic/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
11 changes: 10 additions & 1 deletion src/cmd/tpic/main.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <signal.h>
#include <stdarg.h>
#include "pic.h"
#include "y.tab.h"

Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion src/cmd/tpic/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions src/cmd/tpic/pic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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"
2 changes: 0 additions & 2 deletions src/cmd/tpic/picl.l
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b1b88c7

Please sign in to comment.