From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by dpdk.org (Postfix) with ESMTP id 60716378B for ; Tue, 2 Apr 2019 17:23:59 +0200 (CEST) Received: by mail-pg1-f195.google.com with SMTP id v12so6757639pgq.1 for ; Tue, 02 Apr 2019 08:23:59 -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=1iTJ2Ft983o/dXIRYncBU1LPb5ON3q3vZlUq5R1N/Bo=; b=ubPA/8053IwZkL+2t2PFqCitHDhPrZZoqIxJDW1vV/Fdz+c9yz1YdotCudrLvccbm0 GJDFvSrsIL6feI7eaKvyhR98vi1ZuUBdfDI3LeWpfIQB5L3uF18Jqbjo/bKHHI0Md/m7 c4rov/UAAcybUqzMr82/zLcNKrbN93XEHSH6Elv7HYvj5YmLmNNGDXOjllX4fKzDTrbN tHlsAhoupmyYz4w5rE8An7dZzAhByzCs+uzCQ94itS1CEc0P1yo51gJ7RD3HE9O0gW4c 14IHV+1nH+H3no03IPrHbWKjuzgM85I/pwtB2hIBeA/dswVjVbCYvy4hIv//eUxRPj9k VS1w== 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=1iTJ2Ft983o/dXIRYncBU1LPb5ON3q3vZlUq5R1N/Bo=; b=gvZUNN95MWrkoJY/9cYZwlort9wtPwi3Fcqj0ijM7g9M+TdVy11nT5e1TWjy98tsag 6SWY2ILgBrW4v+7ucKKbpZBKFYhwbyvp1KoEMLJSWUdjFJ47zdqFbx/nTVgRBsCH/JpE xfebP3N6QhHsalcoR2fFh7/nsOqi1r65pa8FMEcOUjd5H4UZRpqa0ZK/TUJDsv3MND1x /L+KdX/gbSIhuQ4Rk7CMIZrzRHuCSAfZTN1dzvI6MMVOTjXZuG69N6ChNwGEn4XDhqVC NLXee4WiT/S2Dg6vAluKo1oVzIT4Yw3JZ6uG/KFBNL4GXMYCdrJ8ELmF1AYcsK3GcYO6 0hGw== X-Gm-Message-State: APjAAAXZE6e33iVv3mgLesfqs1f7Rs4+O6pxo/OmdWZ4LTQKOJot2aRL kRY7CZ3De6+ZjeTce0uMFBKVHzjbOx63VQ== X-Google-Smtp-Source: APXvYqysmkIYYJdRbvKTYIw0Sors0iw1AgXOYf7dkx0RNbZsj7UhWJYUSNQjS+5PUkzGRgNyY0FRzg== X-Received: by 2002:aa7:9095:: with SMTP id i21mr47432676pfa.134.1554218638153; Tue, 02 Apr 2019 08:23:58 -0700 (PDT) Received: from shemminger-XPS-13-9360.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id p6sm5302514pfd.122.2019.04.02.08.23.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Apr 2019 08:23:56 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Tue, 2 Apr 2019 08:23:50 -0700 Message-Id: <20190402152350.17572-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190402152350.17572-1-stephen@networkplumber.org> References: <20180816153106.7608-1-stephen@networkplumber.org> <20190402152350.17572-1-stephen@networkplumber.org> Subject: [dpdk-dev] [PATCH v2 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: Tue, 02 Apr 2019 15:23:59 -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 6af818beb3cb..2d2179d4114e 100644 --- a/lib/librte_eal/common/eal_common_hexdump.c +++ b/lib/librte_eal/common/eal_common_hexdump.c @@ -23,9 +23,16 @@ 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.17.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 9B49CA0679 for ; Tue, 2 Apr 2019 17:24:13 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A2FF94CA0; Tue, 2 Apr 2019 17:24:02 +0200 (CEST) Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by dpdk.org (Postfix) with ESMTP id 60716378B for ; Tue, 2 Apr 2019 17:23:59 +0200 (CEST) Received: by mail-pg1-f195.google.com with SMTP id v12so6757639pgq.1 for ; Tue, 02 Apr 2019 08:23:59 -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=1iTJ2Ft983o/dXIRYncBU1LPb5ON3q3vZlUq5R1N/Bo=; b=ubPA/8053IwZkL+2t2PFqCitHDhPrZZoqIxJDW1vV/Fdz+c9yz1YdotCudrLvccbm0 GJDFvSrsIL6feI7eaKvyhR98vi1ZuUBdfDI3LeWpfIQB5L3uF18Jqbjo/bKHHI0Md/m7 c4rov/UAAcybUqzMr82/zLcNKrbN93XEHSH6Elv7HYvj5YmLmNNGDXOjllX4fKzDTrbN tHlsAhoupmyYz4w5rE8An7dZzAhByzCs+uzCQ94itS1CEc0P1yo51gJ7RD3HE9O0gW4c 14IHV+1nH+H3no03IPrHbWKjuzgM85I/pwtB2hIBeA/dswVjVbCYvy4hIv//eUxRPj9k VS1w== 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=1iTJ2Ft983o/dXIRYncBU1LPb5ON3q3vZlUq5R1N/Bo=; b=gvZUNN95MWrkoJY/9cYZwlort9wtPwi3Fcqj0ijM7g9M+TdVy11nT5e1TWjy98tsag 6SWY2ILgBrW4v+7ucKKbpZBKFYhwbyvp1KoEMLJSWUdjFJ47zdqFbx/nTVgRBsCH/JpE xfebP3N6QhHsalcoR2fFh7/nsOqi1r65pa8FMEcOUjd5H4UZRpqa0ZK/TUJDsv3MND1x /L+KdX/gbSIhuQ4Rk7CMIZrzRHuCSAfZTN1dzvI6MMVOTjXZuG69N6ChNwGEn4XDhqVC NLXee4WiT/S2Dg6vAluKo1oVzIT4Yw3JZ6uG/KFBNL4GXMYCdrJ8ELmF1AYcsK3GcYO6 0hGw== X-Gm-Message-State: APjAAAXZE6e33iVv3mgLesfqs1f7Rs4+O6pxo/OmdWZ4LTQKOJot2aRL kRY7CZ3De6+ZjeTce0uMFBKVHzjbOx63VQ== X-Google-Smtp-Source: APXvYqysmkIYYJdRbvKTYIw0Sors0iw1AgXOYf7dkx0RNbZsj7UhWJYUSNQjS+5PUkzGRgNyY0FRzg== X-Received: by 2002:aa7:9095:: with SMTP id i21mr47432676pfa.134.1554218638153; Tue, 02 Apr 2019 08:23:58 -0700 (PDT) Received: from shemminger-XPS-13-9360.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id p6sm5302514pfd.122.2019.04.02.08.23.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Apr 2019 08:23:56 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Tue, 2 Apr 2019 08:23:50 -0700 Message-Id: <20190402152350.17572-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190402152350.17572-1-stephen@networkplumber.org> References: <20180816153106.7608-1-stephen@networkplumber.org> <20190402152350.17572-1-stephen@networkplumber.org> Subject: [dpdk-dev] [PATCH v2 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Content-Type: text/plain; charset="UTF-8" Message-ID: <20190402152350.8-xVaBdbwZnjE_GTYROUomS6idhomFpRuojznYgH8JA@z> 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 6af818beb3cb..2d2179d4114e 100644 --- a/lib/librte_eal/common/eal_common_hexdump.c +++ b/lib/librte_eal/common/eal_common_hexdump.c @@ -23,9 +23,16 @@ 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.17.1