You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ns...@apache.org on 2016/08/20 09:42:34 UTC

[3/4] thrift git commit: THRIFT-3827 Fix CompactProtocol readI64 function

THRIFT-3827 Fix CompactProtocol readI64 function

cleanup (#1054)


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/527637ac
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/527637ac
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/527637ac

Branch: refs/heads/master
Commit: 527637ac3c75df0a87253ddbf41edc3a27ddd802
Parents: 77e5f3a
Author: Nobuaki Sukegawa <ns...@apache.org>
Authored: Sun Jul 24 15:28:46 2016 +0900
Committer: Nobuaki Sukegawa <ns...@gmail.com>
Committed: Sat Aug 20 18:40:41 2016 +0900

----------------------------------------------------------------------
 .../lib/Thrift/Protocol/TCompactProtocol.php    | 79 ++++++++------------
 1 file changed, 30 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/527637ac/lib/php/lib/Thrift/Protocol/TCompactProtocol.php
----------------------------------------------------------------------
diff --git a/lib/php/lib/Thrift/Protocol/TCompactProtocol.php b/lib/php/lib/Thrift/Protocol/TCompactProtocol.php
index 124f6ec..7b966aa 100644
--- a/lib/php/lib/Thrift/Protocol/TCompactProtocol.php
+++ b/lib/php/lib/Thrift/Protocol/TCompactProtocol.php
@@ -607,15 +607,14 @@ class TCompactProtocol extends TProtocol
       $arr = unpack('C', $x);
       $byte = $arr[1];
       $idx += 1;
-      if ($shift < 32) {
-        $lo |= (($byte & 0x7f) << $shift) &
-          0x00000000ffffffff;
-      }
       // Shift hi and lo together.
-      if ($shift >= 32) {
+      if ($shift < 28) {
+        $lo |= (($byte & 0x7f) << $shift);
+      } elseif ($shift == 28) {
+        $lo |= (($byte & 0x0f) << 28);
+        $hi |= (($byte & 0x70) >> 4);
+      } else {
         $hi |= (($byte & 0x7f) << ($shift - 32));
-      } elseif ($shift > 25) {
-        $hi |= (($byte & 0x7f) >> ($shift - 24));
       }
       if (($byte >> 7) === 0) {
         break;
@@ -634,56 +633,38 @@ class TCompactProtocol extends TProtocol
     $lo = $lo ^ $xorer;
 
     // Now put $hi and $lo back together
-    if (true) {
-      $isNeg = $hi  < 0 || $hi & 0x80000000;
-
-      // Check for a negative
-      if ($isNeg) {
-        $hi = ~$hi & (int) 0xffffffff;
-        $lo = ~$lo & (int) 0xffffffff;
-
-        if ($lo == (int) 0xffffffff) {
-          $hi++;
-          $lo = 0;
-        } else {
-          $lo++;
-        }
-      }
+    $isNeg = $hi < 0 || $hi & 0x80000000;
 
-      // Force 32bit words in excess of 2G to be positive - we deal with sign
-      // explicitly below
+    // Check for a negative
+    if ($isNeg) {
+      $hi = ~$hi & (int) 0xffffffff;
+      $lo = ~$lo & (int) 0xffffffff;
 
-      if ($hi & (int) 0x80000000) {
-        $hi &= (int) 0x7fffffff;
-        $hi += 0x80000000;
+      if ($lo == (int) 0xffffffff) {
+        $hi++;
+        $lo = 0;
+      } else {
+        $lo++;
       }
+    }
 
-      if ($lo & (int) 0x80000000) {
-        $lo &= (int) 0x7fffffff;
-        $lo += 0x80000000;
-      }
+    // Force 32bit words in excess of 2G to be positive - we deal with sign
+    // explicitly below
 
-      $value = $hi * 4294967296 + $lo;
+    if ($hi & (int) 0x80000000) {
+      $hi &= (int) 0x7fffffff;
+      $hi += 0x80000000;
+    }
 
-      if ($isNeg) {
-        $value = 0 - $value;
-      }
-    } else {
+    if ($lo & (int) 0x80000000) {
+      $lo &= (int) 0x7fffffff;
+      $lo += 0x80000000;
+    }
 
-      // Upcast negatives in LSB bit
-      if ($arr[2] & 0x80000000) {
-        $arr[2] = $arr[2] & 0xffffffff;
-      }
+    $value = $hi * 4294967296 + $lo;
 
-      // Check for a negative
-      if ($arr[1] & 0x80000000) {
-        $arr[1] = $arr[1] & 0xffffffff;
-        $arr[1] = $arr[1] ^ 0xffffffff;
-        $arr[2] = $arr[2] ^ 0xffffffff;
-        $value = 0 - $arr[1] * 4294967296 - $arr[2] - 1;
-      } else {
-        $value = $arr[1] * 4294967296 + $arr[2];
-      }
+    if ($isNeg) {
+      $value = 0 - $value;
     }
 
     return $idx;