aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2024-08-07 09:21:07 +0200
committerPeter Eisentraut <peter@eisentraut.org>2024-08-08 07:42:31 +0200
commit2de129b356bfde9a02269c174396add065ace260 (patch)
treef4ff8f284f30be06586d9311521dda7852c5ccbb /src
parentde35207015567da892d825a704933e6681347f19 (diff)
downloadpostgresql-2de129b356bfde9a02269c174396add065ace260.tar.gz
postgresql-2de129b356bfde9a02269c174396add065ace260.zip
Revert ECPG's use of pnstrdup()
Commit 0b9466fce added a dependency on fe_memutils' pnstrdup() inside informix.c. This adds an exit() path in a library, which we don't want. (Unlike libpq, the ecpg libraries don't have an automated check for that, but it makes sense to keep them to a similar standard.) The ecpg code can already handle failure results from the *strdup() call by itself. Author: Jacob Champion <jacob.champion@enterprisedb.com> Discussion: https://www.postgresql.org/message-id/CAOYmi+=pg=W5L1h=3MEP_EB24jaBu2FyATrLXqQHGe7cpuvwyg@mail.gmail.com
Diffstat (limited to 'src')
-rw-r--r--src/interfaces/ecpg/compatlib/informix.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/interfaces/ecpg/compatlib/informix.c b/src/interfaces/ecpg/compatlib/informix.c
index 80d40aa3e09..407eee2e59c 100644
--- a/src/interfaces/ecpg/compatlib/informix.c
+++ b/src/interfaces/ecpg/compatlib/informix.c
@@ -175,6 +175,25 @@ deccopy(decimal *src, decimal *target)
memcpy(target, src, sizeof(decimal));
}
+static char *
+ecpg_strndup(const char *str, size_t len)
+{
+ size_t real_len = strlen(str);
+ int use_len = (int) ((real_len > len) ? len : real_len);
+
+ char *new = malloc(use_len + 1);
+
+ if (new)
+ {
+ memcpy(new, str, use_len);
+ new[use_len] = '\0';
+ }
+ else
+ errno = ENOMEM;
+
+ return new;
+}
+
int
deccvasc(const char *cp, int len, decimal *np)
{
@@ -186,8 +205,8 @@ deccvasc(const char *cp, int len, decimal *np)
if (risnull(CSTRINGTYPE, cp))
return 0;
- str = pnstrdup(cp, len); /* decimal_in always converts the complete
- * string */
+ str = ecpg_strndup(cp, len); /* decimal_in always converts the complete
+ * string */
if (!str)
ret = ECPG_INFORMIX_NUM_UNDERFLOW;
else