From 19e34a3202da21150c61d8ff1e86b105723c05bb Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 25 Apr 2017 12:24:12 +0100 Subject: [PATCH] Added PG 10 compatibility wrapper to simple_prompt() Also checking for malloc failure into previous version's simple_prompt() calls. --- bin/pgut/pgut.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/bin/pgut/pgut.c b/bin/pgut/pgut.c index 66db463..3a3f5ef 100644 --- a/bin/pgut/pgut.c +++ b/bin/pgut/pgut.c @@ -434,7 +434,26 @@ simple_string_list_size(SimpleStringList list) static char * prompt_for_password(void) { - return simple_prompt("Password: ", 100, false); + char *buf; +#define BUFSIZE 100 + +#if PG_VERSION_NUM < 100000 + buf = simple_prompt("Password: ", BUFSIZE, false); +#else + buf = (char *)malloc(BUFSIZE); + if (buf != NULL) + simple_prompt("Password: ", buf, BUFSIZE, false); +#endif + + if (buf == NULL) + ereport(FATAL, + (errcode_errno(), + errmsg("could not allocate memory (" UINT64_FORMAT " bytes): ", + (unsigned long) BUFSIZE))); + + return buf; + +#undef BUFSIZE }