Module Name:    src
Committed By:   dholland
Date:           Sat May  9 23:28:43 UTC 2015

Modified Files:
        src/usr.bin/rpcgen: rpc_parse.c rpc_scan.c rpc_util.c rpc_util.h

Log Message:
Make error() printflike instead of using sprintf before calling it.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/rpcgen/rpc_parse.c
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/rpcgen/rpc_scan.c
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/rpcgen/rpc_util.c
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/rpcgen/rpc_util.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/rpcgen/rpc_parse.c
diff -u src/usr.bin/rpcgen/rpc_parse.c:1.19 src/usr.bin/rpcgen/rpc_parse.c:1.20
--- src/usr.bin/rpcgen/rpc_parse.c:1.19	Sat May  9 23:12:57 2015
+++ src/usr.bin/rpcgen/rpc_parse.c	Sat May  9 23:28:43 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: rpc_parse.c,v 1.19 2015/05/09 23:12:57 dholland Exp $	*/
+/*	$NetBSD: rpc_parse.c,v 1.20 2015/05/09 23:28:43 dholland Exp $	*/
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  * unrestricted use provided that this legend is included on all tape
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)rpc_parse.c 1.8 89/02/22 (C) 1987 SMI";
 #else
-__RCSID("$NetBSD: rpc_parse.c,v 1.19 2015/05/09 23:12:57 dholland Exp $");
+__RCSID("$NetBSD: rpc_parse.c,v 1.20 2015/05/09 23:28:43 dholland Exp $");
 #endif
 #endif
 
@@ -377,21 +377,16 @@ static void
 check_type_name(const char *name, int new_type)
 {
 	int     i;
-	char    tmp[100];
 
 	for (i = 0; reserved_words[i] != NULL; i++) {
 		if (strcmp(name, reserved_words[i]) == 0) {
-			sprintf(tmp,
-			    "Illegal (reserved) name '%s' in type definition", name);
-			error(tmp);
+			error("Illegal (reserved) name '%s' in type definition", name);
 		}
 	}
 	if (new_type) {
 		for (i = 0; reserved_types[i] != NULL; i++) {
 			if (strcmp(name, reserved_types[i]) == 0) {
-				sprintf(tmp,
-				    "Illegal (reserved) name '%s' in type definition", name);
-				error(tmp);
+				error("Illegal (reserved) name '%s' in type definition", name);
 			}
 		}
 	}

Index: src/usr.bin/rpcgen/rpc_scan.c
diff -u src/usr.bin/rpcgen/rpc_scan.c:1.14 src/usr.bin/rpcgen/rpc_scan.c:1.15
--- src/usr.bin/rpcgen/rpc_scan.c:1.14	Sat May  9 23:12:57 2015
+++ src/usr.bin/rpcgen/rpc_scan.c	Sat May  9 23:28:43 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: rpc_scan.c,v 1.14 2015/05/09 23:12:57 dholland Exp $	*/
+/*	$NetBSD: rpc_scan.c,v 1.15 2015/05/09 23:28:43 dholland Exp $	*/
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  * unrestricted use provided that this legend is included on all tape
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)rpc_scan.c 1.11 89/02/22 (C) 1987 SMI";
 #else
-__RCSID("$NetBSD: rpc_scan.c,v 1.14 2015/05/09 23:12:57 dholland Exp $");
+__RCSID("$NetBSD: rpc_scan.c,v 1.15 2015/05/09 23:28:43 dholland Exp $");
 #endif
 #endif
 
@@ -283,17 +283,11 @@ get_token(token *tokp)
 
 	default:
 		if (!(isalpha((unsigned char)*where) || *where == '_')) {
-			char    buf[100];
-			char   *p;
-
-			s_print(buf, "Illegal character in file: ");
-			p = buf + strlen(buf);
 			if (isprint((unsigned char)*where)) {
-				s_print(p, "%c", *where);
+				error("Illegal character '%c' in file", *where);
 			} else {
-				s_print(p, "%d", *where);
+				error("Illegal character %d in file", *where);
 			}
-			error(buf);
 		}
 		findkind(&where, tokp);
 		break;

