#43809 [Opn]: strtok() should return FALSE if needle wasnt found

From: Date: Fri, 11 Jan 2008 00:09:44 +0000
Subject: #43809 [Opn]: strtok() should return FALSE if needle wasnt found
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-121184@lists.php.net to get a copy of this message
 ID:               43809
 Updated by:       felipe@php.net
 Reported By:      admin at ifyouwantblood dot de
 Status:           Open
 Bug Type:         Feature/Change Request
 Operating System: Any
 PHP Version:      5.2.5
 New Comment:

Looks fine to me. My try:

Index: string.c
===================================================================
RCS file: /repository/php-src/ext/standard/string.c,v
retrieving revision 1.445.2.14.2.69.2.8
diff -u -r1.445.2.14.2.69.2.8 string.c
--- string.c    31 Dec 2007 07:17:15 -0000      1.445.2.14.2.69.2.8
+++ string.c    11 Jan 2008 00:00:34 -0000
@@ -1264,7 +1264,7 @@
                }
        }
 
-       if (p - BG(strtok_last)) {
+       if ((skipped || BG(strtok_len) != strlen(BG(strtok_last))) && p
- BG(strtok_last)) {
 return_token:
                RETVAL_STRINGL(BG(strtok_last) + skipped, (p -
BG(strtok_last)) - skipped, 1);
                BG(strtok_last) = p + 1;



Previous Comments:
------------------------------------------------------------------------

[2008-01-10 19:06:45] admin at ifyouwantblood dot de

Description:
------------
In PHP 4.1 strtok() has been changed to return FALSE if a repeated
token wasnt found in the haystack string. It should also return FALSE if
needle wasnt found at first place.

Reproduce code:
---------------
<?php

$something=strtok('something',':');
var_dump($something);

?>

Expected result:
----------------
bool(false)

Actual result:
--------------
string(9) "something"


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=43809&edit=1


Thread (3 messages)

« previous php.bugs (#121184) next »