Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e9e05c6

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 75345f6 commit e9e05c6

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/interfaces/ecpg/compatlib/informix.c

+21-2
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)