From: Stephen Hemminger <stephen@networkplumber.org>
To: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH iproute2] json_print: fix print_uint hidden type promotion
Date: Thu, 29 Mar 2018 14:02:37 -0700 [thread overview]
Message-ID: <20180329140237.7bb711fc@xeon-e3> (raw)
In-Reply-To: <20180329192220.30101-1-ldir@darbyshire-bryant.me.uk>
On Thu, 29 Mar 2018 20:22:20 +0100
Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk> wrote:
> print_int used 'int' type internally, whereas print_uint used 'uint64_t'
>
> These helper functions eventually call vfprintf(fp, fmt, args) which is
> a variable argument list function and is dependent upon 'fmt' containing
> correct information about the length of the passed arguments.
>
> Unfortunately print_int v print_uint offered no clue to the programmer
> that internally passed ints to print_uint were being promoted to 64bits,
> thus the format passed in 'fmt' string vs the actual passed integer
> could be different lengths. This is even more interesting on big endian
> architectures where 'vfprintf' would be looking in the middle of an
> int64 type.
>
> print_u/int now stick with native int size.
>
> Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
> ---
> include/json_print.h | 2 +-
> lib/json_print.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/include/json_print.h b/include/json_print.h
> index 2ca7830a..45bc653d 100644
> --- a/include/json_print.h
> +++ b/include/json_print.h
> @@ -56,10 +56,10 @@ void close_json_array(enum output_type type, const char *delim);
> print_color_##type_name(t, COLOR_NONE, key, fmt, value); \
> }
> _PRINT_FUNC(int, int);
> +_PRINT_FUNC(uint, unsigned int);
> _PRINT_FUNC(bool, bool);
> _PRINT_FUNC(null, const char*);
> _PRINT_FUNC(string, const char*);
> -_PRINT_FUNC(uint, uint64_t);
> _PRINT_FUNC(hu, unsigned short);
> _PRINT_FUNC(hex, unsigned int);
> _PRINT_FUNC(0xhex, unsigned int);
> diff --git a/lib/json_print.c b/lib/json_print.c
> index 6518ba98..8d54d1d4 100644
> --- a/lib/json_print.c
> +++ b/lib/json_print.c
> @@ -117,8 +117,8 @@ void close_json_array(enum output_type type, const char *str)
> } \
> }
> _PRINT_FUNC(int, int);
> +_PRINT_FUNC(uint, unsigned int);
> _PRINT_FUNC(hu, unsigned short);
> -_PRINT_FUNC(uint, uint64_t);
> _PRINT_FUNC(lluint, unsigned long long int);
> _PRINT_FUNC(float, double);
> #undef _PRINT_FUNC
I am concerned that this will break output of 64 bit statistics on 32 bit hosts.
next prev parent reply other threads:[~2018-03-29 21:02 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-29 19:22 [PATCH iproute2] json_print: fix print_uint hidden type promotion Kevin Darbyshire-Bryant
2018-03-29 21:02 ` Stephen Hemminger [this message]
2018-03-29 21:29 ` Kevin Darbyshire-Bryant
2018-04-25 14:30 ` [PATCH iproute2 v2] json_print: Fix hidden 64-bit " Toke Høiland-Jørgensen
2018-04-25 14:55 ` Stephen Hemminger
2018-04-25 14:57 ` Toke Høiland-Jørgensen
2018-04-25 15:12 ` Stephen Hemminger
2018-04-25 15:28 ` [PATCH iproute2 v3] " Toke Høiland-Jørgensen
2018-04-25 18:11 ` Stephen Hemminger
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=20180329140237.7bb711fc@xeon-e3 \
--to=stephen@networkplumber.org \
--cc=ldir@darbyshire-bryant.me.uk \
--cc=netdev@vger.kernel.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 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).