From:             wharmby at uk dot ibm dot com
Operating system: Windows XP
PHP version:      6CVS-2009-01-14 (snap)
PHP Bug Type:     Strings related
Bug description:  strripos issues unepxected warning with UNICODE haystack 

Description:
------------
I get an unexpected warning msg when I specify an haystack with a non-zero
offset. 


I think the problem lies in the following code in ext/standard/string.c  

2913  if (haystack_type == IS_UNICODE) {
2914    if (offset >= 0) {
2915       U16_FWD_N(haystack.u, cu_offset, haystack_len, offset);
2916       if (cu_offset > haystack_len - needle_len) {
2917       php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Offset is greater
than the length of haystack string");
2918       RETURN_FALSE;
2919    }
2920    u_p = haystack.u + cu_offset;
2921    u_e = haystack.u + haystack_len - needle_len;
2922  } else { 

If (cu_offset > haystack_len - needle_len) then FALSE should be returned
but the warning is bogus; that should only be output if cu_offset >
haystack_len.

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

$haystack = "abcdefg";
$needle = "abcdefg";
var_dump( strripos($haystack, $needle, 0) );
var_dump( strripos($haystack, $needle, 1) );

?>

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

Actual result:
--------------
int(0)
bool(false)
PHP Notice:  strripos(): Offset is greater than the length of haystack
string in .... etc 

-- 
Edit bug report at http://bugs.php.net/?id=47102&edit=1
-- 
Try a CVS snapshot (PHP 5.2):        
http://bugs.php.net/fix.php?id=47102&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):        
http://bugs.php.net/fix.php?id=47102&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):        
http://bugs.php.net/fix.php?id=47102&r=trysnapshot60
Fixed in CVS:                        
http://bugs.php.net/fix.php?id=47102&r=fixedcvs
Fixed in CVS and need be documented: 
http://bugs.php.net/fix.php?id=47102&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=47102&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=47102&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=47102&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=47102&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=47102&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=47102&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=47102&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=47102&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=47102&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=47102&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=47102&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=47102&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=47102&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=47102&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=47102&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=47102&r=mysqlcfg

Reply via email to