summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJacob Champion <jchampion@postgresql.org>2025-11-24 09:59:54 -0800
committerJacob Champion <jchampion@postgresql.org>2025-11-24 09:59:54 -0800
commite2ceff13d83a85c634dc358b8291c7ae301e95e1 (patch)
tree183260e85acc957ef29398b36d9230d4158ed2ff /src
parent8934f2136cd82333fd148954a13a8ab01f7bd7ef (diff)
postgres: Use pg_{add,mul}_size_overflow()
The backend implementations of add_size() and mul_size() can now make use of the APIs provided in common/int.h. Reviewed-by: Chao Li <li.evan.chao@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/CAOYmi%2B%3D%2BpqUd2MUitvgW1pAJuXgG_TKCVc3_Ek7pe8z9nkf%2BAg%40mail.gmail.com
Diffstat (limited to 'src')
-rw-r--r--src/backend/storage/ipc/shmem.c11
1 files changed, 3 insertions, 8 deletions
diff --git a/src/backend/storage/ipc/shmem.c b/src/backend/storage/ipc/shmem.c
index 0f18beb6ad4..ee3408df301 100644
--- a/src/backend/storage/ipc/shmem.c
+++ b/src/backend/storage/ipc/shmem.c
@@ -65,6 +65,7 @@
#include "postgres.h"
+#include "common/int.h"
#include "fmgr.h"
#include "funcapi.h"
#include "miscadmin.h"
@@ -495,9 +496,7 @@ add_size(Size s1, Size s2)
{
Size result;
- result = s1 + s2;
- /* We are assuming Size is an unsigned type here... */
- if (result < s1 || result < s2)
+ if (pg_add_size_overflow(s1, s2, &result))
ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("requested shared memory size overflows size_t")));
@@ -512,11 +511,7 @@ mul_size(Size s1, Size s2)
{
Size result;
- if (s1 == 0 || s2 == 0)
- return 0;
- result = s1 * s2;
- /* We are assuming Size is an unsigned type here... */
- if (result / s2 != s1)
+ if (pg_mul_size_overflow(s1, s2, &result))
ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("requested shared memory size overflows size_t")));