Index: src/usr.bin/rpcgen/rpc_util.c
diff -u src/usr.bin/rpcgen/rpc_util.c:1.16 src/usr.bin/rpcgen/rpc_util.c:1.17
--- src/usr.bin/rpcgen/rpc_util.c:1.16	Sat May  9 23:16:51 2015
+++ src/usr.bin/rpcgen/rpc_util.c	Sat May  9 23:28:43 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: rpc_util.c,v 1.16 2015/05/09 23:16:51 dholland Exp $	*/
+/*	$NetBSD: rpc_util.c,v 1.17 2015/05/09 23:28:43 dholland Exp $	*/
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  * unrestricted use provided that this legend is included on all tape
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)rpc_util.c 1.11 89/02/22 (C) 1987 SMI";
 #else
-__RCSID("$NetBSD: rpc_util.c,v 1.16 2015/05/09 23:16:51 dholland Exp $");
+__RCSID("$NetBSD: rpc_util.c,v 1.17 2015/05/09 23:28:43 dholland Exp $");
 #endif
 #endif
 
@@ -254,11 +254,17 @@ pvname(const char *pname, const char *vn
 /*
  * print a useful (?) error message, and then die
  */
-void
-error(const char *msg)
+__printflike(1, 2) void
+error(const char *msg, ...)
 {
+	va_list ap;
+
 	printwhere();
-	f_print(stderr, "%s:%d: %s", infilename, linenum, msg);
+	fprintf(stderr, "%s:%d: ", infilename, linenum);
+	va_start(ap, msg);
+	vfprintf(stderr, msg, ap);
+	va_end(ap);
+	fprintf(stderr, "\n");
 	errx(EXIT_FAILURE, "Cannot recover from this error");
 }
 /*
@@ -288,17 +294,13 @@ record_open(const char *file)
 	}
 }
 
-static char expectbuf[100];
-
 /*
  * error, token encountered was not the expected one
  */
 void
 expected1(tok_kind exp1)
 {
-	s_print(expectbuf, "Expected '%s'",
-	    toktostr(exp1));
-	error(expectbuf);
+	error("Expected '%s'", toktostr(exp1));
 }
 /*
  * error, token encountered was not one of two expected ones
@@ -306,10 +308,9 @@ expected1(tok_kind exp1)
 void
 expected2(tok_kind exp1, tok_kind exp2)
 {
-	s_print(expectbuf, "Expected '%s' or '%s'",
+	error("Expected '%s' or '%s'",
 	    toktostr(exp1),
 	    toktostr(exp2));
-	error(expectbuf);
 }
 /*
  * error, token encountered was not one of 3 expected ones
@@ -317,11 +318,10 @@ expected2(tok_kind exp1, tok_kind exp2)
 void
 expected3(tok_kind exp1, tok_kind exp2, tok_kind exp3)
 {
-	s_print(expectbuf, "Expected '%s', '%s', or '%s'",
+	error("Expected '%s', '%s', or '%s'",
 	    toktostr(exp1),
 	    toktostr(exp2),
 	    toktostr(exp3));
-	error(expectbuf);
 }
 
 void

Index: src/usr.bin/rpcgen/rpc_util.h
diff -u src/usr.bin/rpcgen/rpc_util.h:1.10 src/usr.bin/rpcgen/rpc_util.h:1.11
--- src/usr.bin/rpcgen/rpc_util.h:1.10	Sat May  9 23:19:34 2015
+++ src/usr.bin/rpcgen/rpc_util.h	Sat May  9 23:28:43 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: rpc_util.h,v 1.10 2015/05/09 23:19:34 dholland Exp $	*/
+/*	$NetBSD: rpc_util.h,v 1.11 2015/05/09 23:28:43 dholland Exp $	*/
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  * unrestricted use provided that this legend is included on all tape
@@ -114,7 +114,7 @@ int isvectordef(const char *, relation);
 char *locase(const char *);
 void pvname_svc(const char *, const char *);
 void pvname(const char *, const char *);
-void error(const char *);
+__printflike(1, 2) void error(const char *, ...);
 void crash(void);
 void record_open(const char *);
 void expected1(tok_kind) __dead;

Reply via email to