#31247 [Bgs]: Incorrect C code in unpack.c causes misbehavior and warnings

From: Date: Thu, 23 Dec 2004 10:49:18 +0000
Subject: #31247 [Bgs]: Incorrect C code in unpack.c causes misbehavior and warnings
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-70964@lists.php.net to get a copy of this message
ID: 31247 User updated by: sefer at hotmail dot com Reported By: sefer at hotmail dot com Status: Bogus Bug Type: Compile Warning Operating System: Linux redhat 9 PHP Version: 4.3.10 New Comment: Alas, you're right. Still, the new release (4.3.10) appears to report a warning where the previous one did not. Although I'm not sure I understand the flaw in this warning. See this example code. <?php $data = "hello world"; $h = unpack('H*hex', $data); ?> Warning: unpack(): Type H: outside of string in /home/test/test.php on line 5 Is there something wrong with the example above? Thanks, Sefer. Previous Comments: ------------------------------------------------------------------------ [2004-12-22 16:17:35] iliaa@php.net Please fix your compiler, the position of the break statment should not matter. ------------------------------------------------------------------------ [2004-12-22 15:52:06] sefer at hotmail dot com Description: ------------ In the recent PHP release 4.3.10 there had been added a bug to the unpack (PHP_FUNCTION(unpack)) function in unpack.c The code that manifests the problem is this: $h = unpack('H*hex', $data); The result would be: Warning: unpack(): Type H: outside of string in /my_file.php on line 20 The reason is a change in the function which using the current compiler (Red Hat Linux 3.2.3-42) generates incorrect behavior when "break" is placed within a curly braces block (within a "switch" statement) which causes break to leave the current scope but then continue falling down through the "switch" elements. For example this code: case 'C': { int issigned = (type == 'c') ? (input[inputpos] & 0x80) : 0; long v = php_unpack(&input[inputpos], 1, issigned, byte_map); add_assoc_long(return_value, n, v); break; } case 's': The correct setup needs to move the "break" outside the {...} scope, which would then fix the problem. This behavior is apparent in several places throughout that function and needs to be corrected in all of them. Thanks, Sefer. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=31247&edit=1

« previous php.bugs (#70964) next »