Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:45652 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 55374 invoked from network); 1 Oct 2009 22:56:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Oct 2009 22:56:58 -0000 Authentication-Results: pb1.pair.com smtp.mail=garretts@microsoft.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=garretts@microsoft.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain microsoft.com designates 131.107.115.215 as permitted sender) X-PHP-List-Original-Sender: garretts@microsoft.com X-Host-Fingerprint: 131.107.115.215 smtp.microsoft.com Received: from [131.107.115.215] ([131.107.115.215:11851] helo=smtp.microsoft.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DB/E0-49344-6B335CA4 for ; Thu, 01 Oct 2009 18:56:57 -0400 Received: from TK5EX14MLTC102.redmond.corp.microsoft.com (157.54.79.180) by TK5-EXGWY-E802.partners.extranet.microsoft.com (10.251.56.168) with Microsoft SMTP Server (TLS) id 8.2.176.0; Thu, 1 Oct 2009 15:56:54 -0700 Received: from TK5EX14MBXC127.redmond.corp.microsoft.com ([169.254.6.18]) by TK5EX14MLTC102.redmond.corp.microsoft.com ([157.54.79.180]) with mapi; Thu, 1 Oct 2009 15:56:51 -0700 To: Stanislav Malyshev CC: 'PHP Internals' Thread-Topic: [PHP-DEV] Fix for 49148 (combination of stream_get_line and fseek does not work correctly) Thread-Index: AQHKLBReRR5UABK2xkOGr9gfVRgblpDD0KoAgAI6gwCABuKkIIACYMsAgCItZHA= Date: Thu, 1 Oct 2009 22:56:50 +0000 Message-ID: References: <4A9EE046.4090500@zend.com> <4AA05FCC.2000501@zend.com> <4AA8251A.6010004@zend.com> In-Reply-To: <4AA8251A.6010004@zend.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: RE: [PHP-DEV] Fix for 49148 (combination of stream_get_line and fseek does not work correctly) From: garretts@microsoft.com (Garrett Serack) I've updated my patch to return null on EOF. Index: streams/streams.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- streams/streams.c (revision 289073) +++ streams/streams.c (working copy) @@ -890,6 +890,9 @@ size_t seek_len; seek_len =3D stream->writepos - stream->readpos; + if(!seek_len) + return FALSE; + if (seek_len > maxlen) { seek_len =3D maxlen; } @@ -901,10 +904,7 @@ } if (!e) { - if (seek_len < maxlen && !stream->eof) { - return NULL; - } - toread =3D maxlen; + toread =3D (seek_len < maxlen) ? seek_len : maxlen; } else { toread =3D e - (char *) stream->readbuf - stream->r= eadpos; skip =3D 1; And the test script for it: --TEST-- Bug #49148 (combination of stream_get_line and fseek does not work correctl= y)=20 --FILE-- --EXPECT-- string(5) "line1" bool(false) bool(false) string(5) "line1" bool(false) bool(false) string(5) "line1" string(5) "line2" bool(false) string(5) "line1" string(5) "line2" bool(false) string(5) "line1" string(5) "line2" bool(false) string(5) "line1" string(5) "line2" bool(false) -----Original Message----- From: Stanislav Malyshev [mailto:stas@zend.com]=20 Sent: Wednesday, September 09, 2009 2:59 PM To: Garrett Serack Cc: 'PHP Internals' Subject: Re: [PHP-DEV] Fix for 49148 (combination of stream_get_line and fs= eek does not work correctly) Hi! > Well, that's a really good question. >=20 > Pre-patch, at the end of the stream (when you don't explicitly seek), > you get empty strings: I think it's a bug, docs say it's like fgets and fgets returns false on EOF. Also, "" with this function can mean "delimiter, than another delimititer" if I understand correctly, because it doesn't return the delims - which means returning "" on EOF is even worse bug. > Do you want to change the behavior so that it does return false? It's > trivial to do (and I'd agree that it would be correct), but it does > change the behavior from the current behavior. I think it's a bug and should be changed to return false on EOF, just as=20 fgets does. Of course, if there's data before EOF it should return it,=20 and then next read should return false. The case where file ends with=20 delim should return data before delim on first read, and false on the=20 next after delim was read. --=20 Stanislav Malyshev, Zend Software Architect stas@zend.com http://www.zend.com/ (408)253-8829 MSN: stas@zend.com