Fixed signed VarInt encoding on 64-bit systems

Numbers represented as hex or binary with the 32nd bit set, for example 0xffffffff, were not considered as signed on 64-bit.
This commit is contained in:
Dylan K. Taylor 2017-03-09 12:23:24 +00:00
parent 94d78ca554
commit f8c2eb8c3a

View File

@ -381,7 +381,10 @@ class Binary{
* @return string
*/
public static function writeVarInt($v){
return self::writeUnsignedVarInt(($v << 1) ^ ($v >> (PHP_INT_SIZE === 8 ? 63 : 31)));
if(PHP_INT_SIZE === 8){
$v = ($v << 32 >> 32);
}
return self::writeUnsignedVarInt(($v << 1) ^ ($v >> 31));
}
/**