All of lore.kernel.org
 help / color / mirror / Atom feed
From: Elise Lennion <elise.lennion@gmail.com>
To: pablo@netfilter.org
Cc: netfilter-devel@vger.kernel.org
Subject: [PATCH] erec: Make error messages in nft consistent
Date: Tue, 15 Nov 2016 17:22:38 -0200	[thread overview]
Message-ID: <20161115192237.GA29317@lennorien.com> (raw)

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


             reply	other threads:[~2016-11-15 19:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-15 19:22 Elise Lennion [this message]
2016-11-15 19:50 ` [PATCH] erec: Make error messages in nft consistent Pablo Neira Ayuso
2016-11-15 19:56   ` Pablo Neira Ayuso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161115192237.GA29317@lennorien.com \
    --to=elise.lennion@gmail.com \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.