On 07/28/2017 05:23 PM, David CARLIER wrote:
Good points :-) sorry for the noise.
On 28 July 2017 at 14:07, Willy Tarreau <w...@1wt.eu <mailto:w...@1wt.eu>>
wrote:
Hi David,
On Fri, Jul 28, 2017 at 01:58:29PM +0100, David CARLIER wrote:
> Hi all,
>
> Nothing serious, just a patch proposal to silent compiler warning
about
> function parameter types.
>
> Kind regards.
> From 6ed9b28287440ca74e7a29016f9c4d081cd902d5 Mon Sep 17 00:00:00 2001
> From: David Carlier <devne...@gmail.com <mailto:devne...@gmail.com>>
> Date: Fri, 28 Jul 2017 14:42:42 +0100
> Subject: [PATCH] CLEANUP: spoe: silencing compiler warning.
>
> Here we cast explicitally to silence gcc complains mismatches.
> ---
> src/flt_spoe.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/src/flt_spoe.c b/src/flt_spoe.c
> index 5d574477..4df16ef6 100644
> --- a/src/flt_spoe.c
> +++ b/src/flt_spoe.c
> @@ -706,7 +706,7 @@ spoe_handle_agenthello_frame(struct appctx
*appctx, char *frame, size_t size)
> SPOE_APPCTX(appctx)->status_code =
SPOE_FRM_ERR_INVALID;
> return 0;
> }
> - if (decode_varint(&p, end, &sz) == -1) {
> + if (decode_varint(&p, end, (uint64_t *)&sz)
== -1) {
(...)
I noticed these ones as well recently but I'd rather avoid to start
casting
the pointers, or sooner or later we'll regret it. And by the way
it's a real
bug, as decode_varint() takes an uint64_t* while size_t will
generally be an
uint32_t on 32-bit architectures.
We'll more generally need to slightly modify the internal prototypes
to use
either one or the other type. By experience I tend to be used to see
that
when you change one of them it can propagate far away. But it will
be safer
(and will address the issue on 32-bit).
As long as we have this warning we have a reminder that there's
something
to fix ;-)
Hello Willy, David, Christopher,
I have just had a look at this issue. In fact the required modifications
were not that complicated.
Here is a simple patch for this issue.
Regards.
>From ca080eb5e0ed959686e7cb67cd614a570059aea1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20L=C3=A9caille?= <flecai...@haproxy.com>
Date: Tue, 22 Aug 2017 10:33:14 +0200
Subject: [PATCH] BUG/MINOR: Wrong type used as argument for
spoe_decode_buffer().
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Contrary to 64-bits libCs where size_t type size is 8, on systems with 32-bits
size of size_t is 4 (the size of a long) which does not equal to size of uint64_t type.
This was revealed by such GCC warnings on 32bits systems:
src/flt_spoe.c:2259:40: warning: passing argument 4 of âspoe_decode_bufferâ from
incompatible pointer type
if (spoe_decode_buffer(&p, end, &str, &sz) == -1)
^
As the already existing code using spoe_decode_buffer() already use such pointers to
uint64_t, in place of pointer to size_t ;), most of this code is in contrib directory,
this simple patch modifies the prototype of spoe_decode_buffer() so that to use a
pointer to uint64_t in place of a pointer to size_t, uint64_t type being the type
finally required for decode_varint().
---
include/proto/spoe.h | 7 +++----
src/flt_spoe.c | 4 ++--
2 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/include/proto/spoe.h b/include/proto/spoe.h
index 1372a7d..002cf7d 100644
--- a/include/proto/spoe.h
+++ b/include/proto/spoe.h
@@ -92,7 +92,7 @@ spoe_encode_frag_buffer(const char *str, size_t len, char **buf, char *end)
* On success, it returns the buffer length and <*buf> is moved after the
* encoded buffer. Otherwise, it returns -1. */
static inline int
-spoe_decode_buffer(char **buf, char *end, char **str, size_t *len)
+spoe_decode_buffer(char **buf, char *end, char **str, uint64_t *len)
{
char *p = *buf;
uint64_t sz;
@@ -248,8 +248,7 @@ spoe_skip_data(char **buf, char *end)
{
char *str, *p = *buf;
int type, ret;
- size_t sz;
- uint64_t v;
+ uint64_t v, sz;
if (p >= end)
return -1;
@@ -296,7 +295,7 @@ spoe_decode_data(char **buf, char *end, struct sample *smp)
{
char *str, *p = *buf;
int type, r = 0;
- size_t sz;
+ uint64_t sz;
if (p >= end)
return -1;
diff --git a/src/flt_spoe.c b/src/flt_spoe.c
index 5d57447..1a8bd2c 100644
--- a/src/flt_spoe.c
+++ b/src/flt_spoe.c
@@ -655,7 +655,7 @@ spoe_handle_agenthello_frame(struct appctx *appctx, char *frame, size_t size)
vsn = max_frame_size = flags = 0;
while (p < end) {
char *str;
- size_t sz;
+ uint64_t sz;
int ret;
/* Decode the item key */
@@ -836,7 +836,7 @@ spoe_handle_agentdiscon_frame(struct appctx *appctx, char *frame, size_t size)
/* Loop on K/V items */
while (p < end) {
char *str;
- size_t sz;
+ uint64_t sz;
int ret;
/* Decode the item key */
--
2.1.4