Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:10534 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 21138 invoked by uid 1010); 16 Jun 2004 17:16:04 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 21026 invoked from network); 16 Jun 2004 17:16:02 -0000 Received: from unknown (HELO mailgate.mysql.com) (213.136.52.47) by pb1.pair.com with SMTP; 16 Jun 2004 17:16:02 -0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by mailgate.mysql.com (8.12.10/8.12.10) with ESMTP id i5GHG1Ho030309; Wed, 16 Jun 2004 19:16:01 +0200 Received: from mail.mysql.com ([10.222.1.99]) by localhost (mailgate.mysql.com [10.222.1.98]) (amavisd-new, port 10026) with LMTP id 19217-07; Wed, 16 Jun 2004 19:16:01 +0200 (CEST) Received: from php.net (mailsend.mysql.com [10.100.1.123]) (authenticated bits=0) by mail.mysql.com (8.12.10/8.12.10) with ESMTP id i5GHFtQ6026937; Wed, 16 Jun 2004 19:15:55 +0200 Message-ID: <40D07FB6.6030905@php.net> Date: Wed, 16 Jun 2004 19:13:26 +0200 Reply-To: hartmut@php-groupies.de User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040113 X-Accept-Language: en, de MIME-Version: 1.0 To: Alexander Valyalkin CC: internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at mailgate.mysql.com Subject: Re: [PHP-DEV] strrchr() bugs From: hartmut@php.net (Hartmut Holzgraefe) Alexander Valyalkin wrote: > > Today I've revised strrchr() function in PHP4.3.7 sources. > It wasn't binary-safe. For example: > > 1) strrpos('abcd', '') returns 4. Expected FALSE Although one could argue whether searching for empty strings makes sense at all the result is not completely wrong. There *is* an empty string at the end of the haystack ... So for BC reasons this behavior should not be changed. > 2) strrpos("a\0abcde", 'a') returns 6. Expected 2 > 3) strrpos("a\0bcde", "\0") returns 6. Expected 1 > 4) strrpos('', '\0') returns 0. Expected FALSE these actualy look like bugs ... > My version of strrchr() is binary-safe and faster. > Below I provide standalone test with old and new strrpos() > functions. Anyone can compile it and compare results. Please, *NO MORE STANDALONE TESTS*. Integrate your new implementation, add a regression test (*.phpt) for it and file a bug on bugs.php.net. Add a unified diff patch against a PHP release version or against current CVS. Wait! *First* write a regression test, then try to fix the code so that the regression fails with the old implementation and passes with the new. When not sure about the intended behavior it might be better to just report a bug and maybe add a regression test. If the current behavior is there for a reason (like BC issues) you will find out *before* implementing unneeded stuff. Chances are *way* higher that someone listens to you ... > If you are very lazy or dont know how compile source file, below > you could see my results of this test: All (good) programmers are lazy. And all of the subscribers of this list know how to compile source files. Some even have social skills. You should start working on yours. Thank you in advance for your cooperation ... -- Hartmut Holzgraefe