From cf5e2f63dbacebd836e1213ca18caad76b35cb04 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 17 Jun 2013 01:07:58 +0200 Subject: [PATCH] Fixed pthreads infinite loop when string length was <= 0 --- src/utils/pthreads.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/utils/pthreads.php b/src/utils/pthreads.php index 33d16f38..15b5a656 100644 --- a/src/utils/pthreads.php +++ b/src/utils/pthreads.php @@ -46,10 +46,17 @@ class AsyncMultipleQueue extends Thread{ private function get($len){ $str = ""; - while(!isset($str{$len - 1})){ - $str .= $this->input{0}; - $this->input = (string) substr($this->input, 1); + if($len <= 0){ + return $len; } + $offset = 0; + while(!isset($str{$len - 1})){ + if(isset($this->input{$offset})){ + $str .= $this->input{$offset}; + ++$offset; + } + } + $this->input = (string) substr($this->input, $offset); return $str; }