From mboxrd@z Thu Jan 1 00:00:00 1970 From: Adrien Mazarguil Subject: [PATCH v4 05/25] cmdline: add alignment constraint Date: Tue, 20 Dec 2016 19:42:22 +0100 Message-ID: <525d3d04cfc47fa950fe7068de159152a364be6d.1482257521.git.adrien.mazarguil@6wind.com> References: To: dev@dpdk.org Return-path: Received: from mail-wm0-f42.google.com (mail-wm0-f42.google.com [74.125.82.42]) by dpdk.org (Postfix) with ESMTP id 382A0FBD9 for ; Tue, 20 Dec 2016 19:43:06 +0100 (CET) Received: by mail-wm0-f42.google.com with SMTP id a197so128379295wmd.0 for ; Tue, 20 Dec 2016 10:43:06 -0800 (PST) Received: from 6wind.com (guy78-3-82-239-227-177.fbx.proxad.net. [82.239.227.177]) by smtp.gmail.com with ESMTPSA id k2sm26923921wjv.11.2016.12.20.10.43.04 for (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 20 Dec 2016 10:43:04 -0800 (PST) In-Reply-To: List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This prevents sigbus errors on architectures that cannot handle unexpected unaligned accesses to the output buffer. Signed-off-by: Adrien Mazarguil Acked-by: Olga Shern --- lib/librte_cmdline/cmdline_parse.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/librte_cmdline/cmdline_parse.c b/lib/librte_cmdline/cmdline_parse.c index 14f5553..763c286 100644 --- a/lib/librte_cmdline/cmdline_parse.c +++ b/lib/librte_cmdline/cmdline_parse.c @@ -255,7 +255,10 @@ cmdline_parse(struct cmdline *cl, const char * buf) unsigned int inst_num=0; cmdline_parse_inst_t *inst; const char *curbuf; - char result_buf[CMDLINE_PARSE_RESULT_BUFSIZE]; + union { + char buf[CMDLINE_PARSE_RESULT_BUFSIZE]; + long double align; /* strong alignment constraint for buf */ + } result; cmdline_parse_token_hdr_t *dyn_tokens[CMDLINE_PARSE_DYNAMIC_TOKENS]; void (*f)(void *, struct cmdline *, void *) = NULL; void *data = NULL; @@ -318,7 +321,7 @@ cmdline_parse(struct cmdline *cl, const char * buf) debug_printf("INST %d\n", inst_num); /* fully parsed */ - tok = match_inst(inst, buf, 0, result_buf, sizeof(result_buf), + tok = match_inst(inst, buf, 0, result.buf, sizeof(result.buf), &dyn_tokens); if (tok > 0) /* we matched at least one token */ @@ -353,7 +356,7 @@ cmdline_parse(struct cmdline *cl, const char * buf) /* call func */ if (f) { - f(result_buf, cl, data); + f(result.buf, cl, data); } /* no match */ -- 2.1.4