Skip to content

Commit 5388216

Browse files
committed
Revert ECPG's use of pnstrdup()
Commit 0b9466f 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
1 parent 40064a8 commit 5388216

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/interfaces/ecpg/compatlib/informix.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,25 @@ deccopy(decimal *src, decimal *target)
175175
memcpy(target, src, sizeof(decimal));
176176
}
177177

178+
static char *
179+
ecpg_strndup(const char *str, size_t len)
180+
{
181+
size_t real_len = strlen(str);
182+
int use_len = (int) ((real_len > len) ? len : real_len);
183+
184+
char *new = malloc(use_len + 1);
185+
186+
if (new)
187+
{
188+
memcpy(new, str, use_len);
189+
new[use_len] = '\0';
190+
}
191+
else
192+
errno = ENOMEM;
193+
194+
return new;
195+
}
196+
178197
int
179198
deccvasc(const char *cp, int len, decimal *np)
180199
{
@@ -186,8 +205,8 @@ deccvasc(const char *cp, int len, decimal *np)
186205
if (risnull(CSTRINGTYPE, cp))
187206
return 0;
188207

189-
str = pnstrdup(cp, len); /* decimal_in always converts the complete
190-
* string */
208+
str = ecpg_strndup(cp, len); /* decimal_in always converts the complete
209+
* string */
191210
if (!str)
192211
ret = ECPG_INFORMIX_NUM_UNDERFLOW;
193212
else

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy