From d25d45e4d9221948e6b0d80ce22ce559e99c2f48 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Mon, 30 Jul 2018 17:03:19 -0400 Subject: Verify range bounds to bms_add_range when necessary Now that the bms_add_range boundary protections are gone, some alternative ones are needed in a few places. Author: Amit Langote Discussion: https://postgr.es/m/3437ccf8-a144-55ff-1e2f-fc16b437823b@lab.ntt.co.jp --- src/backend/partitioning/partprune.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/backend/partitioning') diff --git a/src/backend/partitioning/partprune.c b/src/backend/partitioning/partprune.c index 354eb0d4e60..bfacc2ce297 100644 --- a/src/backend/partitioning/partprune.c +++ b/src/backend/partitioning/partprune.c @@ -486,7 +486,10 @@ get_matching_partitions(PartitionPruneContext *context, List *pruning_steps) /* If there are no pruning steps then all partitions match. */ if (num_steps == 0) + { + Assert(context->nparts > 0); return bms_add_range(NULL, 0, context->nparts - 1); + } /* * Allocate space for individual pruning steps to store its result. Each @@ -2048,8 +2051,12 @@ get_matching_hash_bounds(PartitionPruneContext *context, bms_make_singleton(rowHash % greatest_modulus); } else + { + /* Getting here means at least one hash partition exists. */ + Assert(boundinfo->ndatums > 0); result->bound_offsets = bms_add_range(NULL, 0, boundinfo->ndatums - 1); + } /* * There is neither a special hash null partition or the default hash @@ -2128,6 +2135,7 @@ get_matching_list_bounds(PartitionPruneContext *context, */ if (nvalues == 0) { + Assert(boundinfo->ndatums > 0); result->bound_offsets = bms_add_range(NULL, 0, boundinfo->ndatums - 1); result->scan_default = partition_bound_has_default(boundinfo); @@ -2140,6 +2148,7 @@ get_matching_list_bounds(PartitionPruneContext *context, /* * First match to all bounds. We'll remove any matching datums below. */ + Assert(boundinfo->ndatums > 0); result->bound_offsets = bms_add_range(NULL, 0, boundinfo->ndatums - 1); @@ -2250,6 +2259,7 @@ get_matching_list_bounds(PartitionPruneContext *context, break; } + Assert(minoff >= 0 && maxoff >= 0); result->bound_offsets = bms_add_range(NULL, minoff, maxoff); return result; } @@ -2327,6 +2337,7 @@ get_matching_range_bounds(PartitionPruneContext *context, maxoff--; result->scan_default = partition_bound_has_default(boundinfo); + Assert(minoff >= 0 && maxoff >= 0); result->bound_offsets = bms_add_range(NULL, minoff, maxoff); return result; -- cgit v1.2.3