This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch 11.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/11.0.x by this push:
new 4b2f078605 Fix an edge case in MessageBytes.setLong() for
Long.MIN_VALUE
4b2f078605 is described below
commit 4b2f078605597f8637261d8bd01122a9ec584390
Author: Mark Thomas <[email protected]>
AuthorDate: Thu May 21 10:28:34 2026 +0100
Fix an edge case in MessageBytes.setLong() for Long.MIN_VALUE
---
java/org/apache/tomcat/util/buf/MessageBytes.java | 11 ++++-------
test/org/apache/tomcat/util/buf/TestMessageBytes.java | 19 +++++++++++++++++++
2 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/java/org/apache/tomcat/util/buf/MessageBytes.java
b/java/org/apache/tomcat/util/buf/MessageBytes.java
index 9e59dc397a..205879f2e4 100644
--- a/java/org/apache/tomcat/util/buf/MessageBytes.java
+++ b/java/org/apache/tomcat/util/buf/MessageBytes.java
@@ -623,17 +623,14 @@ public final class MessageBytes implements Cloneable,
Serializable {
buf[end++] = (byte) '0';
}
if (l < 0) {
- if (l == Long.MIN_VALUE) {
- current = Long.MAX_VALUE;
- } else {
- current = -l;
- }
buf[end++] = (byte) '-';
+ } else {
+ current = -l;
}
- while (current > 0) {
+ while (current < 0) {
int digit = (int) (current % 10);
current = current / 10;
- buf[end++] = HexUtils.getHex(digit);
+ buf[end++] = HexUtils.getHex(-digit);
}
byteC.setStart(0);
byteC.setEnd(end);
diff --git a/test/org/apache/tomcat/util/buf/TestMessageBytes.java
b/test/org/apache/tomcat/util/buf/TestMessageBytes.java
index a1063a599c..3bfac645a5 100644
--- a/test/org/apache/tomcat/util/buf/TestMessageBytes.java
+++ b/test/org/apache/tomcat/util/buf/TestMessageBytes.java
@@ -76,4 +76,23 @@ public class TestMessageBytes {
Assert.assertTrue(mb1.equals(mb2));
}
+
+
+ @Test
+ public void testSetLong() {
+ doTestSetLong(0);
+ doTestSetLong(-1);
+ doTestSetLong(1);
+ doTestSetLong(-12345);
+ doTestSetLong(12345);
+ doTestSetLong(Long.MIN_VALUE);
+ doTestSetLong(Long.MAX_VALUE);
+ }
+
+
+ private void doTestSetLong(long l) {
+ MessageBytes mb = MessageBytes.newInstance();
+ mb.setLong(l);
+ Assert.assertEquals(mb.toStringType(), Long.toString(l));
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]