diff options
author | Robert Haas <rhaas@postgresql.org> | 2016-05-06 14:23:47 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2016-05-06 14:32:58 -0400 |
commit | 06bd458cb812623c3f1fdd55216c4c08b06a8447 (patch) | |
tree | 49d6d64be5e945fd65df41bf5222d31b193a13d2 /src/backend/access/transam/parallel.c | |
parent | a89505fd21da337b81172871d8f65d9a4fa22a8b (diff) | |
download | postgresql-06bd458cb812623c3f1fdd55216c4c08b06a8447.tar.gz postgresql-06bd458cb812623c3f1fdd55216c4c08b06a8447.zip |
Use mul_size when multiplying by the number of parallel workers.
That way, if the result overflows size_t, you'll get an error instead
of undefined behavior, which seems like a plus. This also has the
effect of casting the number of workers from int to Size, which is
better because it's harder to overflow int than size_t.
Dilip Kumar reported this issue and provided a patch upon which this
patch is based, but his version did use mul_size.
Diffstat (limited to 'src/backend/access/transam/parallel.c')
-rw-r--r-- | src/backend/access/transam/parallel.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c index 0bba9a7dbda..934dba88c66 100644 --- a/src/backend/access/transam/parallel.c +++ b/src/backend/access/transam/parallel.c @@ -241,7 +241,8 @@ InitializeParallelDSM(ParallelContext *pcxt) PARALLEL_ERROR_QUEUE_SIZE, "parallel error queue size not buffer-aligned"); shm_toc_estimate_chunk(&pcxt->estimator, - PARALLEL_ERROR_QUEUE_SIZE * pcxt->nworkers); + mul_size(PARALLEL_ERROR_QUEUE_SIZE, + pcxt->nworkers)); shm_toc_estimate_keys(&pcxt->estimator, 1); /* Estimate how much we'll need for extension entrypoint info. */ @@ -347,7 +348,8 @@ InitializeParallelDSM(ParallelContext *pcxt) */ error_queue_space = shm_toc_allocate(pcxt->toc, - PARALLEL_ERROR_QUEUE_SIZE * pcxt->nworkers); + mul_size(PARALLEL_ERROR_QUEUE_SIZE, + pcxt->nworkers)); for (i = 0; i < pcxt->nworkers; ++i) { char *start; |