From f97698702d0e8dd808bd90ad4285c863ac4f04c1 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sat, 17 Feb 2024 15:24:08 +0000 Subject: [PATCH] General: Consistently cast return value to `int` in functions that use `ceil()`. The return value of `ceil()` is still of type `float` as the value range of `float` is usually bigger than that of `int`. Props crstauf, audrasjb. Fixes #58683. Built from https://develop.svn.wordpress.org/trunk@57648 git-svn-id: http://core.svn.wordpress.org/trunk@57149 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/ajax-actions.php | 8 ++++---- wp-admin/includes/class-wp-list-table.php | 2 +- wp-admin/includes/media.php | 2 +- wp-admin/includes/nav-menu.php | 2 +- wp-includes/class-wp-comment-query.php | 2 +- wp-includes/class-wp-network-query.php | 2 +- wp-includes/class-wp-query.php | 2 +- wp-includes/class-wp-site-query.php | 2 +- wp-includes/class-wp-walker.php | 4 ++-- wp-includes/comment-template.php | 2 +- wp-includes/comment.php | 4 ++-- wp-includes/embed.php | 4 ++-- .../endpoints/class-wp-rest-comments-controller.php | 2 +- .../class-wp-rest-font-collections-controller.php | 2 +- .../class-wp-rest-global-styles-revisions-controller.php | 2 +- .../rest-api/endpoints/class-wp-rest-posts-controller.php | 2 +- .../endpoints/class-wp-rest-revisions-controller.php | 2 +- .../endpoints/class-wp-rest-search-controller.php | 2 +- .../rest-api/endpoints/class-wp-rest-terms-controller.php | 6 +++--- .../rest-api/endpoints/class-wp-rest-users-controller.php | 6 +++--- wp-includes/version.php | 2 +- 21 files changed, 31 insertions(+), 31 deletions(-) diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php index 7541b28d51..f8b6ac4589 100644 --- a/wp-admin/includes/ajax-actions.php +++ b/wp-admin/includes/ajax-actions.php @@ -561,8 +561,8 @@ function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) { 'postId' => $comment ? $comment->comment_post_ID : '', /* translators: %s: Number of comments. */ 'total_items_i18n' => sprintf( _n( '%s item', '%s items', $total ), number_format_i18n( $total ) ), - 'total_pages' => ceil( $total / $per_page ), - 'total_pages_i18n' => number_format_i18n( ceil( $total / $per_page ) ), + 'total_pages' => (int) ceil( $total / $per_page ), + 'total_pages_i18n' => number_format_i18n( (int) ceil( $total / $per_page ) ), 'total' => $total, 'time' => $time, 'in_moderation' => $counts->moderated, @@ -3089,10 +3089,10 @@ function wp_ajax_query_attachments() { $posts_per_page = (int) $attachments_query->get( 'posts_per_page' ); - $max_pages = $posts_per_page ? ceil( $total_posts / $posts_per_page ) : 0; + $max_pages = $posts_per_page ? (int) ceil( $total_posts / $posts_per_page ) : 0; header( 'X-WP-Total: ' . (int) $total_posts ); - header( 'X-WP-TotalPages: ' . (int) $max_pages ); + header( 'X-WP-TotalPages: ' . $max_pages ); wp_send_json_success( $posts ); } diff --git a/wp-admin/includes/class-wp-list-table.php b/wp-admin/includes/class-wp-list-table.php index 4b86a9b286..4e6aaa4854 100644 --- a/wp-admin/includes/class-wp-list-table.php +++ b/wp-admin/includes/class-wp-list-table.php @@ -319,7 +319,7 @@ class WP_List_Table { ); if ( ! $args['total_pages'] && $args['per_page'] > 0 ) { - $args['total_pages'] = ceil( $args['total_items'] / $args['per_page'] ); + $args['total_pages'] = (int) ceil( $args['total_items'] / $args['per_page'] ); } // Redirect if page number is invalid and headers are not already sent. diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index 193e67f7dd..3de25dc548 100644 --- a/wp-admin/includes/media.php +++ b/wp-admin/includes/media.php @@ -2832,7 +2832,7 @@ function media_upload_library_form( $errors ) { 'format' => '', 'prev_text' => __( '«' ), 'next_text' => __( '»' ), - 'total' => ceil( $wp_query->found_posts / 10 ), + 'total' => (int) ceil( $wp_query->found_posts / 10 ), 'current' => $q['paged'], ) ); diff --git a/wp-admin/includes/nav-menu.php b/wp-admin/includes/nav-menu.php index 704f0316db..8f18057c23 100644 --- a/wp-admin/includes/nav-menu.php +++ b/wp-admin/includes/nav-menu.php @@ -874,7 +874,7 @@ function wp_nav_menu_item_taxonomy_meta_box( $data_object, $box ) { return; } - $num_pages = ceil( + $num_pages = (int) ceil( wp_count_terms( array_merge( $args, diff --git a/wp-includes/class-wp-comment-query.php b/wp-includes/class-wp-comment-query.php index e2ea55a22c..448b7994d8 100644 --- a/wp-includes/class-wp-comment-query.php +++ b/wp-includes/class-wp-comment-query.php @@ -470,7 +470,7 @@ class WP_Comment_Query { } if ( $this->found_comments && $this->query_vars['number'] ) { - $this->max_num_pages = ceil( $this->found_comments / $this->query_vars['number'] ); + $this->max_num_pages = (int) ceil( $this->found_comments / $this->query_vars['number'] ); } // If querying for a count only, there's nothing more to do. diff --git a/wp-includes/class-wp-network-query.php b/wp-includes/class-wp-network-query.php index 7199ec03a1..9dc2984f2e 100644 --- a/wp-includes/class-wp-network-query.php +++ b/wp-includes/class-wp-network-query.php @@ -269,7 +269,7 @@ class WP_Network_Query { } if ( $this->found_networks && $this->query_vars['number'] ) { - $this->max_num_pages = ceil( $this->found_networks / $this->query_vars['number'] ); + $this->max_num_pages = (int) ceil( $this->found_networks / $this->query_vars['number'] ); } // If querying for a count only, there's nothing more to do. diff --git a/wp-includes/class-wp-query.php b/wp-includes/class-wp-query.php index f683a52bd1..a826dda5ec 100644 --- a/wp-includes/class-wp-query.php +++ b/wp-includes/class-wp-query.php @@ -3624,7 +3624,7 @@ class WP_Query { $this->found_posts = (int) apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) ); if ( ! empty( $limits ) ) { - $this->max_num_pages = ceil( $this->found_posts / $q['posts_per_page'] ); + $this->max_num_pages = (int) ceil( $this->found_posts / $q['posts_per_page'] ); } } diff --git a/wp-includes/class-wp-site-query.php b/wp-includes/class-wp-site-query.php index 10a9b18339..bda2c0cb2a 100644 --- a/wp-includes/class-wp-site-query.php +++ b/wp-includes/class-wp-site-query.php @@ -377,7 +377,7 @@ class WP_Site_Query { } if ( $this->found_sites && $this->query_vars['number'] ) { - $this->max_num_pages = ceil( $this->found_sites / $this->query_vars['number'] ); + $this->max_num_pages = (int) ceil( $this->found_sites / $this->query_vars['number'] ); } // If querying for a count only, there's nothing more to do. diff --git a/wp-includes/class-wp-walker.php b/wp-includes/class-wp-walker.php index d8c00a3723..e44907ee70 100644 --- a/wp-includes/class-wp-walker.php +++ b/wp-includes/class-wp-walker.php @@ -310,7 +310,7 @@ class Walker { $start = ( (int) $page_num - 1 ) * (int) $per_page; $end = $start + $per_page; if ( -1 == $max_depth ) { - $this->max_pages = ceil( $total_top / $per_page ); + $this->max_pages = (int) ceil( $total_top / $per_page ); } } @@ -354,7 +354,7 @@ class Walker { $total_top = count( $top_level_elements ); if ( $paging ) { - $this->max_pages = ceil( $total_top / $per_page ); + $this->max_pages = (int) ceil( $total_top / $per_page ); } else { $end = $total_top; } diff --git a/wp-includes/comment-template.php b/wp-includes/comment-template.php index a1005d56e2..29f440f3a7 100644 --- a/wp-includes/comment-template.php +++ b/wp-includes/comment-template.php @@ -1515,7 +1515,7 @@ function comments_template( $file = '/comments.php', $separate_comments = false $top_level_count = $top_level_query->query( $top_level_args ); - $comment_args['offset'] = ( ceil( $top_level_count / $per_page ) - 1 ) * $per_page; + $comment_args['offset'] = ( (int) ceil( $top_level_count / $per_page ) - 1 ) * $per_page; } } diff --git a/wp-includes/comment.php b/wp-includes/comment.php index 3d11867b07..cca3901207 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -1031,7 +1031,7 @@ function get_comment_pages_count( $comments = null, $per_page = null, $threaded $count = ceil( count( $comments ) / $per_page ); } - return $count; + return (int) $count; } /** @@ -1170,7 +1170,7 @@ function get_page_of_comment( $comment_id, $args = array() ) { // Divide comments older than this one by comments per page to get this comment's page number. } else { - $page = ceil( ( $older_comment_count + 1 ) / $args['per_page'] ); + $page = (int) ceil( ( $older_comment_count + 1 ) / $args['per_page'] ); } } diff --git a/wp-includes/embed.php b/wp-includes/embed.php index 9e59f1abc0..82cb45d314 100644 --- a/wp-includes/embed.php +++ b/wp-includes/embed.php @@ -73,7 +73,7 @@ function wp_embed_defaults( $url = '' ) { $width = 500; } - $height = min( ceil( $width * 1.5 ), 1000 ); + $height = min( (int) ceil( $width * 1.5 ), 1000 ); /** * Filters the default array of embed dimensions. @@ -577,7 +577,7 @@ function get_oembed_response_data( $post, $width ) { ); $width = min( max( $min_max_width['min'], $width ), $min_max_width['max'] ); - $height = max( ceil( $width / 16 * 9 ), 200 ); + $height = max( (int) ceil( $width / 16 * 9 ), 200 ); $data = array( 'version' => '1.0', diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php index 3a367e7e22..c129ef6e13 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php @@ -300,7 +300,7 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { $prepared_args['orderby'] = 'none'; $total_comments = $query->query( $prepared_args ); - $max_pages = ceil( $total_comments / $request['per_page'] ); + $max_pages = (int) ceil( $total_comments / $request['per_page'] ); } $response = rest_ensure_response( $comments ); diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-font-collections-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-font-collections-controller.php index 05ef0c7b11..3ede1dacdc 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-font-collections-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-font-collections-controller.php @@ -77,7 +77,7 @@ class WP_REST_Font_Collections_Controller extends WP_REST_Controller { $page = $request['page']; $per_page = $request['per_page']; $total_items = count( $collections_all ); - $max_pages = ceil( $total_items / $per_page ); + $max_pages = (int) ceil( $total_items / $per_page ); if ( $page > $max_pages && $total_items > 0 ) { return new WP_Error( diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-revisions-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-revisions-controller.php index db1be197e5..5f5ae8441c 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-revisions-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-revisions-controller.php @@ -206,7 +206,7 @@ class WP_REST_Global_Styles_Revisions_Controller extends WP_REST_Controller { } if ( $revisions_query->query_vars['posts_per_page'] > 0 ) { - $max_pages = ceil( $total_revisions / (int) $revisions_query->query_vars['posts_per_page'] ); + $max_pages = (int) ceil( $total_revisions / (int) $revisions_query->query_vars['posts_per_page'] ); } else { $max_pages = $total_revisions > 0 ? 1 : 0; } diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index ce99d0dde1..4501e47a24 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -403,7 +403,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { $total_posts = $count_query->found_posts; } - $max_pages = ceil( $total_posts / (int) $posts_query->query_vars['posts_per_page'] ); + $max_pages = (int) ceil( $total_posts / (int) $posts_query->query_vars['posts_per_page'] ); if ( $page > $max_pages && $total_posts > 0 ) { return new WP_Error( diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php index 62dff71c16..fb5fa29231 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php @@ -308,7 +308,7 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller { } if ( $revisions_query->query_vars['posts_per_page'] > 0 ) { - $max_pages = ceil( $total_revisions / (int) $revisions_query->query_vars['posts_per_page'] ); + $max_pages = (int) ceil( $total_revisions / (int) $revisions_query->query_vars['posts_per_page'] ); } else { $max_pages = $total_revisions > 0 ? 1 : 0; } diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php index 4c44f67578..cc1c302b9c 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php @@ -152,7 +152,7 @@ class WP_REST_Search_Controller extends WP_REST_Controller { $total = (int) $result[ WP_REST_Search_Handler::RESULT_TOTAL ]; $page = (int) $request['page']; $per_page = (int) $request['per_page']; - $max_pages = ceil( $total / $per_page ); + $max_pages = (int) ceil( $total / $per_page ); if ( $page > $max_pages && $total > 0 ) { return new WP_Error( diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php index cf9dc917c4..8ffc6ade6e 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php @@ -348,13 +348,13 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { // Store pagination values for headers. $per_page = (int) $prepared_args['number']; - $page = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 ); + $page = (int) ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 ); $response->header( 'X-WP-Total', (int) $total_terms ); - $max_pages = ceil( $total_terms / $per_page ); + $max_pages = (int) ceil( $total_terms / $per_page ); - $response->header( 'X-WP-TotalPages', (int) $max_pages ); + $response->header( 'X-WP-TotalPages', $max_pages ); $request_params = $request->get_query_params(); $collection_url = rest_url( rest_get_route_for_taxonomy_items( $this->taxonomy ) ); diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php index 9b38470631..c2e0db83c5 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php @@ -348,7 +348,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller { // Store pagination values for headers then unset for count query. $per_page = (int) $prepared_args['number']; - $page = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 ); + $page = (int) ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 ); $prepared_args['fields'] = 'ID'; @@ -363,9 +363,9 @@ class WP_REST_Users_Controller extends WP_REST_Controller { $response->header( 'X-WP-Total', (int) $total_users ); - $max_pages = ceil( $total_users / $per_page ); + $max_pages = (int) ceil( $total_users / $per_page ); - $response->header( 'X-WP-TotalPages', (int) $max_pages ); + $response->header( 'X-WP-TotalPages', $max_pages ); $base = add_query_arg( urlencode_deep( $request->get_query_params() ), rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ) ); if ( $page > 1 ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index 55610b1432..ddcb7b75cd 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.5-beta1-57647'; +$wp_version = '6.5-beta1-57648'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.