From adc95c511495f00cd1a90feff5fff7968e38fc4a Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Thu, 23 Jun 2016 12:47:06 +0300 Subject: [PATCH] Fixed compilation warnings --- ext/mysqlnd/mysqlnd_connection.c | 2 +- ext/mysqlnd/mysqlnd_plugin.c | 1 + ext/mysqlnd/mysqlnd_ps_codec.c | 2 +- ext/mysqlnd/mysqlnd_wireprotocol.c | 2 +- ext/pgsql/pgsql.c | 2 +- ext/phar/phar.c | 6 +++--- ext/shmop/shmop.c | 4 ++-- ext/snmp/snmp.c | 3 +-- ext/soap/php_sdl.c | 12 ++++++------ ext/soap/php_sdl.h | 2 +- ext/soap/soap.c | 8 ++++---- ext/sockets/conversions.c | 10 +++++----- ext/sockets/multicast.c | 2 +- ext/sockets/sendrecvmsg.c | 4 ++-- ext/sockets/sockaddr_conv.c | 2 +- ext/sockets/sockets.c | 10 +++++----- ext/standard/array.c | 24 ++++++++++++------------ ext/standard/basic_functions.c | 6 ++++-- ext/standard/browscap.c | 5 +++-- ext/standard/crypt_freesec.c | 4 ++-- ext/standard/dir.c | 2 +- ext/standard/exec.c | 8 ++++---- ext/standard/file.c | 4 ++-- ext/standard/ftp_fopen_wrapper.c | 7 ++++--- ext/standard/http_fopen_wrapper.c | 3 ++- ext/standard/iptc.c | 6 +++--- ext/standard/metaphone.c | 4 ++-- ext/standard/pack.c | 21 +++++++++++---------- ext/standard/password.c | 6 +++--- ext/standard/php_fopen_wrapper.c | 3 ++- ext/standard/php_incomplete_class.h | 2 +- ext/standard/string.c | 24 ++++++++++++------------ ext/standard/type.c | 2 +- ext/standard/user_filters.c | 2 +- ext/sysvshm/sysvshm.c | 2 +- ext/xml/xml.c | 4 ++-- 36 files changed, 109 insertions(+), 102 deletions(-) diff --git a/ext/mysqlnd/mysqlnd_connection.c b/ext/mysqlnd/mysqlnd_connection.c index bb582dbf6ac..701bc282e11 100644 --- a/ext/mysqlnd/mysqlnd_connection.c +++ b/ext/mysqlnd/mysqlnd_connection.c @@ -620,7 +620,7 @@ MYSQLND_METHOD(mysqlnd_conn_data, connect)(MYSQLND_CONN_DATA * conn, DBG_INF_FMT("host=%s user=%s db=%s port=%u flags=%u persistent=%u state=%u", hostname.s?hostname.s:"", username.s?username.s:"", database.s?database.s:"", port, mysql_flags, - conn? conn->persistent:0, conn? GET_CONNECTION_STATE(&conn->state):-1); + conn? conn->persistent:0, conn? (int)GET_CONNECTION_STATE(&conn->state):-1); if (GET_CONNECTION_STATE(&conn->state) > CONN_ALLOCED) { DBG_INF("Connecting on a connected handle."); diff --git a/ext/mysqlnd/mysqlnd_plugin.c b/ext/mysqlnd/mysqlnd_plugin.c index b90081a0efc..7e1e3785787 100644 --- a/ext/mysqlnd/mysqlnd_plugin.c +++ b/ext/mysqlnd/mysqlnd_plugin.c @@ -60,6 +60,7 @@ static struct st_mysqlnd_typeii_plugin_example mysqlnd_example_plugin = } }, NULL, /* methods */ + 0 }; diff --git a/ext/mysqlnd/mysqlnd_ps_codec.c b/ext/mysqlnd/mysqlnd_ps_codec.c index d989101060c..086866d1aec 100644 --- a/ext/mysqlnd/mysqlnd_ps_codec.c +++ b/ext/mysqlnd/mysqlnd_ps_codec.c @@ -184,7 +184,7 @@ ps_fetch_float(zval * zv, const MYSQLND_FIELD * const field, const unsigned int # define NOT_FIXED_DEC 31 #endif - dval = mysql_float_to_double(fval, (field->decimals >= NOT_FIXED_DEC) ? -1 : field->decimals); + dval = mysql_float_to_double(fval, (field->decimals >= NOT_FIXED_DEC) ? -1 : (int)field->decimals); ZVAL_DOUBLE(zv, dval); DBG_VOID_RETURN; diff --git a/ext/mysqlnd/mysqlnd_wireprotocol.c b/ext/mysqlnd/mysqlnd_wireprotocol.c index 825c56feaed..48b64c19f04 100644 --- a/ext/mysqlnd/mysqlnd_wireprotocol.c +++ b/ext/mysqlnd/mysqlnd_wireprotocol.c @@ -1611,7 +1611,7 @@ php_mysqlnd_rowp_read_binary_protocol(MYSQLND_MEMORY_POOL_CHUNK * row_buffer, zv MYSQLND_INC_CONN_STATISTIC_W_VALUE2(stats, statistic, 1, STAT_BYTES_RECEIVED_PURE_DATA_PS, (Z_TYPE_P(current_field) == IS_STRING)? - Z_STRLEN_P(current_field) : (p - orig_p)); + Z_STRLEN_P(current_field) : (size_t)(p - orig_p)); if (!((bit<<=1) & 255)) { bit = 1; /* to the following byte */ diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index c4dfe2ed9d6..4ae0ae63ea6 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -6528,7 +6528,7 @@ PHP_FUNCTION(pg_convert) } /* }}} */ -static int do_exec(smart_str *querystr, int expect, PGconn *pg_link, zend_ulong opt) /* {{{ */ +static int do_exec(smart_str *querystr, ExecStatusType expect, PGconn *pg_link, zend_ulong opt) /* {{{ */ { if (opt & PGSQL_DML_ASYNC) { if (PQsendQuery(pg_link, ZSTR_VAL(querystr->s))) { diff --git a/ext/phar/phar.c b/ext/phar/phar.c index 66da7c81c96..81596423ffe 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -1030,7 +1030,7 @@ static int phar_parse_pharfile(php_stream *fp, char *fname, int fname_len, char PHAR_GET_32(buffer, len); } } - if(len > endbuffer - buffer) { + if(len > (size_t)(endbuffer - buffer)) { MAPPHAR_FAIL("internal corruption of phar \"%s\" (trying to read past buffer end)"); } if (phar_parse_metadata(&buffer, &mydata->metadata, len) == FAILURE) { @@ -1071,7 +1071,7 @@ static int phar_parse_pharfile(php_stream *fp, char *fname, int fname_len, char entry.manifest_pos = manifest_index; } - if (entry.filename_len + 20 > endbuffer - buffer) { + if (entry.filename_len + 20 > (size_t)(endbuffer - buffer)) { MAPPHAR_FAIL("internal corruption of phar \"%s\" (truncated manifest entry)"); } @@ -1113,7 +1113,7 @@ static int phar_parse_pharfile(php_stream *fp, char *fname, int fname_len, char } else { entry.metadata_len = 0; } - if (len > endbuffer - buffer) { + if (len > (size_t)(endbuffer - buffer)) { pefree(entry.filename, entry.is_persistent); MAPPHAR_FAIL("internal corruption of phar \"%s\" (truncated manifest entry)"); } diff --git a/ext/shmop/shmop.c b/ext/shmop/shmop.c index d647790aa06..e65df7f790d 100644 --- a/ext/shmop/shmop.c +++ b/ext/shmop/shmop.c @@ -305,7 +305,7 @@ PHP_FUNCTION(shmop_size) PHP_FUNCTION(shmop_write) { struct php_shmop *shmop; - int writesize; + zend_long writesize; zend_long offset; zend_string *data; zval *shmid; @@ -328,7 +328,7 @@ PHP_FUNCTION(shmop_write) RETURN_FALSE; } - writesize = (ZSTR_LEN(data) < shmop->size - offset) ? ZSTR_LEN(data) : shmop->size - offset; + writesize = ((zend_long)ZSTR_LEN(data) < shmop->size - offset) ? (zend_long)ZSTR_LEN(data) : shmop->size - offset; memcpy(shmop->addr + offset, ZSTR_VAL(data), writesize); RETURN_LONG(writesize); diff --git a/ext/snmp/snmp.c b/ext/snmp/snmp.c index 7c4faa6cf32..cb48a0da222 100644 --- a/ext/snmp/snmp.c +++ b/ext/snmp/snmp.c @@ -2077,12 +2077,11 @@ static HashTable *php_snmp_get_properties(zval *object) HashTable *props; zval rv; zend_string *key; - zend_ulong num_key; obj = Z_SNMP_P(object); props = zend_std_get_properties(object); - ZEND_HASH_FOREACH_KEY_PTR(&php_snmp_properties, num_key, key, hnd) { + ZEND_HASH_FOREACH_STR_KEY_PTR(&php_snmp_properties, key, hnd) { if (!hnd->read_func || hnd->read_func(obj, &rv) != SUCCESS) { ZVAL_NULL(&rv); } diff --git a/ext/soap/php_sdl.c b/ext/soap/php_sdl.c index fdbd6d19af2..f3d3aa88db8 100644 --- a/ext/soap/php_sdl.c +++ b/ext/soap/php_sdl.c @@ -177,7 +177,7 @@ encodePtr get_encoder_ex(sdlPtr sdl, const char *nscat, int len) return NULL; } -sdlBindingPtr get_binding_from_type(sdlPtr sdl, int type) +sdlBindingPtr get_binding_from_type(sdlPtr sdl, sdlBindingType type) { sdlBindingPtr binding; @@ -227,7 +227,7 @@ static int is_wsdl_element(xmlNodePtr node) void sdl_set_uri_credentials(sdlCtx *ctx, char *uri) { char *s; - int l1, l2; + size_t l1, l2; zval context; zval *header = NULL; @@ -235,11 +235,11 @@ void sdl_set_uri_credentials(sdlCtx *ctx, char *uri) s = strstr(ctx->sdl->source, "://"); if (!s) return; s = strchr(s+3, '/'); - l1 = s ? (s - ctx->sdl->source) : strlen(ctx->sdl->source); + l1 = s ? (size_t)(s - ctx->sdl->source) : strlen(ctx->sdl->source); s = strstr((char*)uri, "://"); if (!s) return; s = strchr(s+3, '/'); - l2 = s ? (s - (char*)uri) : strlen((char*)uri); + l2 = s ? (size_t)(s - (char*)uri) : strlen((char*)uri); if (l1 != l2) { /* check for http://...:80/ */ if (l1 > 11 && @@ -3156,7 +3156,7 @@ sdlPtr get_sdl(zval *this_ptr, char *uri, zend_long cache_wsdl) char fn[MAXPATHLEN]; sdlPtr sdl = NULL; char* old_error_code = SOAP_GLOBAL(error_code); - int uri_len = 0; + size_t uri_len = 0; php_stream_context *context=NULL; zval *tmp, *proxy_host, *proxy_port, orig_context, new_context; smart_str headers = {0}; @@ -3329,7 +3329,7 @@ cache_in_memory: SOAP_GLOBAL(mem_cache) = malloc(sizeof(HashTable)); zend_hash_init(SOAP_GLOBAL(mem_cache), 0, NULL, delete_psdl, 1); } else if (SOAP_GLOBAL(cache_limit) > 0 && - SOAP_GLOBAL(cache_limit) <= zend_hash_num_elements(SOAP_GLOBAL(mem_cache))) { + SOAP_GLOBAL(cache_limit) <= (zend_long)zend_hash_num_elements(SOAP_GLOBAL(mem_cache))) { /* in-memory cache overflow */ sdl_cache_bucket *q; time_t latest = t; diff --git a/ext/soap/php_sdl.h b/ext/soap/php_sdl.h index f905b508cdf..26ca5c7d176 100644 --- a/ext/soap/php_sdl.h +++ b/ext/soap/php_sdl.h @@ -260,7 +260,7 @@ encodePtr get_encoder_from_prefix(sdlPtr sdl, xmlNodePtr data, const xmlChar *ty encodePtr get_encoder(sdlPtr sdl, const char *ns, const char *type); encodePtr get_encoder_ex(sdlPtr sdl, const char *nscat, int len); -sdlBindingPtr get_binding_from_type(sdlPtr sdl, int type); +sdlBindingPtr get_binding_from_type(sdlPtr sdl, sdlBindingType type); sdlBindingPtr get_binding_from_name(sdlPtr sdl, char *name, char *ns); void delete_sdl(void *handle); diff --git a/ext/soap/soap.c b/ext/soap/soap.c index 885116e2e9b..23bbfb6e84c 100644 --- a/ext/soap/soap.c +++ b/ext/soap/soap.c @@ -2157,7 +2157,7 @@ static void soap_error_handler(int error_num, const char *error_filename, const zval fault; char* code = SOAP_GLOBAL(error_code); char buffer[1024]; - int buffer_len; + size_t buffer_len; #ifdef va_copy va_list argcopy; #endif @@ -2172,7 +2172,7 @@ static void soap_error_handler(int error_num, const char *error_filename, const buffer_len = vslprintf(buffer, sizeof(buffer)-1, format, args); #endif buffer[sizeof(buffer)-1]=0; - if (buffer_len > sizeof(buffer) - 1 || buffer_len < 0) { + if (buffer_len > sizeof(buffer) - 1 || buffer_len == (size_t)-1) { buffer_len = sizeof(buffer) - 1; } @@ -2238,7 +2238,7 @@ static void soap_error_handler(int error_num, const char *error_filename, const !service->send_errors) { strcpy(buffer, "Internal Error"); } else { - int buffer_len; + size_t buffer_len; zval outbuflen; #ifdef va_copy @@ -2249,7 +2249,7 @@ static void soap_error_handler(int error_num, const char *error_filename, const buffer_len = vslprintf(buffer, sizeof(buffer)-1, format, args); #endif buffer[sizeof(buffer)-1]=0; - if (buffer_len > sizeof(buffer) - 1 || buffer_len < 0) { + if (buffer_len > sizeof(buffer) - 1 || buffer_len == (size_t)-1) { buffer_len = sizeof(buffer) - 1; } diff --git a/ext/sockets/conversions.c b/ext/sockets/conversions.c index 892442a88fd..46286a468d7 100644 --- a/ext/sockets/conversions.c +++ b/ext/sockets/conversions.c @@ -225,7 +225,7 @@ static unsigned from_array_iterate(const zval *arr, /* Note i starts at 1, not 0! */ i = 1; ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(arr), elem) { - if (snprintf(buf, sizeof(buf), "element #%u", i) >= sizeof(buf)) { + if ((size_t)snprintf(buf, sizeof(buf), "element #%u", i) >= sizeof(buf)) { memcpy(buf, "element", sizeof("element")); } zend_llist_add_element(&ctx->keys, &bufp); @@ -937,7 +937,7 @@ static void from_zval_write_control_array(const zval *arr, char *msghdr_c, ser_c break; } - if (snprintf(buf, sizeof(buf), "element #%u", (unsigned)i++) >= sizeof(buf)) { + if ((size_t)snprintf(buf, sizeof(buf), "element #%u", (unsigned)i++) >= sizeof(buf)) { memcpy(buf, "element", sizeof("element")); } zend_llist_add_element(&ctx->keys, &bufp); @@ -1019,7 +1019,7 @@ static void to_zval_read_control_array(const char *msghdr_c, zval *zv, res_conte ZVAL_NULL(&tmp); elem = zend_hash_next_index_insert(Z_ARRVAL_P(zv), &tmp); - if (snprintf(buf, sizeof(buf), "element #%u", (unsigned)i++) >= sizeof(buf)) { + if ((size_t)snprintf(buf, sizeof(buf), "element #%u", (unsigned)i++) >= sizeof(buf)) { memcpy(buf, "element", sizeof("element")); } zend_llist_add_element(&ctx->keys, &bufp); @@ -1061,7 +1061,7 @@ static void from_zval_write_msghdr_buffer_size(const zval *elem, char *msghdr_c, return; } - if (lval < 0 || lval > MAX_USER_BUFF_SIZE) { + if (lval < 0 || (zend_ulong)lval > MAX_USER_BUFF_SIZE) { do_from_zval_err(ctx, "the buffer size must be between 1 and " ZEND_LONG_FMT "; " "given " ZEND_LONG_FMT, (zend_long)MAX_USER_BUFF_SIZE, lval); return; @@ -1236,7 +1236,7 @@ static void from_zval_write_ifindex(const zval *zv, char *uinteger, ser_context unsigned ret = 0; if (Z_TYPE_P(zv) == IS_LONG) { - if (Z_LVAL_P(zv) < 0 || Z_LVAL_P(zv) > UINT_MAX) { /* allow 0 (unspecified interface) */ + if (Z_LVAL_P(zv) < 0 || (zend_ulong)Z_LVAL_P(zv) > UINT_MAX) { /* allow 0 (unspecified interface) */ do_from_zval_err(ctx, "the interface index cannot be negative or " "larger than %u; given " ZEND_LONG_FMT, UINT_MAX, Z_LVAL_P(zv)); } else { diff --git a/ext/sockets/multicast.c b/ext/sockets/multicast.c index 75984ec3233..fec762adf6b 100644 --- a/ext/sockets/multicast.c +++ b/ext/sockets/multicast.c @@ -90,7 +90,7 @@ static int php_get_if_index_from_zval(zval *val, unsigned *out) int ret; if (Z_TYPE_P(val) == IS_LONG) { - if (Z_LVAL_P(val) < 0 || Z_LVAL_P(val) > UINT_MAX) { + if (Z_LVAL_P(val) < 0 || (zend_ulong)Z_LVAL_P(val) > UINT_MAX) { php_error_docref(NULL, E_WARNING, "the interface index cannot be negative or larger than %u;" " given " ZEND_LONG_FMT, UINT_MAX, Z_LVAL_P(val)); diff --git a/ext/sockets/sendrecvmsg.c b/ext/sockets/sendrecvmsg.c index 72d8cfc47e4..330645598dd 100644 --- a/ext/sockets/sendrecvmsg.c +++ b/ext/sockets/sendrecvmsg.c @@ -304,8 +304,8 @@ PHP_FUNCTION(socket_cmsg_space) return; } - if (entry->var_el_size > 0 && n > (ZEND_LONG_MAX - (zend_long)entry->size - - (zend_long)CMSG_SPACE(0) - 15L) / entry->var_el_size) { + if (entry->var_el_size > 0 && n > (zend_long)((ZEND_LONG_MAX - entry->size - + CMSG_SPACE(0) - 15L) / entry->var_el_size)) { /* the -15 is to account for any padding CMSG_SPACE may add after the data */ php_error_docref0(NULL, E_WARNING, "The value for the " "third argument (" ZEND_LONG_FMT ") is too large", n); diff --git a/ext/sockets/sockaddr_conv.c b/ext/sockets/sockaddr_conv.c index 1ce109ee8c0..57996612d2d 100644 --- a/ext/sockets/sockaddr_conv.c +++ b/ext/sockets/sockaddr_conv.c @@ -66,7 +66,7 @@ int php_set_inet6_addr(struct sockaddr_in6 *sin6, char *string, php_socket *php_ unsigned scope_id = 0; if (IS_LONG == is_numeric_string(scope, strlen(scope), &lval, &dval, 0)) { - if (lval > 0 && lval <= UINT_MAX) { + if (lval > 0 && (zend_ulong)lval <= UINT_MAX) { scope_id = lval; } } else { diff --git a/ext/sockets/sockets.c b/ext/sockets/sockets.c index c289b0f9a3e..c23f984720c 100644 --- a/ext/sockets/sockets.c +++ b/ext/sockets/sockets.c @@ -1659,9 +1659,9 @@ PHP_FUNCTION(socket_send) RETURN_FALSE; } - retval = send(php_sock->bsd_socket, buf, (buf_len < len ? buf_len : len), flags); + retval = send(php_sock->bsd_socket, buf, (buf_len < (size_t)len ? buf_len : (size_t)len), flags); - if (retval == -1) { + if (retval == (size_t)-1) { PHP_SOCKET_ERROR(php_sock, "unable to write to socket", errno); RETURN_FALSE; } @@ -1827,7 +1827,7 @@ PHP_FUNCTION(socket_sendto) s_un.sun_family = AF_UNIX; snprintf(s_un.sun_path, 108, "%s", addr); - retval = sendto(php_sock->bsd_socket, buf, (len > buf_len) ? buf_len : len, flags, (struct sockaddr *) &s_un, SUN_LEN(&s_un)); + retval = sendto(php_sock->bsd_socket, buf, ((size_t)len > buf_len) ? buf_len : (size_t)len, flags, (struct sockaddr *) &s_un, SUN_LEN(&s_un)); break; case AF_INET: @@ -1843,7 +1843,7 @@ PHP_FUNCTION(socket_sendto) RETURN_FALSE; } - retval = sendto(php_sock->bsd_socket, buf, (len > buf_len) ? buf_len : len, flags, (struct sockaddr *) &sin, sizeof(sin)); + retval = sendto(php_sock->bsd_socket, buf, ((size_t)len > buf_len) ? buf_len : (size_t)len, flags, (struct sockaddr *) &sin, sizeof(sin)); break; #if HAVE_IPV6 case AF_INET6: @@ -1859,7 +1859,7 @@ PHP_FUNCTION(socket_sendto) RETURN_FALSE; } - retval = sendto(php_sock->bsd_socket, buf, (len > buf_len) ? buf_len : len, flags, (struct sockaddr *) &sin6, sizeof(sin6)); + retval = sendto(php_sock->bsd_socket, buf, ((size_t)len > buf_len) ? buf_len : (size_t)len, flags, (struct sockaddr *) &sin6, sizeof(sin6)); break; #endif default: diff --git a/ext/standard/array.c b/ext/standard/array.c index 4dba1a15f34..dd18f07ba63 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -2286,7 +2286,7 @@ long_str: Z_TYPE_INFO(tmp) = IS_LONG; if (low > high) { /* Negative steps */ - if (low - high < lstep) { + if ((zend_ulong)(low - high) < lstep) { err = 1; goto err; } @@ -2300,7 +2300,7 @@ long_str: } } ZEND_HASH_FILL_END(); } else if (high > low) { /* Positive steps */ - if (high - low < lstep) { + if ((zend_ulong)(high - low) < lstep) { err = 1; goto err; } @@ -2336,7 +2336,7 @@ static void php_array_data_shuffle(zval *array) /* {{{ */ Bucket *p, temp; HashTable *hash; zend_long rnd_idx; - uint32_t n_left; + zend_long n_left; n_elems = zend_hash_num_elements(Z_ARRVAL_P(array)); @@ -2429,12 +2429,12 @@ PHP_FUNCTION(shuffle) } /* }}} */ -static void php_splice(HashTable *in_hash, int offset, int length, HashTable *replace, HashTable *removed) /* {{{ */ +static void php_splice(HashTable *in_hash, zend_long offset, zend_long length, HashTable *replace, HashTable *removed) /* {{{ */ { HashTable out_hash; /* Output hashtable */ - int num_in, /* Number of entries in the input hashtable */ - pos; /* Current position in the hashtable */ - uint idx; + zend_long num_in; /* Number of entries in the input hashtable */ + zend_long pos; /* Current position in the hashtable */ + uint32_t idx; Bucket *p; /* Pointer to hash bucket */ zval *entry; /* Hash entry */ uint32_t iter_pos = zend_hash_iterators_lower_pos(in_hash, 0); @@ -2473,7 +2473,7 @@ static void php_splice(HashTable *in_hash, int offset, int length, HashTable *re zend_hash_add_new(&out_hash, p->key, entry); } if (idx == iter_pos) { - if (idx != pos) { + if ((zend_long)idx != pos) { zend_hash_iterators_update(in_hash, idx, pos); } iter_pos = zend_hash_iterators_lower_pos(in_hash, iter_pos + 1); @@ -2543,7 +2543,7 @@ static void php_splice(HashTable *in_hash, int offset, int length, HashTable *re zend_hash_add_new(&out_hash, p->key, entry); } if (idx == iter_pos) { - if (idx != pos) { + if ((zend_long)idx != pos) { zend_hash_iterators_update(in_hash, idx, pos); } iter_pos = zend_hash_iterators_lower_pos(in_hash, iter_pos + 1); @@ -2902,7 +2902,7 @@ PHP_FUNCTION(array_splice) } /* Perform splice */ - php_splice(Z_ARRVAL_P(array), (int)offset, (int)length, repl_array ? Z_ARRVAL_P(repl_array) : NULL, rem_hash); + php_splice(Z_ARRVAL_P(array), offset, length, repl_array ? Z_ARRVAL_P(repl_array) : NULL, rem_hash); } /* }}} */ @@ -3047,7 +3047,7 @@ PHPAPI int php_array_merge_recursive(HashTable *dest, HashTable *src) /* {{{ */ convert_to_array_ex(dest_zval); add_next_index_null(dest_zval); } else if (Z_TYPE_P(dest_zval) == IS_ARRAY) { - if (UNEXPECTED(Z_ARRVAL_P(dest_zval)->nNextFreeElement > Z_ARRVAL_P(dest_zval)->nNumUsed)) { + if (UNEXPECTED(Z_ARRVAL_P(dest_zval)->nNextFreeElement > (zend_long)Z_ARRVAL_P(dest_zval)->nNumUsed)) { Z_ARRVAL_P(dest_zval)->nNextFreeElement = Z_ARRVAL_P(dest_zval)->nNumUsed; } } else { @@ -4954,7 +4954,7 @@ PHP_FUNCTION(array_multisort) /* Make sure the arrays are of the same size. */ array_size = zend_hash_num_elements(Z_ARRVAL_P(arrays[0])); for (i = 0; i < num_arrays; i++) { - if (zend_hash_num_elements(Z_ARRVAL_P(arrays[i])) != array_size) { + if (zend_hash_num_elements(Z_ARRVAL_P(arrays[i])) != (uint32_t)array_size) { php_error_docref(NULL, E_WARNING, "Array sizes are inconsistent"); MULTISORT_ABORT; } diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 5a0d0a5d78b..439c0fdbae1 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -5138,7 +5138,8 @@ ZEND_API void php_get_highlight_struct(zend_syntax_highlighter_ini *syntax_highl PHP_FUNCTION(highlight_file) { char *filename; - size_t filename_len, ret; + size_t filename_len; + int ret; zend_syntax_highlighter_ini syntax_highlighter_ini; zend_bool i = 0; @@ -5181,7 +5182,7 @@ PHP_FUNCTION(php_strip_whitespace) char *filename; size_t filename_len; zend_lex_state original_lex_state; - zend_file_handle file_handle = {{0}}; + zend_file_handle file_handle; if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &filename, &filename_len) == FAILURE) { RETURN_FALSE; @@ -5189,6 +5190,7 @@ PHP_FUNCTION(php_strip_whitespace) php_output_start_default(); + memset(&file_handle, 0, sizeof(file_handle)); file_handle.type = ZEND_HANDLE_FILENAME; file_handle.filename = filename; file_handle.free_filename = 0; diff --git a/ext/standard/browscap.c b/ext/standard/browscap.c index f47478a2415..c283ebc6b96 100644 --- a/ext/standard/browscap.c +++ b/ext/standard/browscap.c @@ -73,7 +73,7 @@ static void browscap_entry_dtor_persistent(zval *zvalue) /* {{{ */ { static void convert_browscap_pattern(zval *pattern, int persistent) /* {{{ */ { - int i, j=0; + size_t i, j=0; char *t; zend_string *res; char *lc_pattern; @@ -216,7 +216,7 @@ static void php_browscap_parser_cb(zval *arg1, zval *arg2, zval *arg3, int callb static int browscap_read_file(char *filename, browser_data *browdata, int persistent) /* {{{ */ { - zend_file_handle fh = {{0}}; + zend_file_handle fh; if (filename == NULL || filename[0] == '\0') { return FAILURE; @@ -232,6 +232,7 @@ static int browscap_read_file(char *filename, browser_data *browdata, int persis :browscap_entry_dtor_request), persistent, 0); + memset(&fh, 0, sizeof(fh)); fh.handle.fp = VCWD_FOPEN(filename, "r"); fh.opened_path = NULL; fh.free_filename = 0; diff --git a/ext/standard/crypt_freesec.c b/ext/standard/crypt_freesec.c index dddab62a616..ba11bf98e8c 100644 --- a/ext/standard/crypt_freesec.c +++ b/ext/standard/crypt_freesec.c @@ -626,7 +626,7 @@ _crypt_extended_r(const char *key, const char *setting, * and padding with zeros. */ q = (u_char *) keybuf; - while (q - (u_char *) keybuf < sizeof(keybuf)) { + while ((size_t)(q - (u_char *) keybuf) < sizeof(keybuf)) { *q++ = *key << 1; if (*key) key++; @@ -667,7 +667,7 @@ _crypt_extended_r(const char *key, const char *setting, * And XOR with the next 8 characters of the key. */ q = (u_char *) keybuf; - while (q - (u_char *) keybuf < sizeof(keybuf) && *key) + while ((size_t)(q - (u_char *) keybuf) < sizeof(keybuf) && *key) *q++ ^= *key++ << 1; if (des_setkey((char *) keybuf, data)) diff --git a/ext/standard/dir.c b/ext/standard/dir.c index 8e0766127df..222c993c657 100644 --- a/ext/standard/dir.c +++ b/ext/standard/dir.c @@ -439,7 +439,7 @@ PHP_FUNCTION(glob) size_t pattern_len; zend_long flags = 0; glob_t globbuf; - int n; + size_t n; int ret; zend_bool basedir_limit = 0; diff --git a/ext/standard/exec.c b/ext/standard/exec.c index a73d0b4e6e0..6436a292783 100644 --- a/ext/standard/exec.c +++ b/ext/standard/exec.c @@ -54,14 +54,14 @@ #include #endif -static int cmd_max_len; +static size_t cmd_max_len; /* {{{ PHP_MINIT_FUNCTION(exec) */ PHP_MINIT_FUNCTION(exec) { #ifdef _SC_ARG_MAX cmd_max_len = sysconf(_SC_ARG_MAX); - if (-1 == cmd_max_len) { + if ((size_t)-1 == cmd_max_len) { #ifdef _POSIX_ARG_MAX cmd_max_len = _POSIX_ARG_MAX; #else @@ -278,7 +278,7 @@ PHP_FUNCTION(passthru) */ PHPAPI zend_string *php_escape_shell_cmd(char *str) { - register int x, y; + register size_t x, y; size_t l = strlen(str); uint64_t estimate = (2 * (uint64_t)l) + 1; zend_string *cmd; @@ -385,7 +385,7 @@ PHPAPI zend_string *php_escape_shell_cmd(char *str) */ PHPAPI zend_string *php_escape_shell_arg(char *str) { - int x, y = 0; + size_t x, y = 0; size_t l = strlen(str); zend_string *cmd; uint64_t estimate = (4 * (uint64_t)l) + 3; diff --git a/ext/standard/file.c b/ext/standard/file.c index dcd13fa9a3a..d89093ffd13 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -576,7 +576,7 @@ PHP_FUNCTION(file_put_contents) char *filename; size_t filename_len; zval *data; - zend_long numbytes = 0; + size_t numbytes = 0; zend_long flags = 0; zval *zcontext = NULL; php_stream_context *context = NULL; @@ -695,7 +695,7 @@ PHP_FUNCTION(file_put_contents) } php_stream_close(stream); - if (numbytes < 0) { + if (numbytes == (size_t)-1) { RETURN_FALSE; } diff --git a/ext/standard/ftp_fopen_wrapper.c b/ext/standard/ftp_fopen_wrapper.c index c85a506d973..41bed54658f 100644 --- a/ext/standard/ftp_fopen_wrapper.c +++ b/ext/standard/ftp_fopen_wrapper.c @@ -828,11 +828,11 @@ static int php_stream_ftp_url_stat(php_stream_wrapper *wrapper, const char *url, struct tm tm, tmbuf, *gmt; time_t stamp; - while (p - tmp_line < sizeof(tmp_line) && !isdigit(*p)) { + while ((size_t)(p - tmp_line) < sizeof(tmp_line) && !isdigit(*p)) { p++; } - if (p - tmp_line > sizeof(tmp_line)) { + if ((size_t)(p - tmp_line) > sizeof(tmp_line)) { goto mdtm_error; } @@ -1177,7 +1177,8 @@ static php_stream_wrapper_ops ftp_stream_wops = { php_stream_ftp_unlink, /* unlink */ php_stream_ftp_rename, /* rename */ php_stream_ftp_mkdir, /* mkdir */ - php_stream_ftp_rmdir /* rmdir */ + php_stream_ftp_rmdir, /* rmdir */ + NULL }; PHPAPI php_stream_wrapper php_stream_ftp_wrapper = { diff --git a/ext/standard/http_fopen_wrapper.c b/ext/standard/http_fopen_wrapper.c index fd996d1763f..ec57cab2b68 100644 --- a/ext/standard/http_fopen_wrapper.c +++ b/ext/standard/http_fopen_wrapper.c @@ -969,7 +969,8 @@ static php_stream_wrapper_ops http_stream_wops = { NULL, /* unlink */ NULL, /* rename */ NULL, /* mkdir */ - NULL /* rmdir */ + NULL, /* rmdir */ + NULL }; PHPAPI php_stream_wrapper php_stream_http_wrapper = { diff --git a/ext/standard/iptc.c b/ext/standard/iptc.c index 7e5a8987b4c..04e51b00c19 100644 --- a/ext/standard/iptc.c +++ b/ext/standard/iptc.c @@ -191,7 +191,7 @@ PHP_FUNCTION(iptcembed) zend_long spool = 0; FILE *fp; unsigned int marker, done = 0; - int inx; + size_t inx; zend_string *spoolbuf = NULL; unsigned char *poi = NULL; zend_stat_t sb; @@ -314,7 +314,7 @@ PHP_FUNCTION(iptcembed) Parse binary IPTC-data into associative array */ PHP_FUNCTION(iptcparse) { - int inx = 0, len; + size_t inx = 0, len; unsigned int tagsfound = 0; unsigned char *buffer, recnum, dataset; char *str, key[16]; @@ -358,7 +358,7 @@ PHP_FUNCTION(iptcparse) inx += 2; } - if ((len < 0) || (len > str_len) || (inx + len) > str_len) { + if ((len > str_len) || (inx + len) > str_len) { break; } diff --git a/ext/standard/metaphone.c b/ext/standard/metaphone.c index 73290e9d70f..11968a6fb6d 100644 --- a/ext/standard/metaphone.c +++ b/ext/standard/metaphone.c @@ -168,7 +168,7 @@ static char Lookahead(char *word, int how_far) static int metaphone(unsigned char *word, size_t word_len, zend_long max_phonemes, zend_string **phoned_word, int traditional) { int w_idx = 0; /* point in the phonization we're at. */ - int p_idx = 0; /* end of the phoned phrase */ + size_t p_idx = 0; /* end of the phoned phrase */ size_t max_buffer_len = 0; /* maximum length of the destination buffer */ /*-- Parameter checks --*/ @@ -265,7 +265,7 @@ static int metaphone(unsigned char *word, size_t word_len, zend_long max_phoneme /* On to the metaphoning */ for (; Curr_Letter != '\0' && - (max_phonemes == 0 || Phone_Len < max_phonemes); + (max_phonemes == 0 || Phone_Len < (size_t)max_phonemes); w_idx++) { /* How many letters to skip because an eariler encoding handled * multiple letters */ diff --git a/ext/standard/pack.c b/ext/standard/pack.c index 1d353d1743d..1252f4286f8 100644 --- a/ext/standard/pack.c +++ b/ext/standard/pack.c @@ -92,7 +92,7 @@ static int little_endian_longlong_map[8]; */ static void php_pack(zval *val, size_t size, int *map, char *output) { - int i; + size_t i; char *v; convert_to_long_ex(val); @@ -112,13 +112,14 @@ static void php_pack(zval *val, size_t size, int *map, char *output) PHP_FUNCTION(pack) { zval *argv = NULL; - int num_args = 0, i; + int num_args = 0; + size_t i; int currentarg; char *format; size_t formatlen; char *formatcodes; int *formatargs; - int formatcount = 0; + size_t formatcount = 0; int outputpos = 0, outputsize = 0; zend_string *output; @@ -334,7 +335,7 @@ PHP_FUNCTION(pack) case 'a': case 'A': case 'Z': { - int arg_cp = (code != 'Z') ? arg : MAX(0, arg - 1); + size_t arg_cp = (code != 'Z') ? arg : MAX(0, arg - 1); zend_string *str = zval_get_string(&argv[currentarg++]); @@ -356,7 +357,7 @@ PHP_FUNCTION(pack) char *v = ZSTR_VAL(str); outputpos--; - if(arg > ZSTR_LEN(str)) { + if ((size_t)arg > ZSTR_LEN(str)) { php_error_docref(NULL, E_WARNING, "Type %c: not enough characters in string", code); arg = ZSTR_LEN(str); } @@ -519,7 +520,7 @@ static zend_long php_unpack(char *data, size_t size, int issigned, int *map) { zend_long result; char *cresult = (char *) &result; - int i; + size_t i; result = issigned ? -1 : 0; @@ -726,7 +727,7 @@ PHP_FUNCTION(unpack) switch ((int) type) { case 'a': { /* a will not strip any trailing whitespace or null padding */ - size_t len = inputlen - inputpos; /* Remaining string */ + zend_long len = inputlen - inputpos; /* Remaining string */ /* If size was given take minimum of len and size */ if ((size >= 0) && (len > size)) { @@ -768,7 +769,7 @@ PHP_FUNCTION(unpack) case 'Z': { /* Z will strip everything after the first null character */ char pad = '\0'; - size_t s, + zend_long s, len = inputlen - inputpos; /* Remaining string */ /* If size was given take minimum of len and size */ @@ -792,11 +793,11 @@ PHP_FUNCTION(unpack) case 'h': case 'H': { - size_t len = (inputlen - inputpos) * 2; /* Remaining */ + zend_long len = (inputlen - inputpos) * 2; /* Remaining */ int nibbleshift = (type == 'h') ? 0 : 4; int first = 1; char *buf; - size_t ipos, opos; + zend_long ipos, opos; /* If size was given take minimum of len and size */ if (size >= 0 && len > (size * 2)) { diff --git a/ext/standard/password.c b/ext/standard/password.c index 2a5cec3e93b..d01ddb0563c 100644 --- a/ext/standard/password.c +++ b/ext/standard/password.c @@ -194,7 +194,7 @@ PHP_FUNCTION(password_needs_rehash) algo = php_password_determine_algo(hash, (size_t) hash_len); - if (algo != new_algo) { + if ((zend_long)algo != new_algo) { RETURN_TRUE; } @@ -224,8 +224,8 @@ PHP_FUNCTION(password_needs_rehash) Verify a hash created using crypt() or password_hash() */ PHP_FUNCTION(password_verify) { - int status = 0, i; - size_t password_len, hash_len; + int status = 0; + size_t i, password_len, hash_len; char *password, *hash; zend_string *ret; diff --git a/ext/standard/php_fopen_wrapper.c b/ext/standard/php_fopen_wrapper.c index 759a4f6a332..dbd0a3fba1d 100644 --- a/ext/standard/php_fopen_wrapper.c +++ b/ext/standard/php_fopen_wrapper.c @@ -437,7 +437,8 @@ static php_stream_wrapper_ops php_stdio_wops = { NULL, /* unlink */ NULL, /* rename */ NULL, /* mkdir */ - NULL /* rmdir */ + NULL, /* rmdir */ + NULL }; PHPAPI php_stream_wrapper php_stream_php_wrapper = { diff --git a/ext/standard/php_incomplete_class.h b/ext/standard/php_incomplete_class.h index ab5b3a3fd74..da262e8b58a 100644 --- a/ext/standard/php_incomplete_class.h +++ b/ext/standard/php_incomplete_class.h @@ -43,7 +43,7 @@ #define PHP_CLASS_ATTRIBUTES \ zend_string *class_name; \ - zend_bool incomplete_class = 0 + zend_bool incomplete_class ZEND_ATTRIBUTE_UNUSED = 0 #define INCOMPLETE_CLASS "__PHP_Incomplete_Class" #define MAGIC_MEMBER "__PHP_Incomplete_Class_Name" diff --git a/ext/standard/string.c b/ext/standard/string.c index f5f0a245683..1efb266c82f 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -978,7 +978,7 @@ PHP_FUNCTION(wordwrap) newtext = zend_string_init(ZSTR_VAL(text), ZSTR_LEN(text), 0); laststart = lastspace = 0; - for (current = 0; current < ZSTR_LEN(text); current++) { + for (current = 0; current < (zend_long)ZSTR_LEN(text); current++) { if (ZSTR_VAL(text)[current] == breakchar[0]) { laststart = lastspace = current + 1; } else if (ZSTR_VAL(text)[current] == ' ') { @@ -1010,7 +1010,7 @@ PHP_FUNCTION(wordwrap) newtextlen = 0; laststart = lastspace = 0; - for (current = 0; current < ZSTR_LEN(text); current++) { + for (current = 0; current < (zend_long)ZSTR_LEN(text); current++) { if (chk <= 0) { alloced += (size_t) (((ZSTR_LEN(text) - current + 1)/linelength + 1) * breakchar_len) + 1; newtext = zend_string_extend(newtext, alloced, 0); @@ -1754,7 +1754,7 @@ PHP_FUNCTION(pathinfo) p = zend_memrchr(ZSTR_VAL(ret), '.', ZSTR_LEN(ret)); - idx = p ? (p - ZSTR_VAL(ret)) : ZSTR_LEN(ret); + idx = p ? (p - ZSTR_VAL(ret)) : (ptrdiff_t)ZSTR_LEN(ret); add_assoc_stringl(&tmp, "filename", ZSTR_VAL(ret), idx); } @@ -2131,7 +2131,7 @@ PHP_FUNCTION(strrpos) RETURN_FALSE; } p = ZSTR_VAL(haystack); - if (-offset < needle_len) { + if ((size_t)-offset < needle_len) { e = ZSTR_VAL(haystack) + ZSTR_LEN(haystack); } else { e = ZSTR_VAL(haystack) + ZSTR_LEN(haystack) + offset + needle_len; @@ -2232,7 +2232,7 @@ PHP_FUNCTION(strripos) RETURN_FALSE; } p = ZSTR_VAL(haystack_dup); - if (-offset < ZSTR_LEN(needle)) { + if ((size_t)-offset < ZSTR_LEN(needle)) { e = ZSTR_VAL(haystack_dup) + ZSTR_LEN(haystack); } else { e = ZSTR_VAL(haystack_dup) + ZSTR_LEN(haystack) + offset + ZSTR_LEN(needle); @@ -2412,7 +2412,7 @@ PHP_FUNCTION(substr) if (f > (zend_long)ZSTR_LEN(str)) { RETURN_FALSE; - } else if (f < 0 && -f > ZSTR_LEN(str)) { + } else if (f < 0 && (size_t)-f > ZSTR_LEN(str)) { f = 0; } @@ -2518,7 +2518,7 @@ PHP_FUNCTION(substr_replace) if (f < 0) { f = 0; } - } else if (f > Z_STRLEN_P(str)) { + } else if ((size_t)f > Z_STRLEN_P(str)) { f = Z_STRLEN_P(str); } /* if "length" position is negative, set it to the length @@ -2531,7 +2531,7 @@ PHP_FUNCTION(substr_replace) } } - if (l > Z_STRLEN_P(str) || (l < 0 && (size_t)(-l) > Z_STRLEN_P(str))) { + if ((size_t)l > Z_STRLEN_P(str) || (l < 0 && (size_t)(-l) > Z_STRLEN_P(str))) { l = Z_STRLEN_P(str); } @@ -4212,8 +4212,8 @@ static void php_hebrev(INTERNAL_FUNCTION_PARAMETERS, int convert_newlines) char *str; char *heb_str, *tmp, *target; size_t block_start, block_end, block_type, block_length, i; - zend_long max_chars=0; - size_t begin, end, char_count, orig_begin; + zend_long max_chars=0, char_count; + size_t begin, end, orig_begin; size_t str_len; zend_string *broken_str; @@ -5324,7 +5324,7 @@ PHP_FUNCTION(substr_count) if (length <= 0) { length += (haystack_len - offset); } - if ((length <= 0) || (length > (haystack_len - offset))) { + if ((length <= 0) || ((size_t)length > (haystack_len - offset))) { php_error_docref(NULL, E_WARNING, "Invalid length value"); RETURN_FALSE; } @@ -5746,7 +5746,7 @@ PHP_FUNCTION(substr_compare) RETURN_FALSE; } - cmp_len = (size_t) (len ? len : MAX(ZSTR_LEN(s2), (ZSTR_LEN(s1) - offset))); + cmp_len = len ? (size_t)len : MAX(ZSTR_LEN(s2), (ZSTR_LEN(s1) - offset)); if (!cs) { RETURN_LONG(zend_binary_strncmp(ZSTR_VAL(s1) + offset, (ZSTR_LEN(s1) - offset), ZSTR_VAL(s2), ZSTR_LEN(s2), cmp_len)); diff --git a/ext/standard/type.c b/ext/standard/type.c index 529d666d02d..5350e13ec5e 100644 --- a/ext/standard/type.c +++ b/ext/standard/type.c @@ -416,7 +416,7 @@ PHP_FUNCTION(is_callable) retval = zend_is_callable_ex(var, NULL, check_flags, &name, NULL, &error); zval_dtor(callable_name); //??? is it necessary to be consistent with old PHP ("\0" support) - if (UNEXPECTED(ZSTR_LEN(name)) != strlen(ZSTR_VAL(name))) { + if (UNEXPECTED(ZSTR_LEN(name) != strlen(ZSTR_VAL(name)))) { ZVAL_STRINGL(callable_name, ZSTR_VAL(name), strlen(ZSTR_VAL(name))); zend_string_release(name); } else { diff --git a/ext/standard/user_filters.c b/ext/standard/user_filters.c index 4434fd1f0d2..b31235b4f13 100644 --- a/ext/standard/user_filters.c +++ b/ext/standard/user_filters.c @@ -452,7 +452,7 @@ static void php_stream_bucket_attach(int append, INTERNAL_FUNCTION_PARAMETERS) if (!bucket->own_buf) { bucket = php_stream_bucket_make_writeable(bucket); } - if ((int)bucket->buflen != Z_STRLEN_P(pzdata)) { + if (bucket->buflen != Z_STRLEN_P(pzdata)) { bucket->buf = perealloc(bucket->buf, Z_STRLEN_P(pzdata), bucket->is_persistent); bucket->buflen = Z_STRLEN_P(pzdata); } diff --git a/ext/sysvshm/sysvshm.c b/ext/sysvshm/sysvshm.c index 55381dbbed2..a0a2f039b23 100644 --- a/ext/sysvshm/sysvshm.c +++ b/ext/sysvshm/sysvshm.c @@ -169,7 +169,7 @@ PHP_FUNCTION(shm_attach) /* get the id from a specified key or create new shared memory */ if ((shm_id = shmget(shm_key, 0, 0)) < 0) { - if (shm_size < sizeof(sysvshm_chunk_head)) { + if (shm_size < (zend_long)sizeof(sysvshm_chunk_head)) { php_error_docref(NULL, E_WARNING, "failed for key 0x" ZEND_XLONG_FMT ": memorysize too small", shm_key); efree(shm_list_ptr); RETURN_FALSE; diff --git a/ext/xml/xml.c b/ext/xml/xml.c index fe29f2891d1..bf497b2d7c1 100644 --- a/ext/xml/xml.c +++ b/ext/xml/xml.c @@ -638,7 +638,7 @@ PHP_XML_API zend_string *xml_utf8_decode(const XML_Char *s, size_t len, const XM c = '?'; } - ZSTR_VAL(str)[ZSTR_LEN(str)++] = decoder ? decoder(c) : c; + ZSTR_VAL(str)[ZSTR_LEN(str)++] = decoder ? (unsigned int)decoder(c) : c; } ZSTR_VAL(str)[ZSTR_LEN(str)] = '\0'; if (ZSTR_LEN(str) < len) { @@ -864,7 +864,7 @@ void _xml_characterDataHandler(void *userData, const XML_Char *s, int len) } if (!Z_ISUNDEF(parser->data)) { - int i; + size_t i; int doprint = 0; zend_string *decoded_value;