1
0
mirror of https://github.com/pmmp/ext-encoding.git synced 2024-11-23 13:36:25 +00:00
ext-encoding/tests/read-reserved-memory.phpt
Dylan K. Taylor 56673dd789
Split Types class into several new classes
the main benefit of this is the increased difficulty of accidentally
using the wrong byte order due to auto complete - now choosing byte
order is decided by the first character typed.

however, it also reduces the verbosity of the API, though I'm not sure
about the 'LE' and 'BE' class names.
2024-04-10 16:34:24 +01:00

32 lines
779 B
PHP

--TEST--
Test that ByteBuffer::read*() can't read reserved unused memory
--DESCRIPTION--
Since we may have allocated more memory than we're currently using, we need to make sure that said extra memory isn't readable, otherwise we will return
uninitialized values to PHP.
--FILE--
<?php
use pmmp\encoding\ByteBuffer;
use pmmp\encoding\DataDecodeException;
use pmmp\encoding\Byte;
$buffer = new ByteBuffer("");
$buffer->reserve(100);
try{
var_dump($buffer->readByteArray(10));
}catch(DataDecodeException $e){
echo $e->getMessage() . PHP_EOL;
}
try{
var_dump(Byte::readUnsigned($buffer));
}catch(DataDecodeException $e){
echo $e->getMessage() . PHP_EOL;
}
?>
--EXPECT--
Need at least 10 bytes, but only have 0 bytes
Need at least 1 bytes, but only have 0 bytes