public inbox for [email protected]
help / color / mirror / Atom feedFrom: Hongxu Ma <[email protected]>
To: Jelte Fennema <[email protected]>
Cc: David G. Johnston <[email protected]>
Cc: PostgreSQL Hackers <[email protected]>
Subject: Re: PSQL error: total cell count of XXX exceeded
Date: Tue, 12 Sep 2023 02:39:55 +0000
Message-ID: <TYBP286MB03515815935D9F6FA90C5921B4F1A@TYBP286MB0351.JPNP286.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <CAGECzQSo0qk+QwzVgGhjx+-gGmj41w+JPmUHmdeObFCp1h7pjQ@mail.gmail.com>
References: <TYBP286MB0351B057B101C90D7C1239E6B4E2A@TYBP286MB0351.JPNP286.PROD.OUTLOOK.COM>
<CAKFQuwYfypo7hMXs8a7Ccx4x2bv1XKCMu=pOoQAfq_0Fpu7YQQ@mail.gmail.com>
<TYBP286MB03514675D5D9AA3F533DC987B4E2A@TYBP286MB0351.JPNP286.PROD.OUTLOOK.COM>
<TYBP286MB03510C21D207F77D80CF6235B4F2A@TYBP286MB0351.JPNP286.PROD.OUTLOOK.COM>
<CAGECzQSo0qk+QwzVgGhjx+-gGmj41w+JPmUHmdeObFCp1h7pjQ@mail.gmail.com>
Thank you for your advice, Jelte.
I have refactored my code, please see the attached patch. (and I put it into https://commitfest.postgresql.org/45/ for trace)
Thanks.
________________________________
From: Jelte Fennema <[email protected]>
Sent: Monday, September 11, 2023 15:04
To: Hongxu Ma <[email protected]>
Cc: David G. Johnston <[email protected]>; PostgreSQL Hackers <[email protected]>
Subject: Re: PSQL error: total cell count of XXX exceeded
On Mon, 11 Sept 2023 at 08:51, Hongxu Ma <[email protected]> wrote:
>
> I created a patch to fix it.
> Really appreciate to anyone can help to review it.
> Thanks.
I think "product" as a variable name isn't very descriptive. Let's
call it total_cells (or something similar instead).
Other than that I think it's a good change. content->cellsadded is
also a long, So I agree that I don't think the limit of int cells was
intended here.
Attachments:
[application/octet-stream] v2-0001-Using-long-type-in-printTableAddCell.patch (1.6K, ../TYBP286MB03515815935D9F6FA90C5921B4F1A@TYBP286MB0351.JPNP286.PROD.OUTLOOK.COM/3-v2-0001-Using-long-type-in-printTableAddCell.patch)
download | inline diff:
From 4c6295aa31fbf325f9b88c942d82a26f2f4aa87e Mon Sep 17 00:00:00 2001
From: interma <[email protected]>
Date: Mon, 11 Sep 2023 14:42:14 +0800
Subject: [PATCH] Using long type in printTableAddCell() to prevent int
overflow
---
src/fe_utils/print.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/src/fe_utils/print.c b/src/fe_utils/print.c
index 7af1ccb6b5..99bbec9f72 100644
--- a/src/fe_utils/print.c
+++ b/src/fe_utils/print.c
@@ -3249,15 +3249,21 @@ void
printTableAddCell(printTableContent *const content, char *cell,
const bool translate, const bool mustfree)
{
+ long total_cells;
#ifndef ENABLE_NLS
(void) translate; /* unused parameter */
#endif
- if (content->cellsadded >= content->ncolumns * content->nrows)
+ /*
+ * total_cells is the product of ncolumns and nrows
+ * Using long type here to prevent int overflow
+ */
+ total_cells = (long)content->ncolumns * (long)content->nrows;
+ if (content->cellsadded >= total_cells)
{
fprintf(stderr, _("Cannot add cell to table content: "
- "total cell count of %d exceeded.\n"),
- content->ncolumns * content->nrows);
+ "total cell count of %ld exceeded, cells added: %ld.\n"),
+ total_cells, content->cellsadded);
exit(EXIT_FAILURE);
}
@@ -3273,7 +3279,7 @@ printTableAddCell(printTableContent *const content, char *cell,
{
if (content->cellmustfree == NULL)
content->cellmustfree =
- pg_malloc0((content->ncolumns * content->nrows + 1) * sizeof(bool));
+ pg_malloc0((total_cells + 1) * sizeof(bool));
content->cellmustfree[content->cellsadded] = true;
}
--
2.39.2 (Apple Git-143)
view thread (4+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: PSQL error: total cell count of XXX exceeded
In-Reply-To: <TYBP286MB03515815935D9F6FA90C5921B4F1A@TYBP286MB0351.JPNP286.PROD.OUTLOOK.COM>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox