* [PATCH] erec: Make error messages in nft consistent
@ 2016-11-15 19:22 Elise Lennion
2016-11-15 19:50 ` Pablo Neira Ayuso
0 siblings, 1 reply; 3+ messages in thread
From: Elise Lennion @ 2016-11-15 19:22 UTC (permalink / raw)
To: pablo; +Cc: netfilter-devel
Error messages in nft should start with "syntax error" to keep
consistency. A new function add_syntax_error() was created to add this
prefix when necessary.
Signed-off-by: Elise Lennion <elise.lennion@gmail.com>
---
include/erec.h | 3 +++
src/erec.c | 23 +++++++++++++++++++++++
2 files changed, 26 insertions(+)
diff --git a/include/erec.h b/include/erec.h
index 36e0efa..82754e0 100644
--- a/include/erec.h
+++ b/include/erec.h
@@ -52,9 +52,12 @@ extern void erec_add_location(struct error_record *erec,
#define warning(loc, fmt, args...) \
erec_create(EREC_WARNING, (loc), (fmt), ## args)
+extern void add_syntax_error(struct error_record *erec);
+
static inline void erec_queue(struct error_record *erec,
struct list_head *queue)
{
+ add_syntax_error(erec);
list_add_tail(&erec->list, queue);
}
diff --git a/src/erec.c b/src/erec.c
index 3603216..e4d7aef 100644
--- a/src/erec.c
+++ b/src/erec.c
@@ -194,3 +194,26 @@ int __fmtstring(4, 5) __stmt_binary_error(struct eval_ctx *ctx,
erec_queue(erec, ctx->msgs);
return -1;
}
+
+void add_syntax_error(struct error_record *erec){
+ if (erec) {
+ const char *stxmsg = "syntax error, ";
+ int mlen = strlen(erec->msg);
+ int slen = strlen(stxmsg);
+ char *tmp;
+
+ if (!strncmp(erec->msg, stxmsg, slen - 2))
+ return;
+
+ if (!mlen)
+ slen -= 2;
+
+ tmp = realloc(erec->msg, slen + mlen + 1);
+ if (tmp) {
+ erec->msg = tmp;
+ memmove(&(erec->msg[slen]), erec->msg, mlen);
+ memcpy(erec->msg, stxmsg, slen);
+ erec->msg[slen + mlen] = '\0';
+ }
+ }
+}
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] erec: Make error messages in nft consistent
2016-11-15 19:22 [PATCH] erec: Make error messages in nft consistent Elise Lennion
@ 2016-11-15 19:50 ` Pablo Neira Ayuso
2016-11-15 19:56 ` Pablo Neira Ayuso
0 siblings, 1 reply; 3+ messages in thread
From: Pablo Neira Ayuso @ 2016-11-15 19:50 UTC (permalink / raw)
To: Elise Lennion; +Cc: netfilter-devel
On Tue, Nov 15, 2016 at 05:22:38PM -0200, Elise Lennion wrote:
> Error messages in nft should start with "syntax error" to keep
> consistency. A new function add_syntax_error() was created to add this
> prefix when necessary.
Probably you can just add EREC_SYNTAX_ERROR to enum
error_record_types, then add:
#define syntax_error(loc, fmt, args...) \
erec_create(EREC_SYNTA_ERROR, (loc), (fmt), ## args)
and use it from src/parser_bison.y
Thanks!
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] erec: Make error messages in nft consistent
2016-11-15 19:50 ` Pablo Neira Ayuso
@ 2016-11-15 19:56 ` Pablo Neira Ayuso
0 siblings, 0 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2016-11-15 19:56 UTC (permalink / raw)
To: Elise Lennion; +Cc: netfilter-devel
On Tue, Nov 15, 2016 at 08:50:10PM +0100, Pablo Neira Ayuso wrote:
> On Tue, Nov 15, 2016 at 05:22:38PM -0200, Elise Lennion wrote:
> > Error messages in nft should start with "syntax error" to keep
> > consistency. A new function add_syntax_error() was created to add this
> > prefix when necessary.
>
> Probably you can just add EREC_SYNTAX_ERROR to enum
> error_record_types, then add:
>
> #define syntax_error(loc, fmt, args...) \
> erec_create(EREC_SYNTA_ERROR, (loc), (fmt), ## args)
Actually, git grep "erec_queue(error(" tells me all:
erec_queue(error(...
occur in parser_bison.y, so we can just update #define error in erec.h
You will have to define something like __error, which doesn't include
the "syntax error" string, as bison is already including it in this
spot below:
static void yyerror(struct location *loc, void *scanner,
struct parser_state *state, const char *s)
{
erec_queue(__error(loc, "%s", s), state->msgs);
}
So it will be a simple patch in the end.
Thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-11-15 19:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-15 19:22 [PATCH] erec: Make error messages in nft consistent Elise Lennion
2016-11-15 19:50 ` Pablo Neira Ayuso
2016-11-15 19:56 ` Pablo Neira Ayuso
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).