|
12 | 12 | namespace Symfony\Component\VarDumper\Tests\Caster; |
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestCase; |
15 | | -use Symfony\Component\VarDumper\Caster\FFICaster; |
16 | 15 | use Symfony\Component\VarDumper\Test\VarDumperTestTrait; |
17 | 16 |
|
18 | 17 | /** |
@@ -191,34 +190,21 @@ public function testCastCuttedPointerToChar() |
191 | 190 | PHP, $pointer); |
192 | 191 | } |
193 | 192 |
|
194 | | - /** |
195 | | - * It is worth noting that such a test can cause SIGSEGV, as it breaks |
196 | | - * into "foreign" memory. However, this is only theoretical, since |
197 | | - * memory is allocated within the PHP process and almost always "garbage |
198 | | - * data" will be read from the PHP process itself. |
199 | | - * |
200 | | - * If this test fails for some reason, please report it: We may have to |
201 | | - * disable the dumping of strings ("char*") feature in VarDumper. |
202 | | - * |
203 | | - * @see FFICaster::castFFIStringValue() |
204 | | - */ |
205 | 193 | public function testCastNonTrailingCharPointer() |
206 | 194 | { |
207 | 195 | $actualMessage = 'Hello World!'; |
208 | 196 | $actualLength = \strlen($actualMessage); |
209 | 197 |
|
210 | | - $string = \FFI::cdef()->new('char['.$actualLength.']'); |
| 198 | + $string = \FFI::cdef()->new('char['.($actualLength + 1).']'); |
211 | 199 | $pointer = \FFI::addr($string[0]); |
212 | | - |
213 | 200 | \FFI::memcpy($pointer, $actualMessage, $actualLength); |
214 | 201 |
|
215 | | - // Remove automatically addition of the trailing "\0" and remove trailing "\0" |
216 | 202 | $pointer = \FFI::cdef()->cast('char*', \FFI::cdef()->cast('void*', $pointer)); |
217 | 203 | $pointer[$actualLength] = "\x01"; |
218 | 204 |
|
219 | 205 | $this->assertDumpMatchesFormat(<<<PHP |
220 | 206 | FFI\CData<char*> size 8 align 8 { |
221 | | - cdata: "$actualMessage%s" |
| 207 | + cdata: %A"$actualMessage%s" |
222 | 208 | } |
223 | 209 | PHP, $pointer); |
224 | 210 | } |
|
0 commit comments