# Newbie help: Segmentation fault

- Thread: https://externals.io/message/27463
- Original archive: https://news-web.php.net/php.internals/27463
- Started by Arnold Daniels on 2007-01-15T20:50:07+00:00
- Messages: 10
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #27463 — Arnold Daniels — 2007-01-15T20:50:07+00:00

URL: https://externals.io/message/27463#27463

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();
}

---

## #27464 — Antony Dovgal — 2007-01-15T20:57:54+00:00

URL: https://externals.io/message/27463#27464 · In reply to: #27463

> 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

---

## #27465 — Arnold Daniels — 2007-01-15T21:12:08+00:00

URL: https://externals.io/message/27463#27465 · In reply to: #27464

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:
> 
> > […]
>
> -     zval *ret;
> +     zval *ret = NULL;

---

## #27466 — Antony Dovgal — 2007-01-15T21:15:09+00:00

URL: https://externals.io/message/27463#27466 · In reply to: #27465

> 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

---

## #27469 — Derick Rethans — 2007-01-15T21:31:27+00:00

URL: https://externals.io/message/27463#27469 · In reply to: #27465

> 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

---

## #27476 — Sebastian Bergmann — 2007-01-16T07:06:36+00:00

URL: https://externals.io/message/27463#27476 · In reply to: #27465

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

---

## #27477 — Michael Wallner — 2007-01-16T07:30:55+00:00

URL: https://externals.io/message/27463#27477 · In reply to: #27463

Arnold Daniels wrote:

>    if (ret != NULL) {
>        printf('1');
>    }

'1' is 0x00000031, use "1" and you'll get a real memory address to print.

-- 
Michael

---

## #27480 — Arnold Daniels — 2007-01-16T11:08:53+00:00

URL: https://externals.io/message/27463#27480 · In reply to: #27476

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:
> Arnold Daniels wrote:
>   
> > […]
>
>  PHPUnit reports progress with .FEIS characters, see
>  http://www.phpunit.de/pocket_guide/3.0/en/textui.html for details.

---

## #27481 — Arnold Daniels — 2007-01-16T11:18:41+00:00

URL: https://externals.io/message/27463#27481 · In reply to: #27477

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:
> Arnold Daniels wrote:
>
>   
> > […]
>
> '1' is 0x00000031, use "1" and you'll get a real memory address to print.

---

## #27482 — Derick Rethans — 2007-01-16T12:13:26+00:00

URL: https://externals.io/message/27463#27482 · In reply to: #27481

> 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
