From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl0-f53.google.com (mail-pl0-f53.google.com [209.85.160.53]) by dpdk.org (Postfix) with ESMTP id 94BE94C88 for ; Thu, 16 Aug 2018 17:31:13 +0200 (CEST) Received: by mail-pl0-f53.google.com with SMTP id j8-v6so2252990pll.12 for ; Thu, 16 Aug 2018 08:31:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=HyKyCEA9ATAGcXoMz8nXarftmoz8HvVZtolopxyL8io=; b=FGk1vWDIKevZXf4YcDSrwo0d7n5ogwil9bqP+8xVXimXwqVOJiV4Vu05Ph6xzwTxtf 9yxS0ZCn+PdPkbRBGIfN+DXOjCderZaJnAnPJQvVjW9Min9zN7y3K+P6cM0PintD19xe p8meHT09OHWZGsDf83op31T1gdd9LeL5UtWMkyt781p/6rY7Q6kD/C0Cmb3HD8hfrmpi QPZM9g+FD4iow5F29SuC8VRlLYMkfRhbT37pHkEkJ0SZ16WNW1EdIJSL+/Ng4EMI8yHr DDaqCj5ygrg8YfV3By+Lmn41Ny/8Fv7C1N4OFZy7oH6RY3HgOyPr0iFLvSfQ0VhXwXSG oM+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=HyKyCEA9ATAGcXoMz8nXarftmoz8HvVZtolopxyL8io=; b=K7aHrvB6IAQhyG3ac7QLU0kDgX6ncKIdEHAk3BwkJ6VtHYhtQfcsRtAYnVAL4AUeU4 868tGz0v7l3mRfshPP7HDcpvXXIK5UTMLsjjGQ9zNyZXldKdDIDmHH9EXj5rx/gA6rYw Z6TWGGVCtfOmV03MrlFJNOCZznOIBBBF74GkFP6K/evRwQEDoz44DGR89FxgMIiHaxr/ 29TxetK2//b2dwJ4M+RYAglyFET5X7iYHQK6g6KhwsvDIK7i7YcDAOXPuPUl6TGLu7xy /93h0TiNA1ec7v5MJI/Cek+jhSA3jlzvf1XeeM3G2d77FTmU7P81kcyH1BGx1nbkQnR+ UY1Q== X-Gm-Message-State: AOUpUlGhezmifsw82F8TishtbS/Lq2wBOvE1oa6qqu8r0Lk6VKKLUg/6 l0KMU7OT/BB32dUa7g3gxPkcUvdzgoPqzg== X-Google-Smtp-Source: AA+uWPx0QPtp5BQZOOW+qTwHlvQPkZNqy4vsF69LBSEFhdhkpyS8VmLKEDK6K67hmd881t/iR1HqEg== X-Received: by 2002:a17:902:561:: with SMTP id 88-v6mr29191430plf.320.1534433472334; Thu, 16 Aug 2018 08:31:12 -0700 (PDT) Received: from xeon-e3.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id p5-v6sm30002104pfn.57.2018.08.16.08.31.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Aug 2018 08:31:11 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Thu, 16 Aug 2018 08:31:06 -0700 Message-Id: <20180816153106.7608-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180816153106.7608-1-stephen@networkplumber.org> References: <20180816153106.7608-1-stephen@networkplumber.org> Subject: [dpdk-dev] [PATCH 2/2] hexdump: align output of string X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Aug 2018 15:31:14 -0000 This fixes the issue where if the length of the output is not a multiple of 16 the formatting was off. Before: 00000000: 45 00 00 1C 12 34 2C E0 40 06 B8 2E C0 A8 01 12 | E....4,.@....... 00000010: C0 A8 01 37 | | | | | | | | | | | | | ...7 After: 00000000: 45 00 00 1C 12 34 2C E0 40 06 B8 2E C0 A8 01 12 | E....4,.@....... 00000010: C0 A8 01 37 | ...7 Signed-off-by: Stephen Hemminger --- lib/librte_eal/common/eal_common_hexdump.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/librte_eal/common/eal_common_hexdump.c b/lib/librte_eal/common/eal_common_hexdump.c index 980cf73ac337..19c2d86c693e 100644 --- a/lib/librte_eal/common/eal_common_hexdump.c +++ b/lib/librte_eal/common/eal_common_hexdump.c @@ -22,9 +22,16 @@ void rte_hexdump(FILE *f, const char *title, const void *buf, unsigned int len) while (ofs < len) { /* format the line in the buffer */ out = snprintf(line, LINE_LEN, "%08X:", ofs); - for (i = 0; i < 16 && ofs + i < len; i++) - out += snprintf(line + out, LINE_LEN - out, + for (i = 0; i < 16; i++) { + if (ofs + i < len) + snprintf(line + out, LINE_LEN - out, " %02X", (data[ofs + i] & 0xff)); + else + strcpy(line + out, " "); + out += 3; + } + + for (; i <= 16; i++) out += snprintf(line + out, LINE_LEN - out, " | "); -- 2.18.0