Newbie help: Segmentation fault

php.internals

Arnold Daniels

19 years ago
Hi, I could use some help on an extension I've written. It worked fine before, but from out the blue I started to get segmentation faults. I've located it down to this piece of code, but I don't do any writes to the code memory, so I don't get what's wrong. It seems like the error lies in the 'ret != NULL'. The module compiled against php 5.1.6 and runs under linux version 2.6.15.4 (Debian). Thank for any reply, Arnold PHP_FUNCTION(qconf_ini_parse) { zval *in; zval *ret; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &in, &ret) == FAILURE) { RETURN_FALSE; } if (ret != NULL) { printf('1'); } RETURN_NULL(); }

Antony Dovgal

19 years ago
On 01/15/2007 11:50 PM, Arnold Daniels wrote:
> Hi, > > I could use some help on an extension I've written. It worked fine > before, but from out the blue I started to get segmentation faults. I've > located it down to this piece of code, but I don't do any writes to the > code memory, so I don't get what's wrong. It seems like the error lies > in the 'ret != NULL'. > > The module compiled against php 5.1.6 and runs under linux version > 2.6.15.4 (Debian).
- zval *ret; + zval *ret = NULL;
-- Wbr, Antony Dovgal

Arnold Daniels

19 years ago
Hi again, First of all thanks for your reply. It sound logical, but doesn't work unfortunately. I now get: seabert:/var/pear# phpunit Test_Standard_qconf PHPUnit 3.0.0alpha11 by Sebastian Bergmann. FFFFSegmentation fault I've got no idea where the the FFFF stands for. /** * Parse .ini content into a zend array */ PHP_FUNCTION(qconf_ini_parse) { zval *in=NULL; zval *ret=NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &in, &ret) == FAILURE) { RETURN_FALSE; } if (ret != NULL) { printf('1'); } RETURN_NULL(); } If you could have a closer look I will be very grateful. Arnold Antony Dovgal schreef:

Antony Dovgal

19 years ago
On 01/16/2007 12:12 AM, Arnold Daniels wrote:
> Hi again, > > First of all thanks for your reply. It sound logical, but doesn't work > unfortunately. I now get: > > seabert:/var/pear# phpunit Test_Standard_qconf > PHPUnit 3.0.0alpha11 by Sebastian Bergmann. > > FFFFSegmentation fault > > I've got no idea where the the FFFF stands for.
Then your problem is elsewhere. GDB or an other debugger will help you to locate it.
-- Wbr, Antony Dovgal

Derick Rethans

19 years ago
On Mon, 15 Jan 2007, Arnold Daniels wrote:
> Hi again, > > First of all thanks for your reply. It sound logical, but doesn't work > unfortunately. I now get: > > seabert:/var/pear# phpunit Test_Standard_qconf > PHPUnit 3.0.0alpha11 by Sebastian Bergmann. > > FFFFSegmentation fault > > I've got no idea where the the FFFF stands for.
For Four Failed Fests. (That almost worked) regards, Derick

Sebastian Bergmann

19 years ago
Arnold Daniels wrote:
> I've got no idea where the the FFFF stands for.
PHPUnit reports progress with .FEIS characters, see http://www.phpunit.de/pocket_guide/3.0/en/textui.html for details.
-- Sebastian Bergmann http://sebastian-bergmann.de/ GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69

Arnold Daniels

19 years ago
Ah off couse, It's not giving the segmentation fault on the first test. Thats even stranger. It appears that the system admin had updated the kernel, than updated some more software and than put back the old kernel. It's still strange. Arnold Sebastian Bergmann wrote:

Michael Wallner

19 years ago
Arnold Daniels wrote:
> if (ret != NULL) { > printf('1'); > }
'1' is 0x00000031, use "1" and you'll get a real memory address to print.
-- Michael

Arnold Daniels

19 years ago
Hi, Yes sure you are right, but there was some other code which I replaced with printf to show where the problem lies. The printf not in the actual code, only in the e-mail :). I'm very sure that the problem lies in the ret != NULL. Function zend_parse_parameters() puts a strange value in ret, when the argument is not supplied in PHP. But I'll try gdb to see if I can find where the problem is coming from. Thanks for replying anyway, Arnold Michael Wallner wrote:

Derick Rethans

19 years ago
On Tue, 16 Jan 2007, Arnold Daniels wrote:
> Yes sure you are right, but there was some other code which I replaced > with printf to show where the problem lies. The printf not in the actual > code, only in the e-mail :). > I'm very sure that the problem lies in the ret != NULL. Function > zend_parse_parameters() puts a strange value in ret, when the argument > is not supplied in PHP. But I'll try gdb to see if I can find where the > problem is coming from.
When an argument is not supplied, zend_pp doesn't touch the value. You would need to initialize it in your variable declaration, such as : char *ret = NULL; regards, Derick