From 88207db63853eef2c86ae9a63f7f6f58c7a5b89e Mon Sep 17 00:00:00 2001 From: George Koehler Date: Wed, 6 Dec 2017 17:09:12 -0500 Subject: [PATCH] Use in util/misc/convert.c I made a syntax error in some .e file, and em_encode dumped core because a 64-bit pointer didn't fit in a 32-bit int. Now use stdarg to pass pointers to error() and fatal(). Stop using the number of errors as the exit status. Many systems use only the low 8 bits of the exit status, so 256 errors would become 0. Also change modules/src/print to accept const char *buf --- modules/src/print/doprnt.c | 2 +- modules/src/print/format.c | 2 +- modules/src/print/fprint.c | 2 +- modules/src/print/print.c | 2 +- modules/src/print/print.h | 10 +++++----- modules/src/print/sprint.c | 2 +- util/misc/convert.c | 28 +++++++++++++++++++--------- 7 files changed, 29 insertions(+), 19 deletions(-) diff --git a/modules/src/print/doprnt.c b/modules/src/print/doprnt.c index a77b7d2c1..1d888e570 100644 --- a/modules/src/print/doprnt.c +++ b/modules/src/print/doprnt.c @@ -16,7 +16,7 @@ %d = int $ */ void -doprnt(File *fp, char *fmt, va_list argp) +doprnt(File *fp, const char *fmt, va_list argp) { char buf[SSIZE]; diff --git a/modules/src/print/format.c b/modules/src/print/format.c index 2ad920bc8..e03717918 100644 --- a/modules/src/print/format.c +++ b/modules/src/print/format.c @@ -35,7 +35,7 @@ integral(int c) %d = int $ */ int -_format(char *buf, char *fmt, va_list argp) +_format(char *buf, const char *fmt, va_list argp) { register char *pf = fmt; register char *pb = buf; diff --git a/modules/src/print/fprint.c b/modules/src/print/fprint.c index c401858a9..6b5b8a389 100644 --- a/modules/src/print/fprint.c +++ b/modules/src/print/fprint.c @@ -17,7 +17,7 @@ $ */ /*VARARGS*/ void -fprint(File *fp, char *fmt, ...) +fprint(File *fp, const char *fmt, ...) { va_list args; char buf[SSIZE]; diff --git a/modules/src/print/print.c b/modules/src/print/print.c index cd9346e98..2e1256a54 100644 --- a/modules/src/print/print.c +++ b/modules/src/print/print.c @@ -17,7 +17,7 @@ $ */ /*VARARGS*/ void -print(char *fmt, ...) +print(const char *fmt, ...) { va_list args; char buf[SSIZE]; diff --git a/modules/src/print/print.h b/modules/src/print/print.h index 56372376a..974e4bf1b 100644 --- a/modules/src/print/print.h +++ b/modules/src/print/print.h @@ -9,10 +9,10 @@ #include -void print(char *fmt, ...); -void fprint(File *f, char *fmt, ...); -void doprnt(File *f, char *fmt, va_list ap); -int _format(char *buf, char *fmt, va_list ap); -char *sprint(char *buf, char *fmt, ...); +void print(const char *fmt, ...); +void fprint(File *f, const char *fmt, ...); +void doprnt(File *f, const char *fmt, va_list ap); +int _format(char *buf, const char *fmt, va_list ap); +char *sprint(char *buf, const char *fmt, ...); #endif /* __PRINT_INCLUDED__ */ diff --git a/modules/src/print/sprint.c b/modules/src/print/sprint.c index d88b47e69..7c9dbf9b0 100644 --- a/modules/src/print/sprint.c +++ b/modules/src/print/sprint.c @@ -17,7 +17,7 @@ $ */ /*VARARGS*/ char * -sprint(char *buf, char *fmt, ...) +sprint(char *buf, const char *fmt, ...) { va_list args; diff --git a/util/misc/convert.c b/util/misc/convert.c index ec38761fa..9bdc12011 100644 --- a/util/misc/convert.c +++ b/util/misc/convert.c @@ -16,8 +16,10 @@ static char rcsid[] = "$Id$"; linked. */ +#include #include #include "system.h" +#include "print.h" #include "em_pseu.h" #include "em_mnem.h" #include "em_spec.h" @@ -30,8 +32,11 @@ char *filename; /* Name of input file */ int errors; /* Number of errors */ extern char *C_error; -main(argc,argv) - char **argv; +void error(const char *, ...); +void fatal(const char *, ...); + +int +main(int argc, char **argv) { struct e_instr buf; register struct e_instr *p = &buf; @@ -66,27 +71,32 @@ main(argc,argv) } C_close(); EM_close(); - exit(errors); + exit(errors ? 1 : 0); } /* VARARGS */ -error(s,a1,a2,a3,a4) - char *s; +void +error(const char *s, ...) { + va_list ap; + va_start(ap, s); fprint(STDERR, "%s, line %d: ", filename ? filename : "standard input", EM_lineno); - fprint(STDERR,s,a1,a2,a3,a4); + doprnt(STDERR, s, ap); fprint(STDERR, "\n"); errors++; + va_end(ap); } /* VARARGS */ -fatal(s,a1,a2,a3,a4) - char *s; +void +fatal(const char *s, ...) { + va_list ap; + va_start(ap, s); if (C_busy()) C_close(); - error(s,a1,a2,a3,a4); + error(s, ap); exit(1); }