Commit 77fbdd28 authored by Armen Baghumian's avatar Armen Baghumian

Correct the max/min signed/unsigned 32-bit int

The test was trying to pack an unsigned int which couldn't fit as a
signed int and putInt() wasn't doing the validation in the correct range
parent fe2f8d32
...@@ -239,7 +239,9 @@ class ByteBuffer ...@@ -239,7 +239,9 @@ class ByteBuffer
*/ */
public function putInt($offset, $value) public function putInt($offset, $value)
{ {
self::validateValue(~PHP_INT_MAX, PHP_INT_MAX, $value, "int"); // 2147483647 = (1 << 31) -1 = Maximum signed 32-bit int
// -2147483648 = -1 << 31 = Minimum signed 32-bit int
self::validateValue(-2147483648, 2147483647, $value, "int");
$this->assertOffsetAndLength($offset, 4); $this->assertOffsetAndLength($offset, 4);
$this->writeLittleEndian($offset, 4, $value); $this->writeLittleEndian($offset, 4, $value);
...@@ -252,7 +254,8 @@ class ByteBuffer ...@@ -252,7 +254,8 @@ class ByteBuffer
public function putUint($offset, $value) public function putUint($offset, $value)
{ {
// NOTE: We can't put big integer value. this is PHP limitation. // NOTE: We can't put big integer value. this is PHP limitation.
self::validateValue(0, PHP_INT_MAX, $value, "uint", " php has big numbers limitation. check your PHP_INT_MAX"); // 4294967295 = (1 << 32) -1 = Maximum unsigned 32-bin int
self::validateValue(0, 4294967295, $value, "uint", " php has big numbers limitation. check your PHP_INT_MAX");
$this->assertOffsetAndLength($offset, 4); $this->assertOffsetAndLength($offset, 4);
$this->writeLittleEndian($offset, 4, $value); $this->writeLittleEndian($offset, 4, $value);
......
...@@ -192,7 +192,7 @@ function fuzzTest1(Assert $assert) ...@@ -192,7 +192,7 @@ function fuzzTest1(Assert $assert)
$uchar_val = 0xFF; $uchar_val = 0xFF;
$short_val = -32222; // 0x8222; $short_val = -32222; // 0x8222;
$ushort_val = 0xFEEE; $ushort_val = 0xFEEE;
$int_val = 0x83333333 | 0; $int_val = 0x7fffffff | 0;
// for now // for now
$uint_val = 1; $uint_val = 1;
$long_val = 2; $long_val = 2;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment