From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f195.google.com ([209.85.192.195]:44116 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751672AbeCPUeq (ORCPT ); Fri, 16 Mar 2018 16:34:46 -0400 Received: by mail-pf0-f195.google.com with SMTP id m68so4594411pfm.11 for ; Fri, 16 Mar 2018 13:34:45 -0700 (PDT) Date: Fri, 16 Mar 2018 13:34:37 -0700 From: Stephen Hemminger To: Kevin Darbyshire-Bryant Cc: netdev@vger.kernel.org Subject: Re: [PATCH] json_print: fix print_uint with helper type extensions Message-ID: <20180316133437.5f535a0e@xeon-e3> In-Reply-To: <20180315200720.829-1-ldir@darbyshire-bryant.me.uk> References: <20180315200720.829-1-ldir@darbyshire-bryant.me.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: netdev-owner@vger.kernel.org List-ID: On Thu, 15 Mar 2018 20:07:20 +0000 Kevin Darbyshire-Bryant wrote: > Introduce print helper functions for int, uint, explicit int32, uint32, > int64 & uint64. > > 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 and hence produced wildly incorrect values in tc qdisc > output. > > print_u/int now stick with native int size. print_u/int32 & print > u/int64 functions offer explicit integer sizes. > > To portably use these formats you should use the relevant PRIdN or PRIuN > formats as defined in inttypes.h > > e.g. > > print_uint64(PRINT_ANY, "refcnt", "refcnt %" PRIu64 " ", t->tcm_info) > > Signed-off-by: Kevin Darbyshire-Bryant I am fine with this. But since there is no code using it yet, it should go net-next branch. Reviewed-by: Stephen Hemminger