From patchwork Thu Mar 29 19:32:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin 'ldir' Darbyshire-Bryant X-Patchwork-Id: 892931 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=darbyshire-bryant.me.uk Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=darbyshire-bryant.me.uk header.i=@darbyshire-bryant.me.uk header.b="gPTzobvq"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40Bvz01nnTz9s21 for ; Fri, 30 Mar 2018 06:32:28 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752156AbeC2TcZ (ORCPT ); Thu, 29 Mar 2018 15:32:25 -0400 Received: from mail-db5eur01on0077.outbound.protection.outlook.com ([104.47.2.77]:31968 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751096AbeC2TcY (ORCPT ); Thu, 29 Mar 2018 15:32:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=darbyshire-bryant.me.uk; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=GqaJnatE+obU23u455/N9DSyEyrKcQMhMqmbAakLXhc=; b=gPTzobvquziK4AZlMivn4f/UJtI8D+4sV7RUwJO5Zmsa+5apQTHN+HKXNK/Rls3JInL0gjW7Y/dN4RkJt5U5XErkJLcPNnXLjnyXcmuOr2/hW1/dnfyLLltD4D4dyYEpMPGDKMji3myS5CJomQzmzgXHUQnd0LCsYy3Y3TGvVns= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=kevin@darbyshire-bryant.me.uk; Received: from Kevins-MBP.darbyshire-bryant.me.uk (151.231.154.194) by VI1PR0702MB3742.eurprd07.prod.outlook.com (2603:10a6:803:7::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.631.5; Thu, 29 Mar 2018 19:32:21 +0000 From: Kevin Darbyshire-Bryant To: netdev@vger.kernel.org Cc: Kevin Darbyshire-Bryant Subject: [PATCH iproute2-next] json_print: fix print_uint with helper type extensions Date: Thu, 29 Mar 2018 20:32:10 +0100 Message-Id: <20180329193210.30415-1-ldir@darbyshire-bryant.me.uk> X-Mailer: git-send-email 2.14.3 (Apple Git-98) MIME-Version: 1.0 X-Originating-IP: [151.231.154.194] X-ClientProxiedBy: AM6PR07CA0019.eurprd07.prod.outlook.com (2603:10a6:209:2a::32) To VI1PR0702MB3742.eurprd07.prod.outlook.com (2603:10a6:803:7::32) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2f8c7f80-3c3a-49c7-e532-08d595abca93 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(7021125)(5600026)(4604075)(4534165)(7022125)(4603075)(4627221)(201702281549075)(7048125)(7024125)(7027125)(7028125)(7023125)(2017052603328)(7153060)(7193020); SRVR:VI1PR0702MB3742; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0702MB3742; 3:n8f9hb7X60tYa1Kw8iZIbQpCINUthbumKCEks68BxuSyCLoDw2NpWLyzADtHv4p6NwUlgroyByqlh26H0XkHh2uCacFly4yV2TaPI9NZ7G1CgDIzzA3eE6QGWu5gyhlKJ32/XlSQQW9srrydJ10RzWprFm5mXNdgCM+kr0a4my4uoaa7WX/GD0zCVWlOyLKwPCSqBA7Nxb2g2o0N4/QKKf+KvEjq2oPtWowGw1R99SbwwBUuUUxzxwZVS1ytvBrI; 25:thGkd2ya9cWgPiQ783z+M6HKbBXKrTLuXGb7PJX8fplFc+C1zj0sV/KkSGdxQJ1S+8awlK/gUiw2ylWJdDisXZ+ZWqMd1q1JWLHlmYrU8zSVwupPsFAt8uZki4VulvM5cCuzQkZ1pYEjTD8h/+56V6f6HcLlAaHWOllSLj0Iw1OYh7hbIa5nqrZ2R2X0oAUs7U9/NchLM7p+6W3pSeNL/PqqzTIfg7zzubG4VZ/8e8fdm7IYlY44yNkdETJvYuaMm0Pnvr/T52cNBgcrajfWQP+q+hF9WXcvLLdoQ7zbNJtxuD02MHTRGxfO2Sa7pC8sOyJU/t3kRRCcvMeufCHhKA==; 31:9zIx7z1UqJtAE0A1pxIyVaqSheBWFJsUEmOBOYIIWnp34gMPbDki4mQ2h713OxeFO1ZOq8mNny/mH8kudThfvRhlnt9tiRxsCjXs5uNSkopczJ3SY/D//2D/cXJXxM18zAHUPpLUXURuUDuivUIOzF4buEDOz6TRRZuoHCDMXjpmfHg+ZvHsFYtWXwq8J57jo3sPoEWOSNUnETh0GyzYahpb0BLkx6T4TCMvxJBRMNk= X-MS-TrafficTypeDiagnostic: VI1PR0702MB3742: X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(8121501046)(5005006)(3231221)(944501327)(52105095)(3002001)(93006095)(93001095)(10201501046)(6041310)(20161123562045)(2016111802025)(20161123558120)(20161123564045)(20161123560045)(6043046)(6072148)(201708071742011); SRVR:VI1PR0702MB3742; BCL:0; PCL:0; RULEID:; SRVR:VI1PR0702MB3742; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0702MB3742; 4:6WMrq/IIfe96GThuo5/0P5nOdmRxGF7NUYDS5o23wNecjuRHyjHdCDf6NkYH0E7M4npXKenNJpD/jnYjZWFzN0NN2bYkvoGdMXmyjN0QHJHE3IPB3FyoNSx3a7dO7eG28r6qB2/0BAeX0VYi6Nv4TzGurICTaaOtLnoO/nx4bKJIxcgdY9KLUO4auK4QBXeLoO+Pl4IvM+D9JpWgwiKxIiwTDIXj1e3/GWqlO4FHsOXGp3BeCqebgP+yJY9egzAQIFebs0KuGt2NcVrEM1ZryA== X-Forefront-PRVS: 0626C21B10 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(376002)(396003)(346002)(366004)(39830400003)(39380400002)(189003)(199004)(5660300001)(1076002)(6666003)(74482002)(53416004)(105586002)(386003)(4326008)(59450400001)(47776003)(6486002)(36756003)(6916009)(51416003)(69596002)(6116002)(66066001)(3846002)(7696005)(52116002)(2351001)(26005)(107886003)(53936002)(16526019)(8936002)(478600001)(2361001)(2906002)(305945005)(186003)(316002)(68736007)(486005)(2616005)(50466002)(106356001)(7736002)(50226002)(476003)(8676002)(486005)(81156014)(16586007)(25786009)(48376002)(81166006)(97736004)(956004); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0702MB3742; H:Kevins-MBP.darbyshire-bryant.me.uk; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: darbyshire-bryant.me.uk does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: 1; VI1PR0702MB3742; 23:RpiuRLAu+B19nV9Oa4ET3dLiWroknnC8HrbwhCdnUrk10zvP+FYAnUXQDFveDOV9ylgKjVjqpDWQObgCKAXJkCeu3vNWe2anORh/vHtCcM4Du08ZmWGZwUKLQsA6xPMqF5OuZ5cd5xO65xUyqNh9j7vl17+mETSn02rrkZv5MfmnKXWEbtSH18ghWHY1ZQiWb0cxqiOK8WTlJV77ZgmMiUYX7KQoIaWXobEhsDKaqHMBkqiJ5tflMmc2sz5rvKCAl6FA7n9tM9nK9pn/OrTBprG4mj7NRGF/drRC7ZMSxr1V1R3bkrm+4aKQgoTMvFhVzr+GtdNVwvqKJyX8kCqgKnC8alBQJLr+fxfv5msvwgDN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H6U58vd0A+AfnUZ82eL/OQe3YimCKCjWh9m4laN56D X-Microsoft-Exchange-Diagnostics: 1; VI1PR0702MB3742; 6:I4MRP9MBicofoh1lp4h8j/00Esba/qvnyZopEbh0sEpoxwV52a2FiM9g5L9uVrrh08Ga0u2gbMMp0MXFbhrdLGn5/Z8SRv83z1582ucW37ILgBA8LmchML/AuSu2iQyQMREL+d+Rp6UFYMal+Pj/Dg5UF1BjPoapCjcL2Hk6V3cdBHNIQF2Aaa/qouqmnF9HT8i7RSWL0wMKuySKQx9LLw8PxiTP1qUHDp61WriPi1/vSDDdIHGJvDkwLIqFjcp7DE+M44Dx+DNgJkHC1ppsbUpC3Z/i/f1Cc7U5Tia8s0DlBIxyv9AYO43881NxXLvgcmrpaCkL3EojGVAhwuJZRHMSenxHqk9vyueecijuuAnVnQ+Dt62uDBwIfqPadJkKp4KRpwOwugYPWz5DacvHqim5h1E3iRvG+IphwTGWYH0lwPntGn3bWuyXjkEljyBMkEAbTVjUts5zxtCK5VikOg==; 5:1RJI7eyH2hBcMICJsoBTnBfApe/hHMD5b0eZx6OdgQLY9vFdskx0suM3pKtyyOLI7k2lr0xGq7JiENa7dM19RbYHViR/UQHVzywIEVX1wm+F2XHnM4Eu37Dw+8UlKePkyhCEZGCP6wl5dISnPbwwG7sPeprZTKL/whn397Yom+Q=; 24:t4NAMS3cBH+/q5eVYWtCo8fLZKVirPQ0F2BI6wuQe1sMAx1eRiEjvOwFBZLP9RzcO6x+xxIXAAOhhLsssDihdSHwzQQWua2MsJeTcxbmNvo= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR0702MB3742; 7:Ku5M42O0WAWTfav/4u4/pH0GyVg7jUgwPhDkgN/BSYPqSR8e5HWWFVHgXyc7aABryHXK5+K6U5miry9wI/8bDMnV4OkMI0tqxpZgNB/fBCrWJdtLLY9ZRhSpDu4P+ktexVj75f9nWVfbsssx3QTt4KuPUGB+PGoEiwhw6HKXS6cMkhRiYhW4jqEFe++MGFqmIMhpB4HMGrMP7wzCUrHPcawYMqjLMPvoEYwX98dlRlBZtKIx0ZLSZgd1x+DtxYDi X-OriginatorOrg: darbyshire-bryant.me.uk X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2018 19:32:21.1788 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2f8c7f80-3c3a-49c7-e532-08d595abca93 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 9151708b-c553-406f-8e56-694f435154a4 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0702MB3742 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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. 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 --- include/json_print.h | 6 +++++- lib/json_print.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/json_print.h b/include/json_print.h index 2ca7830a..fb62b142 100644 --- a/include/json_print.h +++ b/include/json_print.h @@ -56,10 +56,14 @@ 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(int32, int32_t); +_PRINT_FUNC(uint32, uint32_t); +_PRINT_FUNC(int64, int64_t); +_PRINT_FUNC(uint64, 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 bda72933..1194a6ec 100644 --- a/lib/json_print.c +++ b/lib/json_print.c @@ -116,8 +116,12 @@ 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(int32, int32_t); +_PRINT_FUNC(uint32, uint32_t); +_PRINT_FUNC(int64, int64_t); +_PRINT_FUNC(uint64, uint64_t); _PRINT_FUNC(lluint, unsigned long long int); _PRINT_FUNC(float, double); #undef _PRINT_FUNC