php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #11009 Recursive call causes crash
Submitted: 2001-05-21 22:06 UTC Modified: 2001-05-22 00:14 UTC
From: millz at incogen dot com Assigned:
Status: Closed Package: Reproducible crash
PHP Version: 4.0.5 OS: RedHat 6.2
Private report: No CVE-ID: None
 [2001-05-21 22:06 UTC] millz at incogen dot com
I created a function called pad which performs exactly what str_repeat does (didn't realize str_repeat was there originally).

function pad($length,$padVar="-"){
 if($length<=0){return;}
 else{return pad($length-1,$padVar).$padVar;}
}

When passing a length > about 5000 the page will not load and I quickly get this error in the php.error log: 
[notice] child pid 15040 exit signal Segmentation fault (11)

I assume it is b/c the function stack is just not up to the task, but I thought I would let you know anyway. 
Of course I am using str_repeat now....

Thanks!
Jason

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-05-21 22:53 UTC] brianlmoon@php.net
This is more of a programing error.  This is a poor way to use recursive calls.  A loop is the correct way to handle this.
 [2001-05-21 22:58 UTC] millz at incogen dot com
yeah, but a while($length--) was super slow (10-20 times slower)...actually timed-out on the simplest runs. 

maybe a for() is faster?!
 [2001-05-22 00:06 UTC] brianlmoon@php.net
I personally used sprintf for this job before str_repeat came along.  However, it is a useless argument now.
 [2001-05-22 00:14 UTC] millz at incogen dot com
Yeah, but the issue is not that I picked a "bad" way of doing this task, but whether or not a recursive call should be able to go this "deep" in PHP....i guess not.  

Thanks for the help though,
Jas
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 10:01:29 2024 UTC