mirror of
https://github.com/php/php-src.git
synced 2024-11-24 18:34:21 +08:00
- MFH: Fixed warnings.
This commit is contained in:
parent
2cca3d0dd2
commit
d7594edaa0
@ -2225,17 +2225,17 @@ PHP_FUNCTION(mb_stripos)
|
||||
{
|
||||
int n;
|
||||
long offset;
|
||||
char *old_haystack, *old_needle;
|
||||
mbfl_string haystack, needle;
|
||||
char *from_encoding = (char*)mbfl_no2preferred_mime_name(MBSTRG(current_internal_encoding));
|
||||
int old_haystack_len, old_needle_len, from_encoding_len;
|
||||
int from_encoding_len;
|
||||
n = -1;
|
||||
offset = 0;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|ls", &old_haystack, &old_haystack_len, &old_needle, &old_needle_len, &offset, &from_encoding, &from_encoding_len ) == FAILURE) {
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|ls", (char **)&haystack.val, (int *)&haystack.len, (char **)needle.val, (int *)&needle.len, &offset, &from_encoding, &from_encoding_len) == FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
n = php_mb_stripos(0, old_haystack, old_haystack_len, old_needle, old_needle_len, offset, from_encoding TSRMLS_CC);
|
||||
n = php_mb_stripos(0, (char *)haystack.val, haystack.len, (char *)needle.val, needle.len, offset, from_encoding TSRMLS_CC);
|
||||
|
||||
if (n >= 0) {
|
||||
RETVAL_LONG(n);
|
||||
@ -2251,21 +2251,21 @@ PHP_FUNCTION(mb_strripos)
|
||||
{
|
||||
int n;
|
||||
long offset;
|
||||
char *old_haystack, *old_needle;
|
||||
char *from_encoding = (char*)mbfl_no2preferred_mime_name(MBSTRG(current_internal_encoding));
|
||||
int old_haystack_len, old_needle_len, from_encoding_len;
|
||||
mbfl_string haystack, needle;
|
||||
const char *from_encoding = mbfl_no2preferred_mime_name(MBSTRG(current_internal_encoding));
|
||||
int from_encoding_len;
|
||||
n = -1;
|
||||
offset = 0;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|ls", &old_haystack, &old_haystack_len, &old_needle, &old_needle_len, &offset, &from_encoding, &from_encoding_len ) == FAILURE) {
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|ls", (char **)&haystack.val, (int *)&haystack.len, (char **)&needle.val, (int *)&needle.len, &offset, &from_encoding, &from_encoding_len) == FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if(offset > old_haystack_len){
|
||||
if (offset > haystack.len) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
n = php_mb_stripos(1, old_haystack, old_haystack_len, old_needle, old_needle_len, offset, from_encoding TSRMLS_CC);
|
||||
n = php_mb_stripos(1, (char *)haystack.val, haystack.len, (char *)needle.val, needle.len, offset, from_encoding TSRMLS_CC);
|
||||
|
||||
if (n >= 0) {
|
||||
RETVAL_LONG(n);
|
||||
@ -2292,7 +2292,7 @@ PHP_FUNCTION(mb_strstr)
|
||||
needle.no_language = MBSTRG(current_language);
|
||||
needle.no_encoding = MBSTRG(current_internal_encoding);
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|bs", (char **)&haystack.val, &haystack.len, (char **)&needle.val, &needle.len, &part, &enc_name, &enc_name_len) == FAILURE) {
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|bs", (char **)&haystack.val, (int *)&haystack.len, (char **)&needle.val, (int *)&needle.len, &part, &enc_name, &enc_name_len) == FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
@ -2398,9 +2398,9 @@ PHP_FUNCTION(mb_strrchr)
|
||||
PHP_FUNCTION(mb_stristr)
|
||||
{
|
||||
zend_bool part = 0;
|
||||
int n, from_encoding_len, len, mblen;
|
||||
unsigned int n, from_encoding_len, len, mblen;
|
||||
mbfl_string haystack, needle, result, *ret = NULL;
|
||||
char *from_encoding = (char*)mbfl_no2preferred_mime_name(MBSTRG(current_internal_encoding));
|
||||
const char *from_encoding = mbfl_no2preferred_mime_name(MBSTRG(current_internal_encoding));
|
||||
mbfl_string_init(&haystack);
|
||||
mbfl_string_init(&needle);
|
||||
haystack.no_language = MBSTRG(current_language);
|
||||
@ -2413,7 +2413,7 @@ PHP_FUNCTION(mb_stristr)
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if(!needle.len){
|
||||
if (!needle.len) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING,"Empty delimiter.");
|
||||
RETURN_FALSE;
|
||||
}
|
||||
@ -2424,7 +2424,7 @@ PHP_FUNCTION(mb_stristr)
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
n = php_mb_stripos(0, haystack.val, haystack.len, needle.val, needle.len, 0, from_encoding TSRMLS_CC);
|
||||
n = php_mb_stripos(0, (char *)haystack.val, haystack.len, (char *)needle.val, needle.len, 0, from_encoding TSRMLS_CC);
|
||||
|
||||
if (n <0) {
|
||||
RETURN_FALSE;
|
||||
@ -2477,7 +2477,7 @@ PHP_FUNCTION(mb_strrichr)
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
n = php_mb_stripos(1, haystack.val, haystack.len, needle.val, needle.len, 0, from_encoding TSRMLS_CC);
|
||||
n = php_mb_stripos(1, (char *)haystack.val, haystack.len, (char *)needle.val, needle.len, 0, from_encoding TSRMLS_CC);
|
||||
|
||||
if (n <0) {
|
||||
RETURN_FALSE;
|
||||
@ -2624,19 +2624,19 @@ PHP_FUNCTION(mb_substr)
|
||||
PHP_FUNCTION(mb_strcut)
|
||||
{
|
||||
size_t argc = ZEND_NUM_ARGS();
|
||||
char *str, *encoding;
|
||||
char *encoding;
|
||||
long from, len;
|
||||
int str_len, encoding_len;
|
||||
int encoding_len;
|
||||
mbfl_string string, result, *ret;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|ls", &str, &str_len, &from, &len, &encoding, &encoding_len) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
mbfl_string_init(&string);
|
||||
string.no_language = MBSTRG(current_language);
|
||||
string.no_encoding = MBSTRG(current_internal_encoding);
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|ls", (char **)&string.val, (int **)&string.len, &from, &len, &encoding, &encoding_len) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (argc == 4) {
|
||||
string.no_encoding = mbfl_name2no_encoding(encoding);
|
||||
if (string.no_encoding == mbfl_no_encoding_invalid) {
|
||||
@ -2645,18 +2645,15 @@ PHP_FUNCTION(mb_strcut)
|
||||
}
|
||||
}
|
||||
|
||||
string.val = str;
|
||||
string.len = str_len;
|
||||
|
||||
if (argc < 3) {
|
||||
len = str_len;
|
||||
len = string.len;
|
||||
}
|
||||
|
||||
/* if "from" position is negative, count start position from the end
|
||||
* of the string
|
||||
*/
|
||||
if (from < 0) {
|
||||
from = str_len + from;
|
||||
from = string.len + from;
|
||||
if (from < 0) {
|
||||
from = 0;
|
||||
}
|
||||
@ -2666,18 +2663,18 @@ PHP_FUNCTION(mb_strcut)
|
||||
* needed to stop that many chars from the end of the string
|
||||
*/
|
||||
if (len < 0) {
|
||||
len = (str_len - from) + len;
|
||||
len = (string.len - from) + len;
|
||||
if (len < 0) {
|
||||
len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (from > str_len) {
|
||||
if (from > string.len) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (((unsigned) from + (unsigned) len) > str_len) {
|
||||
len = str_len - from;
|
||||
if (((unsigned) from + (unsigned) len) > string.len) {
|
||||
len = string.len - from;
|
||||
}
|
||||
|
||||
ret = mbfl_strcut(&string, &result, from, len);
|
||||
@ -2685,7 +2682,7 @@ PHP_FUNCTION(mb_strcut)
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
RETURN_STRINGL(ret->val, ret->len, 0); /* the string is already strdup()'ed */
|
||||
RETURN_STRINGL((char *)ret->val, ret->len, 0); /* the string is already strdup()'ed */
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@ -2783,7 +2780,7 @@ PHP_FUNCTION(mb_strimwidth)
|
||||
/* }}} */
|
||||
|
||||
/* {{{ MBSTRING_API char *php_mb_convert_encoding() */
|
||||
MBSTRING_API char * php_mb_convert_encoding(char *input, size_t length, char *_to_encoding, char *_from_encodings, size_t *output_len TSRMLS_DC)
|
||||
MBSTRING_API char * php_mb_convert_encoding(const char *input, size_t length, const char *_to_encoding, const char *_from_encodings, size_t *output_len TSRMLS_DC)
|
||||
{
|
||||
mbfl_string string, result, *ret;
|
||||
enum mbfl_no_encoding from_encoding, to_encoding;
|
||||
@ -3596,18 +3593,18 @@ detect_end:
|
||||
} else {
|
||||
zval_dtor(*hash_entry);
|
||||
}
|
||||
ZVAL_STRINGL(*hash_entry, ret->val, ret->len, 0);
|
||||
}
|
||||
ZVAL_STRINGL(*hash_entry, (char *)ret->val, ret->len, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (Z_TYPE_PP(var) == IS_STRING) {
|
||||
string.val = (unsigned char *)Z_STRVAL_PP(var);
|
||||
string.len = Z_STRLEN_PP(var);
|
||||
ret = mbfl_buffer_converter_feed_result(convd, &string, &result);
|
||||
if (ret != NULL) {
|
||||
zval_dtor(*var);
|
||||
ZVAL_STRINGL(*var, ret->val, ret->len, 0);
|
||||
}
|
||||
} else if (Z_TYPE_PP(var) == IS_STRING) {
|
||||
string.val = (unsigned char *)Z_STRVAL_PP(var);
|
||||
string.len = Z_STRLEN_PP(var);
|
||||
ret = mbfl_buffer_converter_feed_result(convd, &string, &result);
|
||||
if (ret != NULL) {
|
||||
zval_dtor(*var);
|
||||
ZVAL_STRINGL(*var, (char *)ret->val, ret->len, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3938,15 +3935,15 @@ out:
|
||||
PHP_FUNCTION(mb_send_mail)
|
||||
{
|
||||
int n;
|
||||
char *to=NULL;
|
||||
char *to = NULL;
|
||||
int to_len;
|
||||
char *message=NULL;
|
||||
char *message = NULL;
|
||||
int message_len;
|
||||
char *headers=NULL;
|
||||
char *headers = NULL;
|
||||
int headers_len;
|
||||
char *subject=NULL;
|
||||
char *subject = NULL;
|
||||
int subject_len;
|
||||
char *extra_cmd=NULL;
|
||||
char *extra_cmd = NULL;
|
||||
int extra_cmd_len;
|
||||
int i;
|
||||
char *to_r = NULL;
|
||||
@ -3956,7 +3953,7 @@ PHP_FUNCTION(mb_send_mail)
|
||||
int cnt_trans_enc:1;
|
||||
} suppressed_hdrs = { 0, 0 };
|
||||
|
||||
char *message_buf=NULL, *subject_buf=NULL, *p;
|
||||
char *message_buf = NULL, *subject_buf = NULL, *p;
|
||||
mbfl_string orig_str, conv_str;
|
||||
mbfl_string *pstr; /* pointer to mbfl string for return value */
|
||||
enum mbfl_no_encoding
|
||||
@ -4123,8 +4120,8 @@ PHP_FUNCTION(mb_send_mail)
|
||||
/* message body */
|
||||
if (message != NULL) {
|
||||
orig_str.no_language = MBSTRG(current_language);
|
||||
orig_str.val = message;
|
||||
orig_str.len = message_len;
|
||||
orig_str.val = (unsigned char *)message;
|
||||
orig_str.len = (unsigned int)message_len;
|
||||
orig_str.no_encoding = MBSTRG(current_internal_encoding);
|
||||
|
||||
if (orig_str.no_encoding == mbfl_no_encoding_invalid
|
||||
@ -4495,7 +4492,7 @@ PHP_FUNCTION(mb_check_encoding)
|
||||
|
||||
if (ret != NULL) {
|
||||
MBSTRG(illegalchars) += illegalchars;
|
||||
if (illegalchars == 0 && strncmp(string.val, ret->val, string.len) == 0) {
|
||||
if (illegalchars == 0 && strncmp((char *)string.val, (char *)ret->val, string.len) == 0) {
|
||||
efree(ret->val);
|
||||
RETURN_TRUE;
|
||||
} else {
|
||||
@ -4650,7 +4647,7 @@ MBSTRING_API int php_mb_gpc_encoding_converter(char **str, int *len, int num, co
|
||||
string.no_language = MBSTRG(current_language);
|
||||
|
||||
for (i=0; i<num; i++){
|
||||
string.val = (char*)str[i];
|
||||
string.val = (unsigned char *)str[i];
|
||||
string.len = len[i];
|
||||
|
||||
/* initialize converter */
|
||||
@ -4665,8 +4662,8 @@ MBSTRING_API int php_mb_gpc_encoding_converter(char **str, int *len, int num, co
|
||||
ret = mbfl_buffer_converter_feed_result(convd, &string, &result);
|
||||
if (ret != NULL) {
|
||||
efree(str[i]);
|
||||
str[i] = ret->val;
|
||||
len[i] = ret->len;
|
||||
str[i] = (char *)ret->val;
|
||||
len[i] = (int)ret->len;
|
||||
}
|
||||
|
||||
MBSTRG(illegalchars) += mbfl_buffer_illegalchars(convd);
|
||||
@ -4757,8 +4754,7 @@ MBSTRING_API int php_mb_gpc_encoding_detector(char **arg_string, int *arg_length
|
||||
|
||||
/* {{{ MBSTRING_API int php_mb_stripos()
|
||||
*/
|
||||
|
||||
MBSTRING_API int php_mb_stripos(int mode, char *old_haystack, int old_haystack_len, char *old_needle, int old_needle_len, long offset, char *from_encoding TSRMLS_DC)
|
||||
MBSTRING_API int php_mb_stripos(int mode, const char *old_haystack, unsigned int old_haystack_len, const char *old_needle, unsigned int old_needle_len, unsigned int offset, const char *from_encoding TSRMLS_DC)
|
||||
{
|
||||
int n;
|
||||
mbfl_string haystack, needle;
|
||||
@ -4772,7 +4768,9 @@ MBSTRING_API int php_mb_stripos(int mode, char *old_haystack, int old_haystack_l
|
||||
needle.no_encoding = MBSTRG(current_internal_encoding);
|
||||
|
||||
do {
|
||||
haystack.val = php_unicode_convert_case(PHP_UNICODE_CASE_UPPER, old_haystack, (size_t) old_haystack_len, &haystack.len, from_encoding TSRMLS_CC);
|
||||
size_t len = 0;
|
||||
haystack.val = (unsigned char *)php_unicode_convert_case(PHP_UNICODE_CASE_UPPER, (char *)old_haystack, old_haystack_len, &len, from_encoding TSRMLS_CC);
|
||||
haystack.len = len;
|
||||
|
||||
if (!haystack.val) {
|
||||
break;
|
||||
@ -4782,7 +4780,8 @@ MBSTRING_API int php_mb_stripos(int mode, char *old_haystack, int old_haystack_l
|
||||
break;
|
||||
}
|
||||
|
||||
needle.val = php_unicode_convert_case(PHP_UNICODE_CASE_UPPER, old_needle, (size_t) old_needle_len, &needle.len, from_encoding TSRMLS_CC);
|
||||
needle.val = (unsigned char *)php_unicode_convert_case(PHP_UNICODE_CASE_UPPER, (char *)old_needle, old_needle_len, &len, from_encoding TSRMLS_CC);
|
||||
needle.len = len;
|
||||
|
||||
if (!needle.val) {
|
||||
break;
|
||||
@ -4798,7 +4797,7 @@ MBSTRING_API int php_mb_stripos(int mode, char *old_haystack, int old_haystack_l
|
||||
break;
|
||||
}
|
||||
|
||||
if (offset < 0 || (unsigned long)offset > haystack.len) {
|
||||
if (offset < 0 || offset > haystack.len) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset not contained in string.");
|
||||
break;
|
||||
}
|
||||
@ -4806,15 +4805,15 @@ MBSTRING_API int php_mb_stripos(int mode, char *old_haystack, int old_haystack_l
|
||||
n = mbfl_strpos(&haystack, &needle, offset, mode);
|
||||
} while(0);
|
||||
|
||||
if(haystack.val){
|
||||
if (haystack.val) {
|
||||
efree(haystack.val);
|
||||
}
|
||||
|
||||
if(needle.val){
|
||||
if (needle.val) {
|
||||
efree(needle.val);
|
||||
}
|
||||
|
||||
return n;
|
||||
return n;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
@ -137,9 +137,9 @@ MBSTRING_API char *php_mb_safe_strrchr(const char *s, unsigned int c,
|
||||
size_t nbytes TSRMLS_DC);
|
||||
MBSTRING_API char *php_mb_strrchr(const char *s, char c TSRMLS_DC);
|
||||
|
||||
MBSTRING_API char * php_mb_convert_encoding(char *input, size_t length,
|
||||
char *_to_encoding,
|
||||
char *_from_encodings,
|
||||
MBSTRING_API char * php_mb_convert_encoding(const char *input, size_t length,
|
||||
const char *_to_encoding,
|
||||
const char *_from_encodings,
|
||||
size_t *output_len TSRMLS_DC);
|
||||
|
||||
MBSTRING_API int php_mb_check_encoding_list(const char *encoding_list TSRMLS_DC);
|
||||
@ -158,7 +158,7 @@ MBSTRING_API int php_mb_gpc_encoding_converter(char **str, int *len, int num, co
|
||||
|
||||
MBSTRING_API int php_mb_gpc_encoding_detector(char **arg_string, int *arg_length, int num, char *arg_list TSRMLS_DC);
|
||||
|
||||
MBSTRING_API int php_mb_stripos(int mode, char *old_haystack, int old_haystack_len, char *old_needle, int old_needle_len, long offset, char *from_encoding TSRMLS_DC);
|
||||
MBSTRING_API int php_mb_stripos(int mode, const char *old_haystack, unsigned int old_haystack_len, const char *old_needle, unsigned int old_needle_len, unsigned int offset, const char *from_encoding TSRMLS_DC);
|
||||
|
||||
ZEND_BEGIN_MODULE_GLOBALS(mbstring)
|
||||
enum mbfl_no_language language;
|
||||
|
@ -267,8 +267,8 @@ MBSTRING_API unsigned long php_unicode_totitle(unsigned long code, enum mbfl_no_
|
||||
((unsigned char*)(ptr))[3] = (v ) & 0xff;\
|
||||
}
|
||||
|
||||
MBSTRING_API char *php_unicode_convert_case(int case_mode, char *srcstr, size_t srclen, size_t *ret_len,
|
||||
char *src_encoding TSRMLS_DC)
|
||||
MBSTRING_API char *php_unicode_convert_case(int case_mode, const char *srcstr, size_t srclen, size_t *ret_len,
|
||||
const char *src_encoding TSRMLS_DC)
|
||||
{
|
||||
char *unicode, *newstr;
|
||||
size_t unicode_len;
|
||||
|
@ -103,8 +103,8 @@
|
||||
|
||||
MBSTRING_API int php_unicode_is_prop(unsigned long code, unsigned long mask1,
|
||||
unsigned long mask2);
|
||||
MBSTRING_API char *php_unicode_convert_case(int case_mode, char *srcstr, size_t srclen, size_t *retlen,
|
||||
char *src_encoding TSRMLS_DC);
|
||||
MBSTRING_API char *php_unicode_convert_case(int case_mode, const char *srcstr, size_t srclen, size_t *retlen,
|
||||
const char *src_encoding TSRMLS_DC);
|
||||
|
||||
#define PHP_UNICODE_CASE_UPPER 0
|
||||
#define PHP_UNICODE_CASE_LOWER 1
|
||||
|
35
ext/mbstring/tests/mb_strstr.phpt
Normal file
35
ext/mbstring/tests/mb_strstr.phpt
Normal file
@ -0,0 +1,35 @@
|
||||
--TEST--
|
||||
mb_strstr()
|
||||
--SKIPIF--
|
||||
<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
|
||||
--INI--
|
||||
mbstring.internal_encoding=UTF-8
|
||||
--FILE--
|
||||
<?php
|
||||
function EUC_JP($utf8str) {
|
||||
return mb_convert_encoding($utf8str, "EUC-JP", "UTF-8");
|
||||
}
|
||||
|
||||
function FROM_EUC_JP($eucjpstr) {
|
||||
return mb_convert_encoding($eucjpstr, "UTF-8", "EUC-JP");
|
||||
}
|
||||
|
||||
var_dump(mb_strstr("あいうえおかきくけこ", "おかき"));
|
||||
var_dump(mb_strstr("あいうえおかきくけこ", "おかき", false));
|
||||
var_dump(mb_strstr("あいうえおかきくけこ", "おかき", true));
|
||||
var_dump(FROM_EUC_JP(mb_strstr(EUC_JP("あいうえおかきくけこ"), EUC_JP("おかき"), false, "EUC-JP")));
|
||||
var_dump(FROM_EUC_JP(mb_strstr(EUC_JP("あいうえおかきくけこ"), EUC_JP("おかき"), true, "EUC-JP")));
|
||||
mb_internal_encoding("EUC-JP");
|
||||
var_dump(FROM_EUC_JP(mb_strstr(EUC_JP("あいうえおかきくけこ"), EUC_JP("おかき"))));
|
||||
var_dump(FROM_EUC_JP(mb_strstr(EUC_JP("あいうえおかきくけこ"), EUC_JP("おかき"), false)));
|
||||
var_dump(FROM_EUC_JP(mb_strstr(EUC_JP("あいうえおかきくけこ"), EUC_JP("おかき"), true)));
|
||||
?>
|
||||
--EXPECT--
|
||||
string(18) "おかきくけこ"
|
||||
string(18) "おかきくけこ"
|
||||
string(12) "あいうえ"
|
||||
string(18) "おかきくけこ"
|
||||
string(12) "あいうえ"
|
||||
string(18) "おかきくけこ"
|
||||
string(18) "おかきくけこ"
|
||||
string(12) "あいうえ"
|
Loading…
Reference in New Issue
Block a user