This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/main by this push:
     new c9024aa552 Reduce duplication. Use correct index in error message.
c9024aa552 is described below

commit c9024aa55281ef46dd06d7705e3d7ac8f60395f6
Author: Mark Thomas <[email protected]>
AuthorDate: Wed Apr 8 15:03:30 2026 +0100

    Reduce duplication. Use correct index in error message.
---
 java/org/apache/coyote/http2/HpackDecoder.java | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/java/org/apache/coyote/http2/HpackDecoder.java 
b/java/org/apache/coyote/http2/HpackDecoder.java
index b9c889eec0..d9f2ec62e4 100644
--- a/java/org/apache/coyote/http2/HpackDecoder.java
+++ b/java/org/apache/coyote/http2/HpackDecoder.java
@@ -238,7 +238,7 @@ public class HpackDecoder {
             return Hpack.STATIC_TABLE[index].name;
         } else {
             // index is 1 based
-            int adjustedIndex = getRealIndex(index - 
Hpack.STATIC_TABLE_LENGTH);
+            int adjustedIndex = getRealIndex(index);
             Hpack.HeaderField res = headerTable[adjustedIndex];
             if (res == null) {
                 throw new 
HpackException(sm.getString("hpackdecoder.nullHeader", Integer.valueOf(index)));
@@ -259,7 +259,7 @@ public class HpackDecoder {
             addStaticTableEntry(index);
         } else {
             // index is 1 based
-            int adjustedIndex = getRealIndex(index - 
Hpack.STATIC_TABLE_LENGTH);
+            int adjustedIndex = getRealIndex(index);
             if (log.isTraceEnabled()) {
                 log.trace(sm.getString("hpackdecoder.useDynamic", 
Integer.valueOf(adjustedIndex)));
             }
@@ -279,14 +279,15 @@ public class HpackDecoder {
      * @return the real index into the array
      */
     int getRealIndex(int index) throws HpackException {
+        int dynamicIndex = index - Hpack.STATIC_TABLE_LENGTH;
         // The index is one based, but our table is zero based
         // Also, because of our ring buffer set up, the indexes are reversed
         // index = 1 is at position firstSlotPosition + filledSlots
-        if (index < 1 || index > filledTableSlots) {
+        if (dynamicIndex < 1 || dynamicIndex > filledTableSlots) {
             throw new 
HpackException(sm.getString("hpackdecoder.headerTableIndexInvalid", 
Integer.valueOf(index),
                     Integer.valueOf(Hpack.STATIC_TABLE_LENGTH), 
Integer.valueOf(filledTableSlots)));
         }
-        return (firstSlotPosition + (filledTableSlots - index)) % 
headerTable.length;
+        return (firstSlotPosition + (filledTableSlots - dynamicIndex)) % 
headerTable.length;
     }
 
     private void addStaticTableEntry(int index) throws HpackException {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to