[php-src] Issue #8007: FFI::cast() from pointer returns incorrect value

From: Date: Sat, 29 Jan 2022 00:22:04 +0000
Subject: [php-src] Issue #8007: FFI::cast() from pointer returns incorrect value
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-239339@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/8007 Author: userqq ### Description Hi! I mentioned in https://github.com/php/php-src/issues/7904 casting from pointer to integer. While https://github.com/php/php-src/issues/7904 still relevant, I found it also casts wrong data when casting from pointer to int ```php $val = FFI::new('char[8]'); FFI::memcpy($val, implode('', range('a', 'h')), 8); $firstInt = FFI::cast('int32_t', $val); var_dump($firstInt); $secondInt = FFI::cast('int32_t', $val + 4); var_dump($secondInt); var_dump(unpack('Nfirst/Nsecond', implode('', range('a', 'h')))); ``` Resulted in this output: ``` object(FFI\CData:int32_t)#2 (1) { ["cdata"]=> int(1684234849) } object(FFI\CData:int32_t)#4 (1) { ["cdata"]=> int(-423620580) // any random int32 actually } array(2) { ["first"]=> int(1633837924) ["second"]=> int(1701209960) } ``` But I expected this output instead: ``` object(FFI\CData:int32_t)#2 (1) { ["cdata"]=> int(1684234849) } object(FFI\CData:int32_t)#4 (1) { ["cdata"]=> int(1701209960) } array(2) { ["first"]=> int(1633837924) ["second"]=> int(1701209960) } ``` ### PHP Version 8.1.1, 8.1.2 ### Operating System _No response_

« previous php.bugs (#239339) next »