From 1454c3a777bc9ec0852de18249c36f5531d09c9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E4=B8=96=E6=88=90?= Date: Mon, 1 Jul 2019 14:35:18 +0800 Subject: [PATCH] Fix the issue of incorrectly calculating the number of dump lines when using PrettyDump in ByteBufUtil (#9304) Motivation: Fix the issue of incorrectly calculating the number of dump rows when using prettyHexDumpmethod in ByteBufUtil. The way to find the remainder is either length % 16 or length & 15 Modification: Fixed the way to calculate the remainder Result: Fixed #9301 --- buffer/src/main/java/io/netty/buffer/ByteBufUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buffer/src/main/java/io/netty/buffer/ByteBufUtil.java b/buffer/src/main/java/io/netty/buffer/ByteBufUtil.java index e2eddf07a1..1d5bfce1ee 100644 --- a/buffer/src/main/java/io/netty/buffer/ByteBufUtil.java +++ b/buffer/src/main/java/io/netty/buffer/ByteBufUtil.java @@ -1095,7 +1095,7 @@ public final class ByteBufUtil { if (length == 0) { return StringUtil.EMPTY_STRING; } else { - int rows = length / 16 + (length % 15 == 0? 0 : 1) + 4; + int rows = length / 16 + ((length & 15) == 0? 0 : 1) + 4; StringBuilder buf = new StringBuilder(rows * 80); appendPrettyHexDump(buf, buffer, offset, length); return buf.toString();