diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c index b61d253c5d4be..157ee41a11a05 100644 --- a/ext/iconv/iconv.c +++ b/ext/iconv/iconv.c @@ -63,15 +63,15 @@ #define PHP_ICONV_IMPL_VALUE "unknown" #endif -static char *get_iconv_version(void) { - char *version = "unknown"; +static const char *get_iconv_version(void) { + const char *version = "unknown"; #ifdef HAVE_LIBICONV static char buf[16]; snprintf(buf, sizeof(buf), "%d.%d", _libiconv_version >> 8, _libiconv_version & 0xff); version = buf; #elif defined(HAVE_GLIBC_ICONV) - version = (char *) gnu_get_libc_version(); + version = gnu_get_libc_version(); #endif return version; @@ -243,7 +243,7 @@ PHP_MSHUTDOWN_FUNCTION(miconv) /* {{{ PHP_MINFO_FUNCTION */ PHP_MINFO_FUNCTION(miconv) { - zval *iconv_impl, *iconv_ver; + const zval *iconv_impl, *iconv_ver; iconv_impl = zend_get_constant_str("ICONV_IMPL", sizeof("ICONV_IMPL")-1); iconv_ver = zend_get_constant_str("ICONV_VERSION", sizeof("ICONV_VERSION")-1); @@ -298,17 +298,18 @@ static php_output_handler *php_iconv_output_handler_init(const char *handler_nam static zend_result php_iconv_output_handler(void **nothing, php_output_context *output_context) { - char *s, *content_type, *mimetype = NULL; - int output_status, mimetype_len = 0; + char *content_type, *mimetype = NULL; if (output_context->op & PHP_OUTPUT_HANDLER_START) { - output_status = php_output_get_status(); + int output_status = php_output_get_status(); if (output_status & PHP_OUTPUT_SENT) { return FAILURE; } + int mimetype_len = 0; if (SG(sapi_headers).mimetype && !strncasecmp(SG(sapi_headers).mimetype, "text/", 5)) { - if ((s = strchr(SG(sapi_headers).mimetype,';')) == NULL){ + const char *s = strchr(SG(sapi_headers).mimetype,';'); + if (s == NULL){ mimetype = SG(sapi_headers).mimetype; } else { mimetype = SG(sapi_headers).mimetype; @@ -320,7 +321,7 @@ static zend_result php_iconv_output_handler(void **nothing, php_output_context * if (mimetype != NULL && (!(output_context->op & PHP_OUTPUT_HANDLER_CLEAN) || ((output_context->op & PHP_OUTPUT_HANDLER_START) && !(output_context->op & PHP_OUTPUT_HANDLER_FINAL)))) { size_t len; - char *p = strstr(get_output_encoding(), "//"); + const char *p = strstr(get_output_encoding(), "//"); if (p) { len = spprintf(&content_type, 0, "Content-Type:%.*s; charset=%.*s", mimetype_len ? mimetype_len : (int) strlen(mimetype), mimetype, (int) (p - get_output_encoding()), get_output_encoding()); @@ -417,16 +418,16 @@ static php_iconv_err_t _php_iconv_appendc(smart_str *d, const char c, iconv_t cd /* {{{ */ #ifdef ICONV_BROKEN_IGNORE -static int _php_check_ignore(const char *charset) +static bool _php_check_ignore(const char *charset) { size_t clen = strlen(charset); if (clen >= 9 && strcmp("//IGNORE", charset+clen-8) == 0) { - return 1; + return true; } if (clen >= 19 && strcmp("//IGNORE//TRANSLIT", charset+clen-18) == 0) { - return 1; + return true; } - return 0; + return false; } #else #define _php_check_ignore(x) (0) @@ -442,7 +443,7 @@ PHP_ICONV_API php_iconv_err_t php_iconv_string(const char *in_p, size_t in_len, size_t bsz, result = 0; php_iconv_err_t retval = PHP_ICONV_ERR_SUCCESS; zend_string *out_buf; - int ignore_ilseq = _php_check_ignore(out_charset); + bool ignore_ilseq = _php_check_ignore(out_charset); *out = NULL; @@ -559,7 +560,7 @@ static php_iconv_err_t _php_iconv_strlen(size_t *pretval, const char *str, size_ size_t out_left; size_t cnt; - int more; + bool more; *pretval = (size_t)-1; @@ -636,7 +637,7 @@ static php_iconv_err_t _php_iconv_substr(smart_str *pretval, size_t cnt; size_t total_len; - int more; + bool more; err = _php_iconv_strlen(&total_len, str, nbytes, enc); if (err != PHP_ICONV_ERR_SUCCESS) { @@ -774,8 +775,7 @@ static php_iconv_err_t _php_iconv_strpos(size_t *pretval, size_t ndl_buf_left; size_t match_ofs; - int more; - size_t iconv_ret; + bool more; *pretval = (size_t)-1; @@ -812,7 +812,7 @@ static php_iconv_err_t _php_iconv_strpos(size_t *pretval, more = in_left > 0; - iconv_ret = iconv(cd, more ? (ICONV_CONST char **)&in_p : NULL, more ? &in_left : NULL, (char **) &out_p, &out_left); + size_t iconv_ret = iconv(cd, more ? (ICONV_CONST char **)&in_p : NULL, more ? &in_left : NULL, (char **) &out_p, &out_left); if (out_left == sizeof(buf)) { break; } @@ -2255,11 +2255,7 @@ PHP_FUNCTION(iconv_set_encoding) retval = zend_alter_ini_entry(name, charset, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); zend_string_release_ex(name, 0); - if (retval == SUCCESS) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } + RETURN_BOOL(retval == SUCCESS); } /* }}} */ @@ -2577,7 +2573,7 @@ static php_stream_filter *php_iconv_stream_filter_factory_create(const char *nam { php_stream_filter *retval = NULL; php_iconv_stream_filter *inst; - char *from_charset = NULL, *to_charset = NULL; + const char *from_charset = NULL, *to_charset = NULL; size_t from_charset_len, to_charset_len; if ((from_charset = strchr(name, '.')) == NULL) { diff --git a/ext/iconv/php_iconv.h b/ext/iconv/php_iconv.h index 7bc1cce0df9f5..fcabdfaf6449e 100644 --- a/ext/iconv/php_iconv.h +++ b/ext/iconv/php_iconv.h @@ -67,7 +67,7 @@ ZEND_TSRMLS_CACHE_EXTERN() /* {{{ typedef enum php_iconv_err_t */ typedef enum _php_iconv_err_t { - PHP_ICONV_ERR_SUCCESS = SUCCESS, + PHP_ICONV_ERR_SUCCESS = 0, PHP_ICONV_ERR_CONVERTER = 1, PHP_ICONV_ERR_WRONG_CHARSET = 2, PHP_ICONV_ERR_TOO_BIG = 3,