From patchwork Tue Feb 28 20:20:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Frysinger X-Patchwork-Id: 19409 Received: (qmail 118378 invoked by alias); 28 Feb 2017 20:20:18 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 118354 invoked by uid 89); 28 Feb 2017 20:20:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=tokp, reserved X-HELO: smtp.gentoo.org From: Mike Frysinger To: libc-alpha@sourceware.org Subject: [PATCH] rpcgen: make error() helper into a varargs func Date: Tue, 28 Feb 2017 13:20:07 -0700 Message-Id: <20170228202007.13529-1-vapier@gentoo.org> A minor clean up to the code to avoid fixed buffers for output messages and to make error() more useful internally. --- sunrpc/proto.h | 2 +- sunrpc/rpc_parse.c | 13 ++----------- sunrpc/rpc_scan.c | 13 +++---------- sunrpc/rpc_util.c | 28 ++++++++++++---------------- sunrpc/rpc_util.h | 2 +- 5 files changed, 19 insertions(+), 39 deletions(-) diff --git a/sunrpc/proto.h b/sunrpc/proto.h index ea28565b1e6e..ff94fe214a2b 100644 --- a/sunrpc/proto.h +++ b/sunrpc/proto.h @@ -45,7 +45,7 @@ void write_tables(void); /****** rpc_util.c ******/ void reinitialize(void); int streq(const char *a, const char *b); -void error(const char *msg) __attribute__ ((noreturn)); +void error(const char *msg, ...) __attribute__ ((noreturn, __format__ (__printf__, 1, 2))); void crash(void) __attribute__ ((noreturn)); void tabify(FILE *f, int tab); char *make_argname(const char *pname, const char *vname); diff --git a/sunrpc/rpc_parse.c b/sunrpc/rpc_parse.c index 505a6554cfa3..be2eb9bd2b4e 100644 --- a/sunrpc/rpc_parse.c +++ b/sunrpc/rpc_parse.c @@ -409,27 +409,18 @@ 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); } } } diff --git a/sunrpc/rpc_scan.c b/sunrpc/rpc_scan.c index a230aa396b37..95405687f30f 100644 --- a/sunrpc/rpc_scan.c +++ b/sunrpc/rpc_scan.c @@ -303,19 +303,12 @@ get_token (token *tokp) if (!(isalpha (*where) || *where == '_')) { char buf[100]; - char *p; - s_print (buf, _("illegal character in file: ")); - p = buf + strlen (buf); if (isprint (*where)) - { - s_print (p, "%c", *where); - } + s_print (buf, "%c", *where); else - { - s_print (p, "%d", *where); - } - error (buf); + s_print (buf, "%d", *where); + error (_("illegal character in file: %s"), buf); } findkind (&where, tokp); break; diff --git a/sunrpc/rpc_util.c b/sunrpc/rpc_util.c index 52aa69757b30..7e62f95f2ac6 100644 --- a/sunrpc/rpc_util.c +++ b/sunrpc/rpc_util.c @@ -35,6 +35,7 @@ */ #include #include +#include #include #include #include "rpc_scan.h" @@ -270,11 +271,16 @@ pvname (const char *pname, const char *vnum) * print a useful (?) error message, and then die */ void -error (const char *msg) +error (const char *msg, ...) { + va_list arg; + printwhere (); f_print (stderr, "%s, line %d: ", infilename, linenum); - f_print (stderr, "%s\n", msg); + va_start (arg, msg); + vfprintf (stderr, msg, arg); + f_print (stderr, "\n"); + va_end (arg); crash (); } @@ -308,17 +314,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)); } /* @@ -327,10 +329,7 @@ expected1 (tok_kind exp1) void expected2 (tok_kind exp1, tok_kind exp2) { - s_print (expectbuf, "expected '%s' or '%s'", - toktostr (exp1), - toktostr (exp2)); - error (expectbuf); + error ("expected '%s' or '%s'", toktostr (exp1), toktostr (exp2)); } /* @@ -339,11 +338,8 @@ 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'", - toktostr (exp1), - toktostr (exp2), - toktostr (exp3)); - error (expectbuf); + error ("expected '%s', '%s' or '%s'", toktostr (exp1), toktostr (exp2), + toktostr (exp3)); } void diff --git a/sunrpc/rpc_util.h b/sunrpc/rpc_util.h index 53316d9516db..e46a5d2a605a 100644 --- a/sunrpc/rpc_util.h +++ b/sunrpc/rpc_util.h @@ -115,7 +115,7 @@ void pvname(const char *pname, const char *vnum); void ptype(const char *prefix, const char *type, int follow); int isvectordef(const char *type, relation rel); int streq(const char *a, const char *b); -void error(const char *msg); +void error(const char *msg, ...); void tabify(FILE *f, int tab); void record_open(const char *file); bas_type *find_type(const char *type